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 4628d1a28b
commit 01b64c34ab

View file

@ -69,6 +69,24 @@ def poll_printers(app: App, db: Db) -> None:
log.info(f"Printer {printer.id} {printer.status} -> {status}") log.info(f"Printer {printer.id} {printer.status} -> {status}")
db.update_printer_status(pid=printer.id, 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 = {} printer_job = {}
try: try:
client = get_client(printer.url, printer.api_key) client = get_client(printer.url, printer.api_key)
@ -98,7 +116,10 @@ def poll_printers(app: App, db: Db) -> None:
_set_status("connecting") _set_status("connecting")
elif printer_state.get("ready"): elif printer_state.get("ready"):
_set_status("idle") if _bed_clear():
_set_status("idle")
else:
_set_status("occupied")
else: else:
raise Exception( raise Exception(