diff --git a/backend/app/api/routes/smart_plugs.py b/backend/app/api/routes/smart_plugs.py index 0d134d90c..78b74fccc 100644 --- a/backend/app/api/routes/smart_plugs.py +++ b/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() diff --git a/backend/app/services/bambu_mqtt.py b/backend/app/services/bambu_mqtt.py index 0313fd567..2e858f827 100644 --- a/backend/app/services/bambu_mqtt.py +++ b/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