Add yolink sensors (#72186)

* Add more sensor support

* change codeowner to active account

* fix suggest
This commit is contained in:
Matrix 2022-05-21 01:06:47 +08:00 committed by GitHub
parent 5866bf48da
commit 1e7b187fc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 11 deletions

View File

@ -1201,8 +1201,8 @@ build.json @home-assistant/supervisor
/tests/components/yeelight/ @zewelor @shenxn @starkillerOG @alexyao2015
/homeassistant/components/yeelightsunflower/ @lindsaymarkward
/homeassistant/components/yi/ @bachya
/homeassistant/components/yolink/ @YoSmart-Inc
/tests/components/yolink/ @YoSmart-Inc
/homeassistant/components/yolink/ @matrixd2
/tests/components/yolink/ @matrixd2
/homeassistant/components/youless/ @gjong
/tests/components/youless/ @gjong
/homeassistant/components/zengge/ @emontnemery

View File

@ -15,7 +15,13 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import ATTR_COORDINATOR, ATTR_DEVICE_DOOR_SENSOR, DOMAIN
from .const import (
ATTR_COORDINATOR,
ATTR_DEVICE_DOOR_SENSOR,
ATTR_DEVICE_LEAK_SENSOR,
ATTR_DEVICE_MOTION_SENSOR,
DOMAIN,
)
from .coordinator import YoLinkCoordinator
from .entity import YoLinkEntity
@ -25,20 +31,37 @@ class YoLinkBinarySensorEntityDescription(BinarySensorEntityDescription):
"""YoLink BinarySensorEntityDescription."""
exists_fn: Callable[[YoLinkDevice], bool] = lambda _: True
key: str = "state"
value: Callable[[str], bool | None] = lambda _: None
SENSOR_DEVICE_TYPE = [ATTR_DEVICE_DOOR_SENSOR]
SENSOR_DEVICE_TYPE = [
ATTR_DEVICE_DOOR_SENSOR,
ATTR_DEVICE_MOTION_SENSOR,
ATTR_DEVICE_LEAK_SENSOR,
]
SENSOR_TYPES: tuple[YoLinkBinarySensorEntityDescription, ...] = (
YoLinkBinarySensorEntityDescription(
key="state",
icon="mdi:door",
device_class=BinarySensorDeviceClass.DOOR,
name="state",
name="State",
value=lambda value: value == "open",
exists_fn=lambda device: device.device_type in [ATTR_DEVICE_DOOR_SENSOR],
),
YoLinkBinarySensorEntityDescription(
device_class=BinarySensorDeviceClass.MOTION,
name="Motion",
value=lambda value: value == "alert",
exists_fn=lambda device: device.device_type in [ATTR_DEVICE_MOTION_SENSOR],
),
YoLinkBinarySensorEntityDescription(
name="Leak",
icon="mdi:water",
device_class=BinarySensorDeviceClass.MOISTURE,
value=lambda value: value == "alert",
exists_fn=lambda device: device.device_type in [ATTR_DEVICE_LEAK_SENSOR],
),
)

View File

@ -14,3 +14,6 @@ ATTR_CLIENT = "client"
ATTR_MQTT_CLIENT = "mqtt_client"
ATTR_DEVICE_ID = "deviceId"
ATTR_DEVICE_DOOR_SENSOR = "DoorSensor"
ATTR_DEVICE_TH_SENSOR = "THSensor"
ATTR_DEVICE_MOTION_SENSOR = "MotionSensor"
ATTR_DEVICE_LEAK_SENSOR = "LeakSensor"

View File

@ -5,6 +5,6 @@
"documentation": "https://www.home-assistant.io/integrations/yolink",
"requirements": ["yolink-api==0.0.5"],
"dependencies": ["auth", "application_credentials"],
"codeowners": ["@YoSmart-Inc"],
"codeowners": ["@matrixd2"],
"iot_class": "cloud_push"
}

View File

@ -13,12 +13,18 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import percentage
from .const import ATTR_COORDINATOR, ATTR_DEVICE_DOOR_SENSOR, DOMAIN
from .const import (
ATTR_COORDINATOR,
ATTR_DEVICE_DOOR_SENSOR,
ATTR_DEVICE_MOTION_SENSOR,
ATTR_DEVICE_TH_SENSOR,
DOMAIN,
)
from .coordinator import YoLinkCoordinator
from .entity import YoLinkEntity
@ -49,11 +55,32 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = (
value=lambda value: percentage.ordered_list_item_to_percentage(
[1, 2, 3, 4], value
),
exists_fn=lambda device: device.device_type in [ATTR_DEVICE_DOOR_SENSOR],
exists_fn=lambda device: device.device_type
in [ATTR_DEVICE_DOOR_SENSOR, ATTR_DEVICE_TH_SENSOR, ATTR_DEVICE_MOTION_SENSOR],
),
YoLinkSensorEntityDescription(
key="humidity",
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE,
name="Humidity",
state_class=SensorStateClass.MEASUREMENT,
exists_fn=lambda device: device.device_type in [ATTR_DEVICE_TH_SENSOR],
),
YoLinkSensorEntityDescription(
key="temperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=TEMP_CELSIUS,
name="Temperature",
state_class=SensorStateClass.MEASUREMENT,
exists_fn=lambda device: device.device_type in [ATTR_DEVICE_TH_SENSOR],
),
)
SENSOR_DEVICE_TYPE = [ATTR_DEVICE_DOOR_SENSOR]
SENSOR_DEVICE_TYPE = [
ATTR_DEVICE_DOOR_SENSOR,
ATTR_DEVICE_MOTION_SENSOR,
ATTR_DEVICE_TH_SENSOR,
]
async def async_setup_entry(