diff --git a/homeassistant/components/yolink/const.py b/homeassistant/components/yolink/const.py index 686160d92489e522dfebe73a6d34081e3095970e..6fe1da0d20b0f80ed8e33aff18ba0bc995a48dcd 100644 --- a/homeassistant/components/yolink/const.py +++ b/homeassistant/components/yolink/const.py @@ -23,3 +23,7 @@ DEV_MODEL_TH_SENSOR_YS8014_UC = "YS8014-UC" DEV_MODEL_TH_SENSOR_YS8014_EC = "YS8014-EC" DEV_MODEL_TH_SENSOR_YS8017_UC = "YS8017-UC" DEV_MODEL_TH_SENSOR_YS8017_EC = "YS8017-EC" +DEV_MODEL_PLUG_YS6602_UC = "YS6602-UC" +DEV_MODEL_PLUG_YS6602_EC = "YS6602-EC" +DEV_MODEL_PLUG_YS6803_UC = "YS6803-UC" +DEV_MODEL_PLUG_YS6803_EC = "YS6803-EC" diff --git a/homeassistant/components/yolink/icons.json b/homeassistant/components/yolink/icons.json index ee9037c864a76e0c86e4e6116e913e0308a738b6..1158c9bd8f2fac4313afe321fe52ee3979468d79 100644 --- a/homeassistant/components/yolink/icons.json +++ b/homeassistant/components/yolink/icons.json @@ -17,6 +17,9 @@ }, "power_failure_alarm_beep": { "default": "mdi:bullhorn" + }, + "water_meter_reading": { + "default": "mdi:gauge" } }, "switch": { diff --git a/homeassistant/components/yolink/sensor.py b/homeassistant/components/yolink/sensor.py index 77bbccb2f6a7365e203db3d4530168d111f8fdde..b8f2a77516c7fbf136534a4383400da7cf1803be 100644 --- a/homeassistant/components/yolink/sensor.py +++ b/homeassistant/components/yolink/sensor.py @@ -40,7 +40,9 @@ from homeassistant.const import ( PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, EntityCategory, + UnitOfEnergy, UnitOfLength, + UnitOfPower, UnitOfTemperature, UnitOfVolume, ) @@ -49,6 +51,10 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.util import percentage from .const import ( + DEV_MODEL_PLUG_YS6602_EC, + DEV_MODEL_PLUG_YS6602_UC, + DEV_MODEL_PLUG_YS6803_EC, + DEV_MODEL_PLUG_YS6803_UC, DEV_MODEL_TH_SENSOR_YS8004_EC, DEV_MODEL_TH_SENSOR_YS8004_UC, DEV_MODEL_TH_SENSOR_YS8014_EC, @@ -125,6 +131,13 @@ NONE_HUMIDITY_SENSOR_MODELS = [ DEV_MODEL_TH_SENSOR_YS8017_EC, ] +POWER_SUPPORT_MODELS = [ + DEV_MODEL_PLUG_YS6602_UC, + DEV_MODEL_PLUG_YS6602_EC, + DEV_MODEL_PLUG_YS6803_UC, + DEV_MODEL_PLUG_YS6803_EC, +] + def cvt_battery(val: int | None) -> int | None: """Convert battery to percentage.""" @@ -228,13 +241,32 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( key="meter_reading", translation_key="water_meter_reading", device_class=SensorDeviceClass.WATER, - icon="mdi:gauge", native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, state_class=SensorStateClass.TOTAL_INCREASING, should_update_entity=lambda value: value is not None, exists_fn=lambda device: device.device_type in ATTR_DEVICE_WATER_METER_CONTROLLER, ), + YoLinkSensorEntityDescription( + key="power", + translation_key="current_power", + device_class=SensorDeviceClass.POWER, + native_unit_of_measurement=UnitOfPower.WATT, + state_class=SensorStateClass.MEASUREMENT, + should_update_entity=lambda value: value is not None, + exists_fn=lambda device: device.device_model_name in POWER_SUPPORT_MODELS, + value=lambda value: value / 10 if value is not None else None, + ), + YoLinkSensorEntityDescription( + key="watt", + translation_key="power_consumption", + device_class=SensorDeviceClass.ENERGY, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + state_class=SensorStateClass.TOTAL, + should_update_entity=lambda value: value is not None, + exists_fn=lambda device: device.device_model_name in POWER_SUPPORT_MODELS, + value=lambda value: value / 100 if value is not None else None, + ), ) diff --git a/homeassistant/components/yolink/strings.json b/homeassistant/components/yolink/strings.json index bc8fb435e76b3755f163f6b8af60bb23fd123296..cefc7737a7908ce1f68e85f27afb138b9c3becb2 100644 --- a/homeassistant/components/yolink/strings.json +++ b/homeassistant/components/yolink/strings.json @@ -51,6 +51,12 @@ "plug_4": { "name": "Plug 4" } }, "sensor": { + "current_power": { + "name": "Current power" + }, + "power_consumption": { + "name": "Power consumption" + }, "power_failure_alarm": { "name": "Power failure alarm", "state": {