Adapted to new aiomqtt version

This commit is contained in:
Martin Bauer 2024-03-07 16:38:05 +01:00
parent 11bf0505fb
commit b2c060fcc9
1 changed files with 4 additions and 5 deletions

View File

@ -33,7 +33,7 @@ class ShelveLightMqtt:
await self._notify_mqtt_state({"state": "OFF"})
async def handle_light_message(self, msg):
if msg.topic == self._discovery_spec['command_topic']:
if msg.topic.value == self._discovery_spec['command_topic']:
payload = msg.payload.decode()
new_state = json.loads(payload)
print("IN ", new_state)
@ -179,10 +179,9 @@ async def start_mqtt(music_mouse_protocol, server, username, password):
async with aiomqtt.Client(hostname=server, username=username, password=password) as client:
shelve_light = ShelveLightMqtt(music_mouse_protocol, client)
await shelve_light.init()
async with client.filtered_messages("musicmouse_json/#") as messages:
await client.subscribe("musicmouse_json/#")
async for message in messages:
await shelve_light.handle_light_message(message)
await client.subscribe("musicmouse_json/#")
async for message in client.messages:
await shelve_light.handle_light_message(message)
except aiomqtt.MqttError as error:
print(f'Error "{error}". Reconnecting in {reconnect_interval} seconds')
finally: