MQTT persist discovery msg
This commit is contained in:
parent
6850c9646e
commit
6128d8706d
|
@ -3,3 +3,4 @@ venv
|
||||||
build
|
build
|
||||||
*.FCStd1
|
*.FCStd1
|
||||||
*.blend1
|
*.blend1
|
||||||
|
__pycache__
|
||||||
|
|
|
@ -6,7 +6,7 @@ from copy import deepcopy
|
||||||
|
|
||||||
|
|
||||||
class ShelveLightMqtt:
|
class ShelveLightMqtt:
|
||||||
def __init__(self, protocol, client):
|
def __init__(self, protocol, client: asyncio_mqtt.Client):
|
||||||
self._protocol = protocol
|
self._protocol = protocol
|
||||||
self._mqtt_client = client
|
self._mqtt_client = client
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ class ShelveLightMqtt:
|
||||||
|
|
||||||
async def _send_autodiscovery_msg(self):
|
async def _send_autodiscovery_msg(self):
|
||||||
topic = f"homeassistant/light/{self._discovery_spec['unique_id']}/config"
|
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):
|
async def _notify_mqtt_state(self, state):
|
||||||
state_payload = json.dumps(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/#")
|
await client.subscribe("musicmouse_json/#")
|
||||||
async for message in messages:
|
async for message in messages:
|
||||||
await shelve_light.handle_light_message(message)
|
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')
|
print(f'Error "{error}". Reconnecting in {reconnect_interval} seconds')
|
||||||
finally:
|
finally:
|
||||||
await asyncio.sleep(reconnect_interval)
|
await asyncio.sleep(reconnect_interval)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
class DummyProtocol:
|
class DummyProtocol:
|
||||||
def shelve_led_effect(self, effect):
|
def shelve_led_effect(self, effect):
|
||||||
print("EFF ", repr(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