Update UniFi Protect ring entity to use event entity (#83270)
parent
ec24b93c17
commit
ee7022dc67
|
@ -67,14 +67,6 @@ MOUNT_DEVICE_CLASS_MAP = {
|
|||
|
||||
|
||||
CAMERA_SENSORS: tuple[ProtectBinaryEntityDescription, ...] = (
|
||||
ProtectBinaryEntityDescription(
|
||||
key="doorbell",
|
||||
name="Doorbell",
|
||||
device_class=BinarySensorDeviceClass.OCCUPANCY,
|
||||
icon="mdi:doorbell-video",
|
||||
ufp_required_field="feature_flags.has_chime",
|
||||
ufp_value="is_ringing",
|
||||
),
|
||||
ProtectBinaryEntityDescription(
|
||||
key="dark",
|
||||
name="Is Dark",
|
||||
|
@ -339,7 +331,16 @@ SENSE_SENSORS: tuple[ProtectBinaryEntityDescription, ...] = (
|
|||
),
|
||||
)
|
||||
|
||||
MOTION_SENSORS: tuple[ProtectBinaryEventEntityDescription, ...] = (
|
||||
EVENT_SENSORS: tuple[ProtectBinaryEventEntityDescription, ...] = (
|
||||
ProtectBinaryEventEntityDescription(
|
||||
key="doorbell",
|
||||
name="Doorbell",
|
||||
device_class=BinarySensorDeviceClass.OCCUPANCY,
|
||||
icon="mdi:doorbell-video",
|
||||
ufp_required_field="feature_flags.has_chime",
|
||||
ufp_value="is_ringing",
|
||||
ufp_event_obj="last_ring_event",
|
||||
),
|
||||
ProtectBinaryEventEntityDescription(
|
||||
key="motion",
|
||||
name="Motion",
|
||||
|
@ -485,7 +486,7 @@ async def async_setup_entry(
|
|||
ufp_device=device,
|
||||
)
|
||||
if device.is_adopted and isinstance(device, Camera):
|
||||
entities += _async_motion_entities(data, ufp_device=device)
|
||||
entities += _async_event_entities(data, ufp_device=device)
|
||||
async_add_entities(entities)
|
||||
|
||||
entry.async_on_unload(
|
||||
|
@ -501,14 +502,14 @@ async def async_setup_entry(
|
|||
lock_descs=DOORLOCK_SENSORS,
|
||||
viewer_descs=VIEWER_SENSORS,
|
||||
)
|
||||
entities += _async_motion_entities(data)
|
||||
entities += _async_event_entities(data)
|
||||
entities += _async_nvr_entities(data)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
@callback
|
||||
def _async_motion_entities(
|
||||
def _async_event_entities(
|
||||
data: ProtectData,
|
||||
ufp_device: ProtectAdoptableDeviceModel | None = None,
|
||||
) -> list[ProtectDeviceEntity]:
|
||||
|
@ -517,7 +518,7 @@ def _async_motion_entities(
|
|||
data.get_by_types({ModelType.CAMERA}) if ufp_device is None else [ufp_device]
|
||||
)
|
||||
for device in devices:
|
||||
for description in MOTION_SENSORS:
|
||||
for description in EVENT_SENSORS:
|
||||
if not description.has_required(device):
|
||||
continue
|
||||
entities.append(ProtectEventBinarySensor(data, device, description))
|
||||
|
|
|
@ -521,7 +521,7 @@ NVR_DISABLED_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
|||
),
|
||||
)
|
||||
|
||||
MOTION_SENSORS: tuple[ProtectSensorEventEntityDescription, ...] = (
|
||||
EVENT_SENSORS: tuple[ProtectSensorEventEntityDescription, ...] = (
|
||||
ProtectSensorEventEntityDescription(
|
||||
key="detected_object",
|
||||
name="Detected Object",
|
||||
|
@ -641,7 +641,7 @@ async def async_setup_entry(
|
|||
ufp_device=device,
|
||||
)
|
||||
if device.is_adopted_by_us and isinstance(device, Camera):
|
||||
entities += _async_motion_entities(data, ufp_device=device)
|
||||
entities += _async_event_entities(data, ufp_device=device)
|
||||
async_add_entities(entities)
|
||||
|
||||
entry.async_on_unload(
|
||||
|
@ -659,14 +659,14 @@ async def async_setup_entry(
|
|||
chime_descs=CHIME_SENSORS,
|
||||
viewer_descs=VIEWER_SENSORS,
|
||||
)
|
||||
entities += _async_motion_entities(data)
|
||||
entities += _async_event_entities(data)
|
||||
entities += _async_nvr_entities(data)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
@callback
|
||||
def _async_motion_entities(
|
||||
def _async_event_entities(
|
||||
data: ProtectData,
|
||||
ufp_device: Camera | None = None,
|
||||
) -> list[ProtectDeviceEntity]:
|
||||
|
@ -687,7 +687,7 @@ def _async_motion_entities(
|
|||
if not device.feature_flags.has_smart_detect:
|
||||
continue
|
||||
|
||||
for event_desc in MOTION_SENSORS:
|
||||
for event_desc in EVENT_SENSORS:
|
||||
if not event_desc.has_required(device):
|
||||
continue
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ from pyunifiprotect.data.nvr import EventMetadata
|
|||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
||||
from homeassistant.components.unifiprotect.binary_sensor import (
|
||||
CAMERA_SENSORS,
|
||||
EVENT_SENSORS,
|
||||
LIGHT_SENSORS,
|
||||
MOTION_SENSORS,
|
||||
SENSE_SENSORS,
|
||||
)
|
||||
from homeassistant.components.unifiprotect.const import (
|
||||
|
@ -124,7 +124,7 @@ async def test_binary_sensor_setup_camera_all(
|
|||
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
description = CAMERA_SENSORS[0]
|
||||
description = EVENT_SENSORS[0]
|
||||
unique_id, entity_id = ids_from_device_description(
|
||||
Platform.BINARY_SENSOR, doorbell, description
|
||||
)
|
||||
|
@ -139,7 +139,7 @@ async def test_binary_sensor_setup_camera_all(
|
|||
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
||||
|
||||
# Is Dark
|
||||
description = CAMERA_SENSORS[1]
|
||||
description = CAMERA_SENSORS[0]
|
||||
unique_id, entity_id = ids_from_device_description(
|
||||
Platform.BINARY_SENSOR, doorbell, description
|
||||
)
|
||||
|
@ -154,7 +154,7 @@ async def test_binary_sensor_setup_camera_all(
|
|||
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
||||
|
||||
# Motion
|
||||
description = MOTION_SENSORS[0]
|
||||
description = EVENT_SENSORS[1]
|
||||
unique_id, entity_id = ids_from_device_description(
|
||||
Platform.BINARY_SENSOR, doorbell, description
|
||||
)
|
||||
|
@ -179,7 +179,7 @@ async def test_binary_sensor_setup_camera_none(
|
|||
assert_entity_counts(hass, Platform.BINARY_SENSOR, 2, 2)
|
||||
|
||||
entity_registry = er.async_get(hass)
|
||||
description = CAMERA_SENSORS[1]
|
||||
description = CAMERA_SENSORS[0]
|
||||
|
||||
unique_id, entity_id = ids_from_device_description(
|
||||
Platform.BINARY_SENSOR, camera, description
|
||||
|
@ -265,7 +265,7 @@ async def test_binary_sensor_update_motion(
|
|||
assert_entity_counts(hass, Platform.BINARY_SENSOR, 13, 13)
|
||||
|
||||
_, entity_id = ids_from_device_description(
|
||||
Platform.BINARY_SENSOR, doorbell, MOTION_SENSORS[0]
|
||||
Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[1]
|
||||
)
|
||||
|
||||
event = Event(
|
||||
|
|
|
@ -23,7 +23,7 @@ from homeassistant.components.unifiprotect.sensor import (
|
|||
ALL_DEVICES_SENSORS,
|
||||
CAMERA_DISABLED_SENSORS,
|
||||
CAMERA_SENSORS,
|
||||
MOTION_SENSORS,
|
||||
EVENT_SENSORS,
|
||||
MOTION_TRIP_SENSORS,
|
||||
NVR_DISABLED_SENSORS,
|
||||
NVR_SENSORS,
|
||||
|
@ -399,7 +399,7 @@ async def test_sensor_setup_camera(
|
|||
|
||||
# Detected Object
|
||||
unique_id, entity_id = ids_from_device_description(
|
||||
Platform.SENSOR, doorbell, MOTION_SENSORS[0]
|
||||
Platform.SENSOR, doorbell, EVENT_SENSORS[0]
|
||||
)
|
||||
|
||||
entity = entity_registry.async_get(entity_id)
|
||||
|
@ -455,7 +455,7 @@ async def test_sensor_update_motion(
|
|||
assert_entity_counts(hass, Platform.SENSOR, 25, 12)
|
||||
|
||||
_, entity_id = ids_from_device_description(
|
||||
Platform.SENSOR, doorbell, MOTION_SENSORS[0]
|
||||
Platform.SENSOR, doorbell, EVENT_SENSORS[0]
|
||||
)
|
||||
|
||||
await enable_entity(hass, ufp.entry.entry_id, entity_id)
|
||||
|
@ -582,7 +582,7 @@ async def test_camera_update_licenseplate(
|
|||
assert_entity_counts(hass, Platform.SENSOR, 24, 13)
|
||||
|
||||
_, entity_id = ids_from_device_description(
|
||||
Platform.SENSOR, camera, MOTION_SENSORS[1]
|
||||
Platform.SENSOR, camera, EVENT_SENSORS[1]
|
||||
)
|
||||
|
||||
event_metadata = EventMetadata(
|
||||
|
|
Loading…
Reference in New Issue