Migrate Yolink to has entity name (#96839)

* Migrate Yolink to has entity name

* Add sensor
This commit is contained in:
Joost Lekkerkerker 2023-07-18 13:58:42 +02:00 committed by GitHub
parent 8a9f117bdc
commit 8dc5f73789
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 73 additions and 41 deletions

View file

@ -51,42 +51,35 @@ SENSOR_TYPES: tuple[YoLinkBinarySensorEntityDescription, ...] = (
key="door_state",
icon="mdi:door",
device_class=BinarySensorDeviceClass.DOOR,
name="State",
value=lambda value: value == "open" if value is not None else None,
exists_fn=lambda device: device.device_type == ATTR_DEVICE_DOOR_SENSOR,
),
YoLinkBinarySensorEntityDescription(
key="motion_state",
device_class=BinarySensorDeviceClass.MOTION,
name="Motion",
value=lambda value: value == "alert" if value is not None else None,
exists_fn=lambda device: device.device_type == ATTR_DEVICE_MOTION_SENSOR,
),
YoLinkBinarySensorEntityDescription(
key="leak_state",
name="Leak",
icon="mdi:water",
device_class=BinarySensorDeviceClass.MOISTURE,
value=lambda value: value == "alert" if value is not None else None,
exists_fn=lambda device: device.device_type == ATTR_DEVICE_LEAK_SENSOR,
),
YoLinkBinarySensorEntityDescription(
key="vibration_state",
name="Vibration",
device_class=BinarySensorDeviceClass.VIBRATION,
value=lambda value: value == "alert" if value is not None else None,
exists_fn=lambda device: device.device_type == ATTR_DEVICE_VIBRATION_SENSOR,
),
YoLinkBinarySensorEntityDescription(
key="co_detected",
name="Co Detected",
device_class=BinarySensorDeviceClass.CO,
value=lambda state: state.get("gasAlarm"),
exists_fn=lambda device: device.device_type == ATTR_DEVICE_CO_SMOKE_SENSOR,
),
YoLinkBinarySensorEntityDescription(
key="smoke_detected",
name="Smoke Detected",
device_class=BinarySensorDeviceClass.SMOKE,
value=lambda state: state.get("smokeAlarm"),
exists_fn=lambda device: device.device_type == ATTR_DEVICE_CO_SMOKE_SENSOR,
@ -135,9 +128,6 @@ class YoLinkBinarySensorEntity(YoLinkEntity, BinarySensorEntity):
self._attr_unique_id = (
f"{coordinator.device.device_id} {self.entity_description.key}"
)
self._attr_name = (
f"{coordinator.device.device_name} ({self.entity_description.name})"
)
@callback
def update_entity_state(self, state: dict[str, Any]) -> None: