Skip to content

Commit

Permalink
Add more MQTT entities #921 #922
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed Jul 17, 2023
1 parent 6e1e68d commit 485ecf1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
65 changes: 62 additions & 3 deletions app/wyzebridge/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def publish_discovery(cam_uri: str, cam: WyzeCamera, stopped: bool = True) -> No
},
}

for entity, data in get_entities(base).items():
for entity, data in get_entities(base, cam.is_pan_cam, cam.rtsp_fw).items():
topic = f"{MQTT_DISCOVERY}/{data['type']}/{cam.mac}/{entity}/config"
if "availability_topic" not in data["payload"]:
data["payload"]["availability_topic"] = f"{MQTT_TOPIC}/state"
Expand Down Expand Up @@ -188,8 +188,8 @@ def _on_message(client, callback, msg):
logger.info(f"[MQTT] {resp}")


def get_entities(base_topic: str) -> dict:
return {
def get_entities(base_topic: str, pan_cam: bool = False, rtsp: bool = False) -> dict:
entities = {
"snapshot": {
"type": "camera",
"payload": {
Expand Down Expand Up @@ -226,6 +226,16 @@ def get_entities(base_topic: str) -> dict:
"icon": "mdi:weather-night",
},
},
"alarm": {
"type": "switch",
"payload": {
"state_topic": f"{base_topic}alarm",
"command_topic": f"{base_topic}alarm/set",
"payload_on": 1,
"payload_off": 2,
"icon": "mdi:alarm-bell",
},
},
"status_light": {
"type": "switch",
"payload": {
Expand All @@ -237,6 +247,17 @@ def get_entities(base_topic: str) -> dict:
"entity_category": "diagnostic",
},
},
"motion_tagging": {
"type": "switch",
"payload": {
"state_topic": f"{base_topic}motion_tagging",
"command_topic": f"{base_topic}motion_tagging/set",
"payload_on": 1,
"payload_off": 2,
"icon": "mdi:image-filter-center-focus",
"entity_category": "diagnostic",
},
},
"bitrate": {
"type": "number",
"payload": {
Expand Down Expand Up @@ -285,3 +306,41 @@ def get_entities(base_topic: str) -> dict:
},
},
}
if pan_cam:
entities |= {
"pan_cruise": {
"type": "switch",
"payload": {
"state_topic": f"{base_topic}pan_cruise",
"command_topic": f"{base_topic}pan_cruise/set",
"payload_on": 1,
"payload_off": 2,
"icon": "mdi:rotate-right",
},
},
"motion_tracking": {
"type": "switch",
"payload": {
"state_topic": f"{base_topic}motion_tracking",
"command_topic": f"{base_topic}motion_tracking/set",
"payload_on": 1,
"payload_off": 2,
"icon": "mdi:motion-sensor",
},
},
}
if rtsp:
entities |= {
"rtsp": {
"type": "switch",
"payload": {
"state_topic": f"{base_topic}rtsp",
"command_topic": f"{base_topic}rtsp/set",
"payload_on": 1,
"payload_off": 2,
"icon": "mdi:motion-sensor",
},
},
}

return entities
6 changes: 6 additions & 0 deletions app/wyzecam/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
# known 2k cameras
PRO_CAMS = {"HL_CAM3P", "HL_PANP"}

PAN_CAMS = {"WYZECP1_JEF", "HL_PAN2", "HL_PAN3", "HL_PANP"}

BATTERY_CAMS = {"WVOD1", "HL_WCO2", "AN_RSCW"}

# Doorbells
Expand Down Expand Up @@ -166,6 +168,10 @@ def is_battery(self) -> bool:
def is_vertical(self) -> bool:
return self.product_model in VERTICAL_CAMS

@property
def is_pan_cam(self) -> bool:
return self.product_model in PAN_CAMS

@property
def can_substream(self) -> bool:
if self.rtsp_fw:
Expand Down

0 comments on commit 485ecf1

Please sign in to comment.