From 0c2a187191d575f7e84edd631a96842a37d1abc4 Mon Sep 17 00:00:00 2001 From: Martin Ziegler Date: Sat, 29 Nov 2025 12:16:53 +0100 Subject: [PATCH] Added power consumption costs calculation --- backend/app/main.py | 2 +- backend/app/services/bambu_mqtt.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index ba9489fc2..6ba128b49 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -287,7 +287,7 @@ async def on_print_complete(printer_id: int, data: dict): await service.update_archive_status( archive_id, status=status, - completed_at=datetime.now() if status in ("completed", "failed") else None, + completed_at=datetime.now() if status in ("completed", "failed", "aborted") else None, ) await ws_manager.send_archive_updated({ diff --git a/backend/app/services/bambu_mqtt.py b/backend/app/services/bambu_mqtt.py index ce21ebf07..362e0fbf2 100644 --- a/backend/app/services/bambu_mqtt.py +++ b/backend/app/services/bambu_mqtt.py @@ -251,18 +251,24 @@ class BambuMQTTClient: "raw_data": data, }) - # Detect print completion (FINISH = success, FAILED = error) + # Detect print completion (FINISH = success, FAILED = error, IDLE = aborted) if ( self._previous_gcode_state == "RUNNING" - and self.state.state in ("FINISH", "FAILED") + and self.state.state in ("FINISH", "FAILED", "IDLE") and self.on_print_complete ): + if self.state.state == "FINISH": + status = "completed" + elif self.state.state == "FAILED": + status = "failed" + else: + status = "aborted" logger.info( f"[{self.serial_number}] PRINT COMPLETE detected - state: {self.state.state}, " - f"file: {self._previous_gcode_file or current_file}" + f"status: {status}, file: {self._previous_gcode_file or current_file}" ) self.on_print_complete({ - "status": "completed" if self.state.state == "FINISH" else "failed", + "status": status, "filename": self._previous_gcode_file or current_file, "raw_data": data, })