mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-17 11:25:48 +02:00
Improved notification scheduler and templates
This commit is contained in:
@@ -1354,6 +1354,7 @@ class BambuMQTTClient:
|
||||
self.state.state == "RUNNING"
|
||||
and self._previous_gcode_state != "RUNNING"
|
||||
and current_file
|
||||
and not self._was_running # Prevent duplicates when resuming from PAUSE
|
||||
)
|
||||
# Also detect if file changed while running (new print started)
|
||||
is_file_change = (
|
||||
@@ -1385,6 +1386,7 @@ class BambuMQTTClient:
|
||||
self.on_print_start({
|
||||
"filename": current_file,
|
||||
"subtask_name": self.state.subtask_name,
|
||||
"remaining_time": self.state.remaining_time * 60 if self.state.remaining_time > 0 else None, # Convert minutes to seconds
|
||||
"raw_data": data,
|
||||
})
|
||||
|
||||
|
||||
@@ -107,9 +107,15 @@ class NotificationService:
|
||||
return f"{minutes}m"
|
||||
|
||||
def _clean_filename(self, filename: str) -> str:
|
||||
"""Remove file extensions from filename."""
|
||||
"""Extract filename and remove file extensions."""
|
||||
import os
|
||||
# Strip path prefix (e.g., /data/Metadata/plate_5.gcode -> plate_5.gcode)
|
||||
filename = os.path.basename(filename)
|
||||
# Remove common extensions
|
||||
if filename.endswith(".gcode.3mf"):
|
||||
return filename[:-10]
|
||||
elif filename.endswith(".gcode"):
|
||||
return filename[:-6]
|
||||
elif filename.endswith(".3mf"):
|
||||
return filename[:-4]
|
||||
return filename
|
||||
@@ -552,9 +558,21 @@ class NotificationService:
|
||||
logger.info(f"No notification providers configured for print_start event on printer {printer_id}")
|
||||
return
|
||||
|
||||
filename = self._clean_filename(data.get("filename", "Unknown"))
|
||||
estimated_time = data.get("raw_data", {}).get("print", {}).get("mc_remaining_time")
|
||||
time_str = self._format_duration(estimated_time * 60 if estimated_time else None)
|
||||
# Use subtask_name (project name) if available, otherwise use filename
|
||||
subtask_name = data.get("subtask_name")
|
||||
if subtask_name:
|
||||
# Replace underscores with spaces for readability
|
||||
filename = subtask_name.replace("_", " ")
|
||||
else:
|
||||
filename = self._clean_filename(data.get("filename", "Unknown"))
|
||||
|
||||
# remaining_time can be passed directly, or look in raw_data at top level
|
||||
# mc_remaining_time is in minutes in MQTT data
|
||||
estimated_time = data.get("remaining_time")
|
||||
if estimated_time is None:
|
||||
raw_time = data.get("raw_data", {}).get("mc_remaining_time")
|
||||
estimated_time = raw_time * 60 if raw_time else None
|
||||
time_str = self._format_duration(estimated_time)
|
||||
|
||||
variables = {
|
||||
"printer": printer_name,
|
||||
@@ -598,7 +616,12 @@ class NotificationService:
|
||||
logger.info(f"No notification providers configured for {event_field} event on printer {printer_id}")
|
||||
return
|
||||
|
||||
filename = self._clean_filename(data.get("filename", "Unknown"))
|
||||
# Use subtask_name (project name) if available, otherwise use filename
|
||||
subtask_name = data.get("subtask_name")
|
||||
if subtask_name:
|
||||
filename = subtask_name.replace("_", " ")
|
||||
else:
|
||||
filename = self._clean_filename(data.get("filename", "Unknown"))
|
||||
|
||||
variables = {
|
||||
"printer": printer_name,
|
||||
|
||||
Reference in New Issue
Block a user