diff --git a/dayglo_detector/dayglo_detector.py b/dayglo_detector/dayglo_detector.py index 788b618..210708e 100644 --- a/dayglo_detector/dayglo_detector.py +++ b/dayglo_detector/dayglo_detector.py @@ -33,20 +33,22 @@ initial_snapshot_processed = False connected_once = False class DaygloDetectorMQTTClient(MQTTClient): - async def on_connect(self, client, flags, rc, properties): + async def handle_on_connect(self, client, flags, rc, properties): + asyncio.create_task(self.handle_on_connect(client, flags, rc, properties)) global connected_once if rc == 0 and not connected_once: print("Connected successfully to MQTT broker") - await self.subscribe(MQTT_SNAPSHOT_TOPIC, qos=1) + await client.subscribe(MQTT_SNAPSHOT_TOPIC, qos=1) print(f"Subscribed to topic: {MQTT_SNAPSHOT_TOPIC}") connected_once = True - await publish_discovery_configurations(self) + await publish_discovery_configurations(client) # Publish initial rating of 0 - await publish_rating(self, 0) + await publish_rating(client, 0) else: print(f"Failed to connect, return code {rc}") - async def on_message(self, client, topic, payload, qos, properties): + async def handle_on_message(self, client, topic, payload, qos, properties): + asyncio.create_task(self.handle_on_message(client, topic, payload, qos, properties)) if topic == MQTT_SNAPSHOT_TOPIC: print("Snapshot received") if len(payload) == 0: