Compare commits

..

No commits in common. "730a6a3950b751cb9177c6cabce0e5541de0fa91" and "10d827c39f989bb8d48760f8bdc806ad93eecf3f" have entirely different histories.

2 changed files with 5 additions and 36 deletions

View file

@ -157,10 +157,6 @@ CREATE TABLE IF NOT EXISTS email_spool (
, FOREIGN KEY(user_id) REFERENCES users(id) , FOREIGN KEY(user_id) REFERENCES users(id)
); );
-- name: migration-0002-create-occupied-state
-- Create a state representing that the printer needs to be unloaded after a print
INSERT OR IGNORE INTO printer_statuses (id, name) VALUES (5, 'occupied');
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
-- Users -- Users
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------

View file

@ -8,7 +8,6 @@ Mostly related to monitoring and managing Printer state.
""" """
from contextlib import closing from contextlib import closing
from functools import cache
import logging import logging
from pathlib import Path from pathlib import Path
from pprint import pformat from pprint import pformat
@ -50,11 +49,6 @@ class OctoRest(_OR):
raise e raise e
@cache
def get_client(url, key):
return OctoRest(url=url, apikey=key)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -69,27 +63,9 @@ 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 = OctoRest(url=printer.url, apikey=printer.api_key)
printer_job: dict = client.job_info() printer_job: dict = client.job_info()
try: try:
printer_state: dict = client.printer().get("state").get("flags", {}) printer_state: dict = client.printer().get("state").get("flags", {})
@ -116,10 +92,7 @@ def poll_printers(app: App, db: Db) -> None:
_set_status("connecting") _set_status("connecting")
elif printer_state.get("ready"): elif printer_state.get("ready"):
if _bed_clear(): _set_status("idle")
_set_status("idle")
else:
_set_status("occupied")
else: else:
raise Exception( raise Exception(
@ -163,7 +136,7 @@ def push_jobs(app: App, db: Db) -> None:
db.delete_job(job.user_id, job.id) db.delete_job(job.user_id, job.id)
try: try:
client = get_client(printer.url, printer.api_key) client = OctoRest(url=printer.url, apikey=printer.api_key)
printer_job = client.job_info() printer_job = client.job_info()
try: try:
printer_state = client.printer().get("state").get("flags", {}) printer_state = client.printer().get("state").get("flags", {})
@ -209,7 +182,7 @@ def revoke_jobs(app: App, db: Db) -> None:
try: try:
log.info(f"Cancelling running job {job.id}") log.info(f"Cancelling running job {job.id}")
client = get_client(printer.url, printer.api_key) client = OctoRest(url=printer.url, apikey=printer.api_key)
try: try:
client.cancel() client.cancel()
except HTTPError as e: except HTTPError as e:
@ -238,7 +211,7 @@ def pull_jobs(app: App, db: Db) -> None:
for job in db.list_running_jobs(): for job in db.list_running_jobs():
printer = db.fetch_printer(pid=job.printer_id) printer = db.fetch_printer(pid=job.printer_id)
try: try:
client = get_client(printer.url, printer.api_key) client = OctoRest(url=printer.url, apikey=printer.api_key)
job_state = client.job_info() job_state = client.job_info()
try: try:
printer_state = client.printer().get("state").get("flags", {}) printer_state = client.printer().get("state").get("flags", {})