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:
Christopher Bailey 2022-12-11 10:32:26 -08:00 committed by GitHub
parent 4fbaefe55a
commit 1f6e2511f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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