fix: mqtt subscription format

- Updated subscription format to use dict with topic and qos fields
- Fixed both _post_connect and subscribe methods
This commit is contained in:
Josh Finlay 2025-01-08 10:04:00 +10:00
parent 771a0d3e23
commit 92daf9c8ad
1 changed files with 3 additions and 3 deletions

View File

@ -102,8 +102,8 @@ class HomeAssistantMQTT:
logger.info("Connected to MQTT broker") logger.info("Connected to MQTT broker")
self._connected = True self._connected = True
try: try:
# Subscribe to command topic # Subscribe to command topic using a dict
await self.client.subscribe([(self.command_topic, 1)]) await self.client.subscribe([{'topic': self.command_topic, 'qos': 1}])
logger.info(f"Subscribed to command topic: {self.command_topic}") logger.info(f"Subscribed to command topic: {self.command_topic}")
# Publish discovery config # Publish discovery config
@ -192,7 +192,7 @@ class HomeAssistantMQTT:
"""Subscribe to a topic""" """Subscribe to a topic"""
if self.client and self._connected: if self.client and self._connected:
try: try:
await self.client.subscribe([(topic, 0)]) await self.client.subscribe([{'topic': topic, 'qos': 1}])
except Exception as e: except Exception as e:
logger.error(f"Failed to subscribe to topic: {e}") logger.error(f"Failed to subscribe to topic: {e}")