Verbessere Verbindungsstatusverfolgung in BambuVirtualPrinter mit erweiterten Debug-Logs und informiere über erfolgreiche MQTT-Verbindungen

This commit is contained in:
Manuel Weiser 2025-03-02 11:13:04 +01:00
parent 3690767ced
commit 5661c11190

View File

@ -176,7 +176,9 @@ class BambuVirtualPrinter:
@property
def is_connected(self):
"""Custom property to track connection status without modifying BambuClient directly"""
return self._custom_connected and self._mqtt_connected
connection_status = self._custom_connected and self._mqtt_connected
self._log.debug(f"Connection status check: custom_connected={self._custom_connected}, mqtt_connected={self._mqtt_connected}, result={connection_status}")
return connection_status
def change_state(self, new_state: APrinterState):
self._state_change_queue.put(new_state)
@ -252,6 +254,7 @@ class BambuVirtualPrinter:
client.subscribe(device_topic)
self._log.debug(f"Subscribed to topic: {device_topic}")
self._log.info(f"MQTT connection successful. Connected: {self.is_connected}")
# Notify that we're connected
self.sendOk()
@ -448,6 +451,13 @@ class BambuVirtualPrinter:
self._mqtt_client.connect(host, port, 60)
self._mqtt_client.loop_start()
self._log.info(f"MQTT client started with {host}:{port}")
# Explicitly set the connection status
self._custom_connected = True
# Force initialize the printer connection status
if not hasattr(self._bambu_client, 'device'):
self._bambu_client._init_device()
except Exception as e:
self._log.error(f"Failed to connect to MQTT broker: {e}")
raise