Add YoLink YS8017 support (#122064)

This commit is contained in:
Matrix 2024-07-19 18:20:30 +08:00 committed by GitHub
parent 16434b5306
commit 8cb7e9785f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -17,3 +17,5 @@ YOLINK_OFFLINE_TIME = 32400
DEV_MODEL_WATER_METER_YS5007 = "YS5007" DEV_MODEL_WATER_METER_YS5007 = "YS5007"
DEV_MODEL_MULTI_OUTLET_YS6801 = "YS6801" DEV_MODEL_MULTI_OUTLET_YS6801 = "YS6801"
DEV_MODEL_TH_SENSOR_YS8017_UC = "YS8017-UC"
DEV_MODEL_TH_SENSOR_YS8017_EC = "YS8017-EC"

View File

@ -48,7 +48,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import percentage from homeassistant.util import percentage
from .const import DOMAIN from .const import DEV_MODEL_TH_SENSOR_YS8017_EC, DEV_MODEL_TH_SENSOR_YS8017_UC, DOMAIN
from .coordinator import YoLinkCoordinator from .coordinator import YoLinkCoordinator
from .entity import YoLinkEntity from .entity import YoLinkEntity
@ -108,6 +108,11 @@ MCU_DEV_TEMPERATURE_SENSOR = [
ATTR_DEVICE_CO_SMOKE_SENSOR, ATTR_DEVICE_CO_SMOKE_SENSOR,
] ]
NONE_HUMIDITY_SENSOR_MODELS = [
DEV_MODEL_TH_SENSOR_YS8017_UC,
DEV_MODEL_TH_SENSOR_YS8017_EC,
]
def cvt_battery(val: int | None) -> int | None: def cvt_battery(val: int | None) -> int | None:
"""Convert battery to percentage.""" """Convert battery to percentage."""
@ -141,7 +146,8 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = (
device_class=SensorDeviceClass.HUMIDITY, device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
exists_fn=lambda device: device.device_type in [ATTR_DEVICE_TH_SENSOR], exists_fn=lambda device: device.device_type in [ATTR_DEVICE_TH_SENSOR]
and device.device_model_name not in NONE_HUMIDITY_SENSOR_MODELS,
), ),
YoLinkSensorEntityDescription( YoLinkSensorEntityDescription(
key="temperature", key="temperature",