mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Remove unreachable sensor code in unifiprotect (#119501)
This commit is contained in:
parent
0f0c2f0553
commit
db3029dc5f
@ -520,7 +520,7 @@ NVR_DISABLED_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
EVENT_SENSORS: tuple[ProtectSensorEventEntityDescription, ...] = (
|
LICENSE_PLATE_EVENT_SENSORS: tuple[ProtectSensorEventEntityDescription, ...] = (
|
||||||
ProtectSensorEventEntityDescription(
|
ProtectSensorEventEntityDescription(
|
||||||
key="smart_obj_licenseplate",
|
key="smart_obj_licenseplate",
|
||||||
name="License Plate Detected",
|
name="License Plate Detected",
|
||||||
@ -678,11 +678,11 @@ def _async_event_entities(
|
|||||||
if not device.feature_flags.has_smart_detect:
|
if not device.feature_flags.has_smart_detect:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for event_desc in EVENT_SENSORS:
|
for event_desc in LICENSE_PLATE_EVENT_SENSORS:
|
||||||
if not event_desc.has_required(device):
|
if not event_desc.has_required(device):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entities.append(ProtectEventSensor(data, device, event_desc))
|
entities.append(ProtectLicensePlateEventSensor(data, device, event_desc))
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Adding sensor entity %s for %s",
|
"Adding sensor entity %s for %s",
|
||||||
description.name,
|
description.name,
|
||||||
@ -750,35 +750,6 @@ class ProtectEventSensor(EventEntityMixin, SensorEntity):
|
|||||||
|
|
||||||
entity_description: ProtectSensorEventEntityDescription
|
entity_description: ProtectSensorEventEntityDescription
|
||||||
|
|
||||||
@callback
|
|
||||||
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) # noqa: SLF001
|
|
||||||
event = self._event
|
|
||||||
entity_description = self.entity_description
|
|
||||||
is_on = entity_description.get_is_on(self.device, self._event)
|
|
||||||
is_license_plate = (
|
|
||||||
entity_description.ufp_event_obj == "last_license_plate_detect_event"
|
|
||||||
)
|
|
||||||
if (
|
|
||||||
not is_on
|
|
||||||
or event is None
|
|
||||||
or (
|
|
||||||
is_license_plate
|
|
||||||
and (event.metadata is None or event.metadata.license_plate 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 = event.metadata.license_plate.name # type: ignore[union-attr]
|
|
||||||
else:
|
|
||||||
self._attr_native_value = event.smart_detect_types[0].value
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_get_state_attrs(self) -> tuple[Any, ...]:
|
def _async_get_state_attrs(self) -> tuple[Any, ...]:
|
||||||
"""Retrieve data that goes into the current state of the entity.
|
"""Retrieve data that goes into the current state of the entity.
|
||||||
@ -792,3 +763,24 @@ class ProtectEventSensor(EventEntityMixin, SensorEntity):
|
|||||||
self._attr_native_value,
|
self._attr_native_value,
|
||||||
self._attr_extra_state_attributes,
|
self._attr_extra_state_attributes,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ProtectLicensePlateEventSensor(ProtectEventSensor):
|
||||||
|
"""A UniFi Protect license plate sensor."""
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _async_update_device_from_protect(self, device: ProtectModelWithId) -> None:
|
||||||
|
super()._async_update_device_from_protect(device)
|
||||||
|
event = self._event
|
||||||
|
entity_description = self.entity_description
|
||||||
|
if (
|
||||||
|
event is None
|
||||||
|
or (event.metadata is None or event.metadata.license_plate is None)
|
||||||
|
or not entity_description.get_is_on(self.device, event)
|
||||||
|
):
|
||||||
|
self._attr_native_value = OBJECT_TYPE_NONE
|
||||||
|
self._event = None
|
||||||
|
self._attr_extra_state_attributes = {}
|
||||||
|
return
|
||||||
|
|
||||||
|
self._attr_native_value = event.metadata.license_plate.name
|
||||||
|
@ -14,7 +14,7 @@ from homeassistant.components.unifiprotect.sensor import (
|
|||||||
ALL_DEVICES_SENSORS,
|
ALL_DEVICES_SENSORS,
|
||||||
CAMERA_DISABLED_SENSORS,
|
CAMERA_DISABLED_SENSORS,
|
||||||
CAMERA_SENSORS,
|
CAMERA_SENSORS,
|
||||||
EVENT_SENSORS,
|
LICENSE_PLATE_EVENT_SENSORS,
|
||||||
MOTION_TRIP_SENSORS,
|
MOTION_TRIP_SENSORS,
|
||||||
NVR_DISABLED_SENSORS,
|
NVR_DISABLED_SENSORS,
|
||||||
NVR_SENSORS,
|
NVR_SENSORS,
|
||||||
@ -514,7 +514,7 @@ async def test_camera_update_licenseplate(
|
|||||||
assert_entity_counts(hass, Platform.SENSOR, 23, 13)
|
assert_entity_counts(hass, Platform.SENSOR, 23, 13)
|
||||||
|
|
||||||
_, entity_id = ids_from_device_description(
|
_, entity_id = ids_from_device_description(
|
||||||
Platform.SENSOR, camera, EVENT_SENSORS[0]
|
Platform.SENSOR, camera, LICENSE_PLATE_EVENT_SENSORS[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
event_metadata = EventMetadata(
|
event_metadata = EventMetadata(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user