From 5623231aecc2097ea287b72ece5c2a95eb215f9a Mon Sep 17 00:00:00 2001 From: Stefan Allius Date: Sat, 3 May 2025 23:34:22 +0200 Subject: [PATCH] check received counter in unit test --- app/src/mqtt.py | 3 ++- app/tests/test_mqtt.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/mqtt.py b/app/src/mqtt.py index e106ed2..cab0766 100644 --- a/app/src/mqtt.py +++ b/app/src/mqtt.py @@ -91,7 +91,6 @@ class Mqtt(metaclass=Singleton): async for message in self.__client.messages: await self.dispatch_msg(message) - self.received += 1 except aiomqtt.MqttError: self.ctime = None @@ -119,6 +118,8 @@ class Mqtt(metaclass=Singleton): f"{traceback.format_exc()}") async def dispatch_msg(self, message): + self.received += 1 + if message.topic.matches(self.ha_status_topic): status = message.payload.decode("UTF-8") logger_mqtt.info('Home-Assistant Status:' diff --git a/app/tests/test_mqtt.py b/app/tests/test_mqtt.py index 421fadb..c6f7f49 100644 --- a/app/tests/test_mqtt.py +++ b/app/tests/test_mqtt.py @@ -140,6 +140,7 @@ async def test_ha_reconnect(config_mqtt_conn): assert on_connect.is_set() finally: + assert m.received == 2 await m.close() @pytest.mark.asyncio