job_state; check stored state on disconnect

If Klipper disconnects while printing manually set the state
to "error".

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-04-04 20:15:33 -04:00
parent 99b97afc7d
commit 44a5600038
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 11 additions and 1 deletions

View File

@ -25,7 +25,17 @@ class JobState:
self.server = config.get_server()
self.last_print_stats: Dict[str, Any] = {}
self.server.register_event_handler(
"server:klippy_started", self._handle_started)
"server:klippy_started", self._handle_started
)
self.server.register_event_handler(
"server:klippy_disconnect", self._handle_disconnect
)
def _handle_disconnect(self):
state = self.last_print_stats.get("state", "")
if state in ("printing", "paused"):
# set error state
self.last_print_stats["state"] = "error"
async def _handle_started(self, state: KlippyState) -> None:
if state != KlippyState.READY: