From 60864c5cab7e5ad073b2271976dba7478d788471 Mon Sep 17 00:00:00 2001 From: mrlt8 <67088095+mrlt8@users.noreply.github.com> Date: Sat, 22 Jul 2023 07:24:38 -0700 Subject: [PATCH] Additional MQTT entities #921 --- app/wyzebridge/mqtt.py | 59 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/app/wyzebridge/mqtt.py b/app/wyzebridge/mqtt.py index 22d43e39..d7edc027 100644 --- a/app/wyzebridge/mqtt.py +++ b/app/wyzebridge/mqtt.py @@ -96,7 +96,7 @@ def bridge_status(client: Optional[paho.mqtt.client.Client]): @mqtt_enabled def send_mqtt(messages: list) -> None: - """Publish a message to the MQTT server.""" + """Publish multiple messages to the MQTT server.""" paho.mqtt.publish.multiple( messages, hostname=MQTT_HOST, @@ -110,7 +110,7 @@ def send_mqtt(messages: list) -> None: @mqtt_enabled -def publish_message(topic: str, message=None): +def publish_message(topic: str, message=None, retain=True): paho.mqtt.publish.single( topic=f"{MQTT_TOPIC}/{topic}", payload=message, @@ -121,12 +121,16 @@ def publish_message(topic: str, message=None): if env_bool("MQTT_AUTH") else None ), + retain=retain, ) @mqtt_enabled def update_mqtt_state(camera: str, state: str): - return publish_message(f"{camera}/state", state) + msg = [(f"{MQTT_TOPIC}/{camera}/state", state)] + if state == "online": + msg.append((f"{MQTT_TOPIC}/{camera}/power", "1")) + send_mqtt(msg) @mqtt_enabled @@ -197,13 +201,35 @@ def get_entities(base_topic: str, pan_cam: bool = False, rtsp: bool = False) -> "icon": "mdi:cctv", }, }, + "stream": { + "type": "switch", + "payload": { + "state_topic": f"{base_topic}state", + "command_topic": f"{base_topic}state/set", + "payload_on": "start", + "state_on": "online", + "payload_off": "stop", + "state_off": "stopped", + "icon": "mdi:play-pause", + }, + }, "power": { "type": "switch", "payload": { + "state_topic": f"{base_topic}power", "command_topic": f"{base_topic}power/set", + "payload_on": 1, + "payload_off": 2, "icon": "mdi:power-plug", }, }, + "update_snapshot": { + "type": "button", + "payload": { + "command_topic": f"{base_topic}update_snapshot/get", + "icon": "mdi:camera", + }, + }, "ir": { "type": "switch", "payload": { @@ -225,7 +251,7 @@ def get_entities(base_topic: str, pan_cam: bool = False, rtsp: bool = False) -> }, }, "alarm": { - "type": "switch", + "type": "siren", "payload": { "state_topic": f"{base_topic}alarm", "command_topic": f"{base_topic}alarm/set", @@ -303,6 +329,15 @@ def get_entities(base_topic: str, pan_cam: bool = False, rtsp: bool = False) -> "entity_category": "diagnostic", }, }, + "reboot": { + "type": "button", + "payload": { + "command_topic": f"{base_topic}power/set", + "payload_press": "restart", + "icon": "mdi:restart", + "entity_category": "diagnostic", + }, + }, } if pan_cam: entities |= { @@ -326,6 +361,22 @@ def get_entities(base_topic: str, pan_cam: bool = False, rtsp: bool = False) -> "icon": "mdi:motion-sensor", }, }, + "reset_rotation": { + "type": "button", + "payload": { + "command_topic": f"{base_topic}reset_rotation/set", + "icon": "mdi:restore", + }, + }, + "cruise_point": { + "type": "select", + "payload": { + "state_topic": f"{base_topic}cruise_point", + "command_topic": f"{base_topic}cruise_point/set", + "options": [1, 2, 3, 4], + "icon": "mdi:map-marker-multiple", + }, + }, } if rtsp: entities |= {