Add yolink CoSmoke Sensor and Switch (#73209)

add CoSmoke Sensor and Switch
This commit is contained in:
Matrix 2022-06-08 17:54:32 +08:00 committed by GitHub
parent 4bc04383d1
commit 79096864eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 8 deletions

View file

@ -18,6 +18,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import (
ATTR_COORDINATORS,
ATTR_DEVICE_CO_SMOKE_SENSOR,
ATTR_DEVICE_DOOR_SENSOR,
ATTR_DEVICE_LEAK_SENSOR,
ATTR_DEVICE_MOTION_SENSOR,
@ -42,8 +43,10 @@ SENSOR_DEVICE_TYPE = [
ATTR_DEVICE_MOTION_SENSOR,
ATTR_DEVICE_LEAK_SENSOR,
ATTR_DEVICE_VIBRATION_SENSOR,
ATTR_DEVICE_CO_SMOKE_SENSOR,
]
SENSOR_TYPES: tuple[YoLinkBinarySensorEntityDescription, ...] = (
YoLinkBinarySensorEntityDescription(
key="door_state",
@ -51,14 +54,14 @@ SENSOR_TYPES: tuple[YoLinkBinarySensorEntityDescription, ...] = (
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 in [ATTR_DEVICE_DOOR_SENSOR],
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 in [ATTR_DEVICE_MOTION_SENSOR],
exists_fn=lambda device: device.device_type == ATTR_DEVICE_MOTION_SENSOR,
),
YoLinkBinarySensorEntityDescription(
key="leak_state",
@ -66,14 +69,28 @@ SENSOR_TYPES: tuple[YoLinkBinarySensorEntityDescription, ...] = (
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 in [ATTR_DEVICE_LEAK_SENSOR],
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 in [ATTR_DEVICE_VIBRATION_SENSOR],
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,
),
)