Skip to content

Commit

Permalink
feat: Add ETA window calculation based on estimated time of current f…
Browse files Browse the repository at this point in the history
…ile rather than default 10 min
  • Loading branch information
Clon1998 committed Jun 2, 2024
1 parent b08e1ce commit ea7277e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 11 additions & 0 deletions mobileraker/data/dtos/moonraker/printer_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,15 @@ def progress(self) -> Optional[int]:
@property
def is_timelapse_pause(self) -> bool:
return self.print_state == "paused" and self.timelapse_pause is True


@property
def eta_window(self) -> Optional[int]:
"""
Calculate the ETA window based on the estimated time of the current file.
Returns: Optional[int]: ETA window in minutes, or None if calculation is not possible.
"""
if self.current_file is not None and self.current_file.estimated_time is not None:
return int(self.current_file.estimated_time * 0.05) // 60
return None

6 changes: 5 additions & 1 deletion mobileraker/mobileraker_companion.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,13 @@ def _live_activity_update(self, cfg: DeviceNotificationEntry, cur_snap: PrinterS
'LiveActivityUpdate preChecks passed'
)


# Calculate the eta delta based on the estimated time of the current file or 15 minutes (whichever is higher)
eta_delta = max(15, cur_snap.eta_window) if cur_snap.eta_window is not None else 15

etaUpdate = self._last_snapshot is not None and \
self._last_snapshot.eta is not None and cur_snap.eta is not None and \
abs((self._last_snapshot.eta - cur_snap.eta).seconds) > 600
abs((self._last_snapshot.eta - cur_snap.eta).seconds) > eta_delta

# The live activity can be updted more frequent. Max however in 5 percent steps or if there was a state change
if not normalized_progress_interval_reached(cfg.snap.progress_live_activity, cur_snap.progress, self.remote_config.increments) and cfg.snap.state == cur_snap.print_state and not etaUpdate:
Expand Down
4 changes: 2 additions & 2 deletions mobileraker/util/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'state_completed_body': 'Finished printing: "$file"',
'state_error_body': 'Error while printing file: "$file"',
'state_standby_body': 'Printer is in Standby',
'state_resumed_body': 'Resumed printing file: "$file"',
'state_resumed_body': 'Resumed printing for: "$file"',
'm117_custom_title': 'User Notification',
"filament_sensor_triggered_title": "Filament Sensor Triggered",
"filament_sensor_triggered_body": "$$sensor triggered on printer $printer_name",
Expand Down Expand Up @@ -49,7 +49,7 @@
'state_completed_body': 'Druck abgeschlossen: "$file"',
'state_error_body': 'Fehler beim Drucken der Datei: "$file"',
'state_standby_body': 'Drucker im Standby',
'state_resumed_body': 'Druck der Datei fortgesetzt: "$file"',
'state_resumed_body': 'Druck fortgesetzt für Datei: "$file"',
'm117_custom_title': 'Nutzer-Benachrichtigung',
"filament_sensor_triggered_title": "Filament Sensor ausgelöst",
"filament_sensor_triggered_body": "$$sensor auf Drucker $printer_name ausgelöst",
Expand Down

0 comments on commit ea7277e

Please sign in to comment.