Fix event sensor for UniFi Protect (#83663)
* Fix event sensor for UniFi Protect * Linting * Adds no cover * Clean up check * Linting
This commit is contained in:
parent
4fbaefe55a
commit
1f6e2511f8
1 changed files with 22 additions and 13 deletions
|
@ -772,20 +772,29 @@ class ProtectEventSensor(EventEntityMixin, SensorEntity):
|
|||
def _async_update_device_from_protect(self, device: ProtectModelWithId) -> None:
|
||||
# do not call ProtectDeviceSensor method since we want event to get value here
|
||||
EventEntityMixin._async_update_device_from_protect(self, device)
|
||||
if (
|
||||
is_on = self.entity_description.get_is_on(device)
|
||||
is_license_plate = (
|
||||
self.entity_description.ufp_smart_type
|
||||
== SmartDetectObjectType.LICENSE_PLATE
|
||||
):
|
||||
)
|
||||
if (
|
||||
self._event is None
|
||||
or self._event.metadata is None
|
||||
not is_on
|
||||
or self._event is None
|
||||
or (
|
||||
is_license_plate
|
||||
and (
|
||||
self._event.metadata is None
|
||||
or self._event.metadata.license_plate is None
|
||||
)
|
||||
)
|
||||
):
|
||||
self._attr_native_value = OBJECT_TYPE_NONE
|
||||
else:
|
||||
self._attr_native_value = self._event.metadata.license_plate.name
|
||||
else:
|
||||
if self._event is None:
|
||||
self._attr_native_value = OBJECT_TYPE_NONE
|
||||
self._event = None
|
||||
self._attr_extra_state_attributes = {}
|
||||
return
|
||||
|
||||
if is_license_plate:
|
||||
# type verified above
|
||||
self._attr_native_value = self._event.metadata.license_plate.name # type: ignore[union-attr]
|
||||
else:
|
||||
self._attr_native_value = self._event.smart_detect_types[0].value
|
||||
|
|
Loading…
Add table
Reference in a new issue