Przeglądaj źródła

Fixed bug where current printers power stage was not updated in frontend

Martin Ziegler 5 miesięcy temu
rodzic
commit
46b312704c

+ 4 - 0
backend/app/api/routes/smart_plugs.py

@@ -20,6 +20,7 @@ from backend.app.schemas.smart_plug import (
     SmartPlugEnergy,
 )
 from backend.app.services.tasmota import tasmota_service
+from backend.app.services.printer_manager import printer_manager
 
 logger = logging.getLogger(__name__)
 
@@ -178,6 +179,9 @@ async def control_smart_plug(
         plug.last_state = expected_state
         if expected_state == "ON":
             plug.auto_off_executed = False  # Reset flag when manually turning on
+        elif expected_state == "OFF" and plug.printer_id:
+            # Mark printer offline immediately for faster UI update
+            printer_manager.mark_printer_offline(plug.printer_id)
     plug.last_checked = datetime.utcnow()
     await db.commit()
 

+ 3 - 0
backend/app/services/bambu_mqtt.py

@@ -116,6 +116,9 @@ class BambuMQTTClient:
             client.subscribe(self.topic_subscribe)
             # Request full status update
             self._request_push_all()
+            # Immediately broadcast connection state change
+            if self.on_state_change:
+                self.on_state_change(self.state)
         else:
             self.state.connected = False