job_state: track and store most recent Job Event
Signed-off-by: Eric Callahan <arksine.codee@gmail.com>
This commit is contained in:
parent
4b1a3b8792
commit
e7d3f3e961
|
@ -24,6 +24,7 @@ class JobState:
|
||||||
def __init__(self, config: ConfigHelper) -> None:
|
def __init__(self, config: ConfigHelper) -> None:
|
||||||
self.server = config.get_server()
|
self.server = config.get_server()
|
||||||
self.last_print_stats: Dict[str, Any] = {}
|
self.last_print_stats: Dict[str, Any] = {}
|
||||||
|
self.last_event: JobEvent = JobEvent.STANDBY
|
||||||
self.server.register_event_handler(
|
self.server.register_event_handler(
|
||||||
"server:klippy_started", self._handle_started
|
"server:klippy_started", self._handle_started
|
||||||
)
|
)
|
||||||
|
@ -36,6 +37,7 @@ class JobState:
|
||||||
if state in ("printing", "paused"):
|
if state in ("printing", "paused"):
|
||||||
# set error state
|
# set error state
|
||||||
self.last_print_stats["state"] = "error"
|
self.last_print_stats["state"] = "error"
|
||||||
|
self.last_event = JobEvent.ERROR
|
||||||
|
|
||||||
async def _handle_started(self, state: KlippyState) -> None:
|
async def _handle_started(self, state: KlippyState) -> None:
|
||||||
if state != KlippyState.READY:
|
if state != KlippyState.READY:
|
||||||
|
@ -80,9 +82,10 @@ class JobState:
|
||||||
# should register handlers for "job_state: status_changed" and
|
# should register handlers for "job_state: status_changed" and
|
||||||
# match against the JobEvent object provided.
|
# match against the JobEvent object provided.
|
||||||
self.server.send_event(f"job_state:{new_state}", prev_ps, new_ps)
|
self.server.send_event(f"job_state:{new_state}", prev_ps, new_ps)
|
||||||
|
self.last_event = JobEvent.from_string(new_state)
|
||||||
self.server.send_event(
|
self.server.send_event(
|
||||||
"job_state:state_changed",
|
"job_state:state_changed",
|
||||||
JobEvent.from_string(new_state),
|
self.last_event,
|
||||||
prev_ps,
|
prev_ps,
|
||||||
new_ps
|
new_ps
|
||||||
)
|
)
|
||||||
|
@ -108,5 +111,8 @@ class JobState:
|
||||||
def get_last_stats(self) -> Dict[str, Any]:
|
def get_last_stats(self) -> Dict[str, Any]:
|
||||||
return dict(self.last_print_stats)
|
return dict(self.last_print_stats)
|
||||||
|
|
||||||
|
def get_last_job_event(self) -> JobEvent:
|
||||||
|
return self.last_event
|
||||||
|
|
||||||
def load_component(config: ConfigHelper) -> JobState:
|
def load_component(config: ConfigHelper) -> JobState:
|
||||||
return JobState(config)
|
return JobState(config)
|
||||||
|
|
Loading…
Reference in New Issue