Fix dropped unifiprotect motion events (#120489)

This commit is contained in:
J. Nick Koston 2024-06-26 08:32:43 +02:00 committed by GitHub
parent 6fb32db151
commit 07b70cba10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 31 deletions

View file

@ -437,9 +437,6 @@ EVENT_SENSORS: tuple[ProtectBinaryEventEntityDescription, ...] = (
ufp_enabled="is_motion_detection_on",
ufp_event_obj="last_motion_event",
),
)
SMART_EVENT_SENSORS: tuple[ProtectBinaryEventEntityDescription, ...] = (
ProtectBinaryEventEntityDescription(
key="smart_obj_any",
name="Object detected",
@ -711,26 +708,6 @@ class ProtectEventBinarySensor(EventEntityMixin, BinarySensorEntity):
entity_description: ProtectBinaryEventEntityDescription
_state_attrs = ("_attr_available", "_attr_is_on", "_attr_extra_state_attributes")
@callback
def _async_update_device_from_protect(self, device: ProtectModelWithId) -> None:
super()._async_update_device_from_protect(device)
description = self.entity_description
event = self.entity_description.get_event_obj(device)
if is_on := bool(description.get_ufp_value(device)):
if event:
self._set_event_attrs(event)
else:
self._attr_extra_state_attributes = {}
self._attr_is_on = is_on
class ProtectSmartEventBinarySensor(EventEntityMixin, BinarySensorEntity):
"""A UniFi Protect Device Binary Sensor for smart events."""
device: Camera
entity_description: ProtectBinaryEventEntityDescription
_state_attrs = ("_attr_available", "_attr_is_on", "_attr_extra_state_attributes")
@callback
def _set_event_done(self) -> None:
self._attr_is_on = False
@ -749,7 +726,10 @@ class ProtectSmartEventBinarySensor(EventEntityMixin, BinarySensorEntity):
if not (
event
and description.has_matching_smart(event)
and (
description.ufp_obj_type is None
or description.has_matching_smart(event)
)
and not self._event_already_ended(prev_event, prev_event_end)
):
self._set_event_done()
@ -774,11 +754,6 @@ def _async_event_entities(
) -> list[ProtectDeviceEntity]:
entities: list[ProtectDeviceEntity] = []
for device in data.get_cameras() if ufp_device is None else [ufp_device]:
entities.extend(
ProtectSmartEventBinarySensor(data, device, description)
for description in SMART_EVENT_SENSORS
if description.has_required(device)
)
entities.extend(
ProtectEventBinarySensor(data, device, description)
for description in EVENT_SENSORS

View file

@ -25,7 +25,6 @@ from homeassistant.components.unifiprotect.binary_sensor import (
LIGHT_SENSORS,
MOUNTABLE_SENSE_SENSORS,
SENSE_SENSORS,
SMART_EVENT_SENSORS,
)
from homeassistant.components.unifiprotect.const import (
ATTR_EVENT_SCORE,
@ -453,7 +452,7 @@ async def test_binary_sensor_package_detected(
doorbell.smart_detect_settings.object_types.append(SmartDetectObjectType.PACKAGE)
_, entity_id = ids_from_device_description(
Platform.BINARY_SENSOR, doorbell, SMART_EVENT_SENSORS[4]
Platform.BINARY_SENSOR, doorbell, EVENT_SENSORS[6]
)
event = Event(