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)