MQTT persist discovery msg
This commit is contained in:
parent
6850c9646e
commit
6128d8706d
|
@ -3,3 +3,4 @@ venv
|
|||
build
|
||||
*.FCStd1
|
||||
*.blend1
|
||||
__pycache__
|
||||
|
|
|
@ -6,7 +6,7 @@ from copy import deepcopy
|
|||
|
||||
|
||||
class ShelveLightMqtt:
|
||||
def __init__(self, protocol, client):
|
||||
def __init__(self, protocol, client: asyncio_mqtt.Client):
|
||||
self._protocol = protocol
|
||||
self._mqtt_client = client
|
||||
|
||||
|
@ -121,7 +121,7 @@ class ShelveLightMqtt:
|
|||
|
||||
async def _send_autodiscovery_msg(self):
|
||||
topic = f"homeassistant/light/{self._discovery_spec['unique_id']}/config"
|
||||
await self._mqtt_client.publish(topic, json.dumps(self._discovery_spec).encode())
|
||||
await self._mqtt_client.publish(topic, json.dumps(self._discovery_spec).encode(), retain=True)
|
||||
|
||||
async def _notify_mqtt_state(self, state):
|
||||
state_payload = json.dumps(self._state)
|
||||
|
@ -155,14 +155,13 @@ 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:
|
||||
except asyncio_mqtt.MqttError as error:
|
||||
print(f'Error "{error}". Reconnecting in {reconnect_interval} seconds')
|
||||
finally:
|
||||
await asyncio.sleep(reconnect_interval)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
class DummyProtocol:
|
||||
def shelve_led_effect(self, effect):
|
||||
print("EFF ", repr(effect))
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# Put this into /etc/systemd/system/musicmouse.service
|
||||
[Unit]
|
||||
Description=Music Mouse RFID Music Player
|
||||
After=multi-user.target
|
||||
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Restart=always
|
||||
ExecStart=/opt/musicmouse/venv/bin/python /opt/musicmouse/espmusicmouse/host_driver/main.py /media/musicmouse/
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in New Issue