From 300e773ccd98e903a3b70dd4bfa4a77590a0d9fd Mon Sep 17 00:00:00 2001
From: lilly
Date: Tue, 1 Dec 2026 18:29:12 +0100
Subject: [PATCH] add probatory exception trigger in mqtt connection handling
---
api/src/dooris_api/mqtt_client.py | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/api/src/dooris_api/mqtt_client.py b/api/src/dooris_api/mqtt_client.py
index 8b5bd92..25080d7 100644
--- a/api/src/dooris_api/mqtt_client.py
+++ b/api/src/dooris_api/mqtt_client.py
@@ -3,14 +3,13 @@
# https://github.com/eclipse-paho/paho.mqtt.python/blob/master/examples/loop_asyncio.py
#
-from typing import Any, Set, Iterable
-import logging
import asyncio
+import logging
import socket
+from typing import Any, Iterable, Set
import paho.mqtt.client as mqtt
-
logger = logging.getLogger(__name__)
@@ -109,9 +108,20 @@ class AsyncMqttClient:
properties: mqtt.Properties,
):
logger.debug(f"mqtt client disconnected with message '{reason_code}'")
+
if self.fut_disconnect:
self.fut_disconnect.set_result(None)
+ # this should not be needed since we have an on_connect_fail callback but logs suggest it to be needed
+ # TODO: investigate whether dooris is now more able to keep its connections
+ if self.fut_connected is not None:
+ logger.debug(
+ f"triggering exceptional failure in connection future from disconnect. this shouldn't happen."
+ )
+ self.fut_connected.set_exception(
+ Exception("mqtt client could not connect to broker")
+ )
+
def on_message(self, client: mqtt.Client, userdata: Any, msg: mqtt.MQTTMessage):
self.messages.put_nowait(msg)