From 96bcbb43c42d26790fec5e2baafa14ab62b61126 Mon Sep 17 00:00:00 2001 From: Vitalii Martyniak Date: Tue, 11 Aug 2020 20:38:45 +0300 Subject: [PATCH] Add power sensor for Aqara Wall Plug (#38672) --- homeassistant/components/xiaomi_aqara/const.py | 6 ++++++ homeassistant/components/xiaomi_aqara/sensor.py | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/xiaomi_aqara/const.py b/homeassistant/components/xiaomi_aqara/const.py index 58932d7a0bc..0eb117cdf3c 100644 --- a/homeassistant/components/xiaomi_aqara/const.py +++ b/homeassistant/components/xiaomi_aqara/const.py @@ -53,3 +53,9 @@ BATTERY_MODELS = [ "lock.aq1", "lock.acn02", ] + +POWER_MODELS = [ + "86plug", + "ctrl_86plug", + "ctrl_86plug.aq1", +] diff --git a/homeassistant/components/xiaomi_aqara/sensor.py b/homeassistant/components/xiaomi_aqara/sensor.py index 3463cded56d..471011eab6e 100644 --- a/homeassistant/components/xiaomi_aqara/sensor.py +++ b/homeassistant/components/xiaomi_aqara/sensor.py @@ -6,14 +6,16 @@ from homeassistant.const import ( DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, + DEVICE_CLASS_POWER, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, + POWER_WATT, TEMP_CELSIUS, UNIT_PERCENTAGE, ) from . import XiaomiDevice -from .const import BATTERY_MODELS, DOMAIN, GATEWAYS_KEY +from .const import BATTERY_MODELS, DOMAIN, GATEWAYS_KEY, POWER_MODELS _LOGGER = logging.getLogger(__name__) @@ -24,6 +26,7 @@ SENSOR_TYPES = { "lux": ["lx", None, DEVICE_CLASS_ILLUMINANCE], "pressure": ["hPa", None, DEVICE_CLASS_PRESSURE], "bed_activity": ["μm", None, None], + "load_power": [POWER_WATT, None, DEVICE_CLASS_POWER], } @@ -89,7 +92,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities): entities.append( XiaomiBatterySensor(device, "Battery", gateway, config_entry) ) - + if device["model"] in POWER_MODELS: + entities.append( + XiaomiSensor( + device, "Load Power", "load_power", gateway, config_entry + ) + ) async_add_entities(entities)