Browse Source

Fix progress milestone notification showing wrong time unit

The remaining_time from printer state is in minutes (from mc_remaining_time),
but _format_duration() expects seconds. This caused "17h 47m" to display as
"17m" in milestone notifications.

Closes #157
maziggy 4 months ago
parent
commit
2e03fca2df
1 changed files with 3 additions and 2 deletions
  1. 3 2
      backend/app/main.py

+ 3 - 2
backend/app/main.py

@@ -437,10 +437,11 @@ async def on_printer_status_change(printer_id: int, state: PrinterState):
                     printer = result.scalar_one_or_none()
                     printer = result.scalar_one_or_none()
                     printer_name = printer.name if printer else f"Printer {printer_id}"
                     printer_name = printer.name if printer else f"Printer {printer_id}"
                     filename = state.subtask_name or state.gcode_file or "Unknown"
                     filename = state.subtask_name or state.gcode_file or "Unknown"
-                    remaining_time = state.remaining_time
+                    # remaining_time is in minutes, convert to seconds for notification
+                    remaining_time_seconds = state.remaining_time * 60 if state.remaining_time else None
 
 
                     await notification_service.on_print_progress(
                     await notification_service.on_print_progress(
-                        printer_id, printer_name, filename, current_milestone, db, remaining_time
+                        printer_id, printer_name, filename, current_milestone, db, remaining_time_seconds
                     )
                     )
             except Exception as e:
             except Exception as e:
                 logging.getLogger(__name__).warning(f"Progress milestone notification failed: {e}")
                 logging.getLogger(__name__).warning(f"Progress milestone notification failed: {e}")