From b83f5b5932e248349763bc025d3808684f7e444d Mon Sep 17 00:00:00 2001
From: Christopher Bailey <cbailey@mort.is>
Date: Thu, 11 Jan 2024 00:23:59 -0500
Subject: [PATCH] Add new event sensors from UniFi Protect 2.11 (#107773)

---
 .../components/unifiprotect/binary_sensor.py  | 126 ++++++++++++++++++
 .../components/unifiprotect/switch.py         |  77 +++++++++++
 2 files changed, 203 insertions(+)

diff --git a/homeassistant/components/unifiprotect/binary_sensor.py b/homeassistant/components/unifiprotect/binary_sensor.py
index e156a60c787..d5baaa3b5bf 100644
--- a/homeassistant/components/unifiprotect/binary_sensor.py
+++ b/homeassistant/components/unifiprotect/binary_sensor.py
@@ -210,6 +210,69 @@ CAMERA_SENSORS: tuple[ProtectBinaryEntityDescription, ...] = (
         ufp_value="is_co_detection_on",
         ufp_perm=PermRequired.NO_WRITE,
     ),
+    ProtectBinaryEntityDescription(
+        key="smart_siren",
+        name="Detections: Siren",
+        icon="mdi:alarm-bell",
+        entity_category=EntityCategory.DIAGNOSTIC,
+        ufp_required_field="can_detect_siren",
+        ufp_value="is_siren_detection_on",
+        ufp_perm=PermRequired.NO_WRITE,
+    ),
+    ProtectBinaryEntityDescription(
+        key="smart_baby_cry",
+        name="Detections: Baby Cry",
+        icon="mdi:cradle",
+        entity_category=EntityCategory.DIAGNOSTIC,
+        ufp_required_field="can_detect_baby_cry",
+        ufp_value="is_baby_cry_detection_on",
+        ufp_perm=PermRequired.NO_WRITE,
+    ),
+    ProtectBinaryEntityDescription(
+        key="smart_speak",
+        name="Detections: Speaking",
+        icon="mdi:account-voice",
+        entity_category=EntityCategory.DIAGNOSTIC,
+        ufp_required_field="can_detect_speaking",
+        ufp_value="is_speaking_detection_on",
+        ufp_perm=PermRequired.NO_WRITE,
+    ),
+    ProtectBinaryEntityDescription(
+        key="smart_bark",
+        name="Detections: Barking",
+        icon="mdi:dog",
+        entity_category=EntityCategory.DIAGNOSTIC,
+        ufp_required_field="can_detect_bark",
+        ufp_value="is_bark_detection_on",
+        ufp_perm=PermRequired.NO_WRITE,
+    ),
+    ProtectBinaryEntityDescription(
+        key="smart_car_alarm",
+        name="Detections: Car Alarm",
+        icon="mdi:car",
+        entity_category=EntityCategory.DIAGNOSTIC,
+        ufp_required_field="can_detect_car_alarm",
+        ufp_value="is_car_alarm_detection_on",
+        ufp_perm=PermRequired.NO_WRITE,
+    ),
+    ProtectBinaryEntityDescription(
+        key="smart_car_horn",
+        name="Detections: Car Horn",
+        icon="mdi:bugle",
+        entity_category=EntityCategory.DIAGNOSTIC,
+        ufp_required_field="can_detect_car_horn",
+        ufp_value="is_car_horn_detection_on",
+        ufp_perm=PermRequired.NO_WRITE,
+    ),
+    ProtectBinaryEntityDescription(
+        key="smart_glass_break",
+        name="Detections: Glass Break",
+        icon="mdi:glass-fragile",
+        entity_category=EntityCategory.DIAGNOSTIC,
+        ufp_required_field="can_detect_glass_break",
+        ufp_value="is_glass_break_detection_on",
+        ufp_perm=PermRequired.NO_WRITE,
+    ),
 )
 
 LIGHT_SENSORS: tuple[ProtectBinaryEntityDescription, ...] = (
@@ -415,6 +478,69 @@ EVENT_SENSORS: tuple[ProtectBinaryEventEntityDescription, ...] = (
         ufp_enabled="is_co_detection_on",
         ufp_event_obj="last_cmonx_detect_event",
     ),
+    ProtectBinaryEventEntityDescription(
+        key="smart_audio_siren",
+        name="Siren Detected",
+        icon="mdi:alarm-bell",
+        ufp_value="is_siren_currently_detected",
+        ufp_required_field="can_detect_siren",
+        ufp_enabled="is_siren_detection_on",
+        ufp_event_obj="last_siren_detect_event",
+    ),
+    ProtectBinaryEventEntityDescription(
+        key="smart_audio_baby_cry",
+        name="Baby Cry Detected",
+        icon="mdi:cradle",
+        ufp_value="is_baby_cry_currently_detected",
+        ufp_required_field="can_detect_baby_cry",
+        ufp_enabled="is_baby_cry_detection_on",
+        ufp_event_obj="last_baby_cry_detect_event",
+    ),
+    ProtectBinaryEventEntityDescription(
+        key="smart_audio_speak",
+        name="Speaking Detected",
+        icon="mdi:account-voice",
+        ufp_value="is_speaking_currently_detected",
+        ufp_required_field="can_detect_speaking",
+        ufp_enabled="is_speaking_detection_on",
+        ufp_event_obj="last_speaking_detect_event",
+    ),
+    ProtectBinaryEventEntityDescription(
+        key="smart_audio_bark",
+        name="Barking Detected",
+        icon="mdi:dog",
+        ufp_value="is_bark_currently_detected",
+        ufp_required_field="can_detect_bark",
+        ufp_enabled="is_bark_detection_on",
+        ufp_event_obj="last_bark_detect_event",
+    ),
+    ProtectBinaryEventEntityDescription(
+        key="smart_audio_car_alarm",
+        name="Car Alarm Detected",
+        icon="mdi:car",
+        ufp_value="is_car_alarm_currently_detected",
+        ufp_required_field="can_detect_car_alarm",
+        ufp_enabled="is_car_alarm_detection_on",
+        ufp_event_obj="last_car_alarm_detect_event",
+    ),
+    ProtectBinaryEventEntityDescription(
+        key="smart_audio_car_horn",
+        name="Car Horn Detected",
+        icon="mdi:bugle",
+        ufp_value="is_car_horn_currently_detected",
+        ufp_required_field="can_detect_car_horn",
+        ufp_enabled="is_car_horn_detection_on",
+        ufp_event_obj="last_car_horn_detect_event",
+    ),
+    ProtectBinaryEventEntityDescription(
+        key="smart_audio_glass_break",
+        name="Glass Break Detected",
+        icon="mdi:glass-fragile",
+        ufp_value="last_glass_break_detect",
+        ufp_required_field="can_detect_glass_break",
+        ufp_enabled="is_glass_break_detection_on",
+        ufp_event_obj="last_glass_break_detect_event",
+    ),
 )
 
 DOORLOCK_SENSORS: tuple[ProtectBinaryEntityDescription, ...] = (
diff --git a/homeassistant/components/unifiprotect/switch.py b/homeassistant/components/unifiprotect/switch.py
index f3224e086a5..57089157169 100644
--- a/homeassistant/components/unifiprotect/switch.py
+++ b/homeassistant/components/unifiprotect/switch.py
@@ -221,6 +221,83 @@ CAMERA_SWITCHES: tuple[ProtectSwitchEntityDescription, ...] = (
         ufp_set_method="set_cmonx_detection",
         ufp_perm=PermRequired.WRITE,
     ),
+    ProtectSwitchEntityDescription(
+        key="smart_siren",
+        name="Detections: Siren",
+        icon="mdi:alarm-bell",
+        entity_category=EntityCategory.CONFIG,
+        ufp_required_field="can_detect_siren",
+        ufp_value="is_siren_detection_on",
+        ufp_enabled="is_recording_enabled",
+        ufp_set_method="set_siren_detection",
+        ufp_perm=PermRequired.WRITE,
+    ),
+    ProtectSwitchEntityDescription(
+        key="smart_baby_cry",
+        name="Detections: Baby Cry",
+        icon="mdi:cradle",
+        entity_category=EntityCategory.CONFIG,
+        ufp_required_field="can_detect_baby_cry",
+        ufp_value="is_baby_cry_detection_on",
+        ufp_enabled="is_recording_enabled",
+        ufp_set_method="set_baby_cry_detection",
+        ufp_perm=PermRequired.WRITE,
+    ),
+    ProtectSwitchEntityDescription(
+        key="smart_speak",
+        name="Detections: Speaking",
+        icon="mdi:account-voice",
+        entity_category=EntityCategory.CONFIG,
+        ufp_required_field="can_detect_speaking",
+        ufp_value="is_speaking_detection_on",
+        ufp_enabled="is_recording_enabled",
+        ufp_set_method="set_speaking_detection",
+        ufp_perm=PermRequired.WRITE,
+    ),
+    ProtectSwitchEntityDescription(
+        key="smart_bark",
+        name="Detections: Barking",
+        icon="mdi:dog",
+        entity_category=EntityCategory.CONFIG,
+        ufp_required_field="can_detect_bark",
+        ufp_value="is_bark_detection_on",
+        ufp_enabled="is_recording_enabled",
+        ufp_set_method="set_bark_detection",
+        ufp_perm=PermRequired.WRITE,
+    ),
+    ProtectSwitchEntityDescription(
+        key="smart_car_alarm",
+        name="Detections: Car Alarm",
+        icon="mdi:car",
+        entity_category=EntityCategory.CONFIG,
+        ufp_required_field="can_detect_car_alarm",
+        ufp_value="is_car_alarm_detection_on",
+        ufp_enabled="is_recording_enabled",
+        ufp_set_method="set_car_alarm_detection",
+        ufp_perm=PermRequired.WRITE,
+    ),
+    ProtectSwitchEntityDescription(
+        key="smart_car_horn",
+        name="Detections: Car Horn",
+        icon="mdi:bugle",
+        entity_category=EntityCategory.CONFIG,
+        ufp_required_field="can_detect_car_horn",
+        ufp_value="is_car_horn_detection_on",
+        ufp_enabled="is_recording_enabled",
+        ufp_set_method="set_car_horn_detection",
+        ufp_perm=PermRequired.WRITE,
+    ),
+    ProtectSwitchEntityDescription(
+        key="smart_glass_break",
+        name="Detections: Glass Break",
+        icon="mdi:glass-fragile",
+        entity_category=EntityCategory.CONFIG,
+        ufp_required_field="can_detect_glass_break",
+        ufp_value="is_glass_break_detection_on",
+        ufp_enabled="is_recording_enabled",
+        ufp_set_method="set_glass_break_detection",
+        ufp_perm=PermRequired.WRITE,
+    ),
 )
 
 PRIVACY_MODE_SWITCH = ProtectSwitchEntityDescription[Camera](