From 91e48200d64c647bb2c27074ed5a29339d6b85bd Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Tue, 11 Oct 2022 16:41:01 -0400 Subject: [PATCH] simplyprint: implement direct layer detection Klipper now has the ability to report the current layer on properly configured slicers. Prefer this value if available, otherwise fall back to layer detection. Signed-off-by: Eric Callahan --- moonraker/components/simplyprint.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/moonraker/components/simplyprint.py b/moonraker/components/simplyprint.py index 7e0eda4..94ea751 100644 --- a/moonraker/components/simplyprint.py +++ b/moonraker/components/simplyprint.py @@ -844,8 +844,8 @@ class SimplyPrint(Subscribable): def _update_job_progress(self) -> None: job_info: Dict[str, Any] = {} est_time = self.cache.metadata.get("estimated_time") + last_stats: Dict[str, Any] = self.job_state.get_last_stats() if est_time is not None: - last_stats: Dict[str, Any] = self.job_state.get_last_stats() duration: float = last_stats["print_duration"] time_left = max(0, int(est_time - duration + .5)) last_time_left = self.cache.job_info.get("time", time_left + 60.) @@ -860,7 +860,9 @@ class SimplyPrint(Subscribable): pct_prog = int(progress * 100 + .5) if pct_prog != self.cache.job_info.get("progress", 0): job_info["progress"] = int(progress * 100 + .5) - layer = self.layer_detect.layer + layer: Optional[int] = last_stats.get("info", {}).get("current_layer") + if layer is None: + layer = self.layer_detect.layer if layer != self.cache.job_info.get("layer", -1): job_info["layer"] = layer if job_info: