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

@ -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(