modification on musicmouse host

This commit is contained in:
Martin Bauer 2023-01-03 20:50:45 +01:00
parent a67c6078c5
commit 804940bfac
1 changed files with 14 additions and 7 deletions

View File

@ -145,6 +145,9 @@ class ShelveLightMqtt:
async def start_mqtt(music_mouse_protocol, server, username, password):
reconnect_interval = 10 # [seconds]
while True:
try:
async with asyncio_mqtt.Client(hostname=server, username=username, password=password) as client:
shelve_light = ShelveLightMqtt(music_mouse_protocol, client)
await shelve_light.init()
@ -152,6 +155,10 @@ async def start_mqtt(music_mouse_protocol, server, username, password):
await client.subscribe("musicmouse_json/#")
async for message in messages:
await shelve_light.handle_light_message(message)
except MqttError as error:
print(f'Error "{error}". Reconnecting in {reconnect_interval} seconds')
finally:
await asyncio.sleep(reconnect_interval)
if __name__ == "__main__":