Migrate Unifi Protect last tripped time attributes to their own entities (#68347)
This commit is contained in:
parent
9a396c1d16
commit
63ca0e70be
4 changed files with 139 additions and 42 deletions
|
@ -186,6 +186,15 @@ CAMERA_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
|||
ufp_required_field="voltage",
|
||||
precision=2,
|
||||
),
|
||||
ProtectSensorEntityDescription(
|
||||
key="doorbell_last_trip_time",
|
||||
name="Last Doorbell Ring",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
icon="mdi:doorbell-video",
|
||||
ufp_required_field="feature_flags.has_chime",
|
||||
ufp_value="last_ring",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
)
|
||||
|
||||
CAMERA_DISABLED_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
||||
|
@ -252,6 +261,27 @@ SENSE_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
|||
ufp_value_fn=_get_alarm_sound,
|
||||
ufp_enabled="is_alarm_sensor_enabled",
|
||||
),
|
||||
ProtectSensorEntityDescription(
|
||||
key="door_last_trip_time",
|
||||
name="Last Open",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
ufp_value="open_status_changed_at",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
ProtectSensorEntityDescription(
|
||||
key="motion_last_trip_time",
|
||||
name="Last Motion Detected",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
ufp_value="motion_detected_at",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
ProtectSensorEntityDescription(
|
||||
key="tampering_last_trip_time",
|
||||
name="Last Tampering Detected",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
ufp_value="tampering_detected_at",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
)
|
||||
|
||||
DOORLOCK_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
||||
|
@ -399,6 +429,27 @@ MOTION_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
|||
)
|
||||
|
||||
|
||||
LIGHT_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
||||
ProtectSensorEntityDescription(
|
||||
key="motion_last_trip_time",
|
||||
name="Last Motion Detected",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
ufp_value="last_motion",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
)
|
||||
|
||||
MOTION_TRIP_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
||||
ProtectSensorEntityDescription(
|
||||
key="motion_last_trip_time",
|
||||
name="Last Motion Detected",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
ufp_value="last_motion",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
|
@ -412,6 +463,7 @@ async def async_setup_entry(
|
|||
all_descs=ALL_DEVICES_SENSORS,
|
||||
camera_descs=CAMERA_SENSORS + CAMERA_DISABLED_SENSORS,
|
||||
sense_descs=SENSE_SENSORS,
|
||||
light_descs=LIGHT_SENSORS,
|
||||
lock_descs=DOORLOCK_SENSORS,
|
||||
)
|
||||
entities += _async_motion_entities(data)
|
||||
|
@ -426,6 +478,14 @@ def _async_motion_entities(
|
|||
) -> list[ProtectDeviceEntity]:
|
||||
entities: list[ProtectDeviceEntity] = []
|
||||
for device in data.api.bootstrap.cameras.values():
|
||||
for description in MOTION_TRIP_SENSORS:
|
||||
entities.append(ProtectDeviceSensor(data, device, description))
|
||||
_LOGGER.debug(
|
||||
"Adding trip sensor entity %s for %s",
|
||||
description.name,
|
||||
device.name,
|
||||
)
|
||||
|
||||
if not device.feature_flags.has_smart_detect:
|
||||
continue
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue