Use the bedready plugin to check if the bed is clear or occupied

This commit is contained in:
Reid 'arrdem' McKenzie 2023-06-19 23:24:39 -06:00
parent ae1d00b13f
commit 730a6a3950

View file

@ -69,6 +69,24 @@ def poll_printers(app: App, db: Db) -> None:
log.info(f"Printer {printer.id} {printer.status} -> {status}")
db.update_printer_status(pid=printer.id, status=status)
def _bed_clear():
if not (
snapshots := client._post(
"/api/plugin/bedready", json={"command": "list_snapshots"}
)
):
return True # Assume the bed is ready
status = client._post(
"/api/plugin/bedready",
json={
"command": "check_bed",
"similarity": 0.97,
"reference": snapshots[0],
},
)
return status.get("bed_clear", True)
printer_job = {}
try:
client = get_client(printer.url, printer.api_key)
@ -98,7 +116,10 @@ def poll_printers(app: App, db: Db) -> None:
_set_status("connecting")
elif printer_state.get("ready"):
if _bed_clear():
_set_status("idle")
else:
_set_status("occupied")
else:
raise Exception(