Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for animal detection in unifiprotect #116290

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions homeassistant/components/unifiprotect/binary_sensor.py
Expand Up @@ -175,6 +175,15 @@ class ProtectBinaryEventEntityDescription(
ufp_value="is_vehicle_detection_on",
ufp_perm=PermRequired.NO_WRITE,
),
ProtectBinaryEntityDescription(
key="smart_animal",
name="Detections: Animal",
icon="mdi:paw",
entity_category=EntityCategory.DIAGNOSTIC,
ufp_required_field="can_detect_animal",
ufp_value="is_animal_detection_on",
ufp_perm=PermRequired.NO_WRITE,
),
ProtectBinaryEntityDescription(
key="smart_package",
name="Detections: Package",
Expand Down Expand Up @@ -453,6 +462,15 @@ class ProtectBinaryEventEntityDescription(
ufp_enabled="is_vehicle_detection_on",
ufp_event_obj="last_vehicle_detect_event",
),
ProtectBinaryEventEntityDescription(
key="smart_obj_animal",
name="Animal Detected",
icon="mdi:paw",
ufp_value="is_animal_currently_detected",
ufp_required_field="can_detect_animal",
ufp_enabled="is_animal_detection_on",
ufp_event_obj="last_animal_detect_event",
),
ProtectBinaryEventEntityDescription(
key="smart_obj_package",
name="Package Detected",
Expand Down
11 changes: 11 additions & 0 deletions homeassistant/components/unifiprotect/switch.py
Expand Up @@ -179,6 +179,17 @@ async def _set_highfps(obj: Camera, value: bool) -> None:
ufp_set_method="set_vehicle_detection",
ufp_perm=PermRequired.WRITE,
),
ProtectSwitchEntityDescription(
key="smart_animal",
name="Detections: Animal",
icon="mdi:paw",
entity_category=EntityCategory.CONFIG,
ufp_required_field="can_detect_animal",
ufp_value="is_animal_detection_on",
ufp_enabled="is_recording_enabled",
ufp_set_method="set_animal_detection",
ufp_perm=PermRequired.WRITE,
),
ProtectSwitchEntityDescription(
key="smart_package",
name="Detections: Package",
Expand Down
1 change: 1 addition & 0 deletions tests/components/unifiprotect/conftest.py
Expand Up @@ -216,6 +216,7 @@ def doorbell_fixture(camera: Camera, fixed_now: datetime):
doorbell.feature_flags.smart_detect_types = [
SmartDetectObjectType.PERSON,
SmartDetectObjectType.VEHICLE,
SmartDetectObjectType.ANIMAL,
]
doorbell.has_speaker = True
doorbell.feature_flags.has_hdr = True
Expand Down
17 changes: 9 additions & 8 deletions tests/components/unifiprotect/test_switch.py
Expand Up @@ -43,6 +43,7 @@
or d.name == "Detections: Motion"
or d.name == "Detections: Person"
or d.name == "Detections: Vehicle"
or d.name == "Detections: Animal"
]
CAMERA_SWITCHES_NO_EXTRA = [
d
Expand All @@ -58,11 +59,11 @@ async def test_switch_camera_remove(

ufp.api.bootstrap.nvr.system_info.ustorage = None
await init_entry(hass, ufp, [doorbell, unadopted_camera])
assert_entity_counts(hass, Platform.SWITCH, 15, 13)
assert_entity_counts(hass, Platform.SWITCH, 16, 14)
await remove_entities(hass, ufp, [doorbell, unadopted_camera])
assert_entity_counts(hass, Platform.SWITCH, 2, 2)
await adopt_devices(hass, ufp, [doorbell, unadopted_camera])
assert_entity_counts(hass, Platform.SWITCH, 15, 13)
assert_entity_counts(hass, Platform.SWITCH, 16, 14)


async def test_switch_light_remove(
Expand Down Expand Up @@ -174,7 +175,7 @@ async def test_switch_setup_camera_all(
"""Test switch entity setup for camera devices (all enabled feature flags)."""

await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.SWITCH, 15, 13)
assert_entity_counts(hass, Platform.SWITCH, 16, 14)

entity_registry = er.async_get(hass)

Expand Down Expand Up @@ -297,7 +298,7 @@ async def test_switch_camera_ssh(
"""Tests SSH switch for cameras."""

await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.SWITCH, 15, 13)
assert_entity_counts(hass, Platform.SWITCH, 16, 14)

description = CAMERA_SWITCHES[0]

Expand Down Expand Up @@ -330,7 +331,7 @@ async def test_switch_camera_simple(
"""Tests all simple switches for cameras."""

await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.SWITCH, 15, 13)
assert_entity_counts(hass, Platform.SWITCH, 16, 14)

assert description.ufp_set_method is not None

Expand Down Expand Up @@ -359,7 +360,7 @@ async def test_switch_camera_highfps(
"""Tests High FPS switch for cameras."""

await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.SWITCH, 15, 13)
assert_entity_counts(hass, Platform.SWITCH, 16, 14)

description = CAMERA_SWITCHES[3]

Expand Down Expand Up @@ -390,7 +391,7 @@ async def test_switch_camera_privacy(
previous_record = doorbell.recording_settings.mode = RecordingMode.DETECTIONS

await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.SWITCH, 15, 13)
assert_entity_counts(hass, Platform.SWITCH, 16, 14)

description = PRIVACY_MODE_SWITCH

Expand Down Expand Up @@ -442,7 +443,7 @@ async def test_switch_camera_privacy_already_on(

doorbell.add_privacy_zone()
await init_entry(hass, ufp, [doorbell])
assert_entity_counts(hass, Platform.SWITCH, 15, 13)
assert_entity_counts(hass, Platform.SWITCH, 16, 14)

description = PRIVACY_MODE_SWITCH

Expand Down