From 7a22813d8e4eea7b655fb018736283d8891fff13 Mon Sep 17 00:00:00 2001 From: Josh Finlay Date: Wed, 8 Jan 2025 10:05:53 +1000 Subject: [PATCH] fix: mqtt subscription format - Use gmqtt's Subscription class for MQTT subscriptions - Updated both _post_connect and subscribe methods --- backend/mqtt_integration.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/mqtt_integration.py b/backend/mqtt_integration.py index 3de5b3e..177bce0 100644 --- a/backend/mqtt_integration.py +++ b/backend/mqtt_integration.py @@ -3,6 +3,7 @@ import json import asyncio from typing import Optional, Callable, Union from gmqtt import Client as MQTTClient +from gmqtt.mqtt.subscription import Subscription import logging # Get logger @@ -102,8 +103,9 @@ class HomeAssistantMQTT: logger.info("Connected to MQTT broker") self._connected = True try: - # Subscribe to command topic using a dict - await self.client.subscribe([{'topic': self.command_topic, 'qos': 1}]) + # Subscribe to command topic using gmqtt's format + sub = Subscription(self.command_topic, qos=1) + await self.client.subscribe([sub]) logger.info(f"Subscribed to command topic: {self.command_topic}") # Publish discovery config @@ -192,7 +194,8 @@ class HomeAssistantMQTT: """Subscribe to a topic""" if self.client and self._connected: try: - await self.client.subscribe([{'topic': topic, 'qos': 1}]) + sub = Subscription(topic, qos=1) + await self.client.subscribe([sub]) except Exception as e: logger.error(f"Failed to subscribe to topic: {e}")