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: def _async_update_device_from_protect(self, device: ProtectModelWithId) -> None:
# do not call ProtectDeviceSensor method since we want event to get value here # do not call ProtectDeviceSensor method since we want event to get value here
EventEntityMixin._async_update_device_from_protect(self, device) 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 self.entity_description.ufp_smart_type
== SmartDetectObjectType.LICENSE_PLATE == SmartDetectObjectType.LICENSE_PLATE
)
if (
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
)
)
): ):
if ( self._attr_native_value = OBJECT_TYPE_NONE
self._event is None self._event = None
or self._event.metadata is None self._attr_extra_state_attributes = {}
or self._event.metadata.license_plate is None return
):
self._attr_native_value = OBJECT_TYPE_NONE if is_license_plate:
else: # type verified above
self._attr_native_value = self._event.metadata.license_plate.name self._attr_native_value = self._event.metadata.license_plate.name # type: ignore[union-attr]
else: else:
if self._event is None: self._attr_native_value = self._event.smart_detect_types[0].value
self._attr_native_value = OBJECT_TYPE_NONE
else:
self._attr_native_value = self._event.smart_detect_types[0].value