Skip to content

Commit

Permalink
Additional MQTT entities #921
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed Jul 22, 2023
1 parent 249f389 commit 60864c5
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions app/wyzebridge/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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": {
Expand All @@ -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",
Expand Down Expand Up @@ -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 |= {
Expand All @@ -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 |= {
Expand Down

0 comments on commit 60864c5

Please sign in to comment.