From aaddeb0bcdefa735a6b5c4be3f3f905537467518 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Sun, 8 Aug 2021 15:21:55 +0200 Subject: [PATCH] Add missing `motor_speed` sensor for Xiaomi Miio humidifier CA1 and CB1 (#54264) * Add motor_speed sensor for CA1 and CB1 * Remove value limits --- .../components/xiaomi_miio/sensor.py | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/xiaomi_miio/sensor.py b/homeassistant/components/xiaomi_miio/sensor.py index 852adfcc071..c180bb75a77 100644 --- a/homeassistant/components/xiaomi_miio/sensor.py +++ b/homeassistant/components/xiaomi_miio/sensor.py @@ -49,6 +49,8 @@ from .const import ( DOMAIN, KEY_COORDINATOR, KEY_DEVICE, + MODEL_AIRHUMIDIFIER_CA1, + MODEL_AIRHUMIDIFIER_CB1, MODELS_HUMIDIFIER_MIIO, MODELS_HUMIDIFIER_MIOT, MODELS_HUMIDIFIER_MJJSQ, @@ -69,13 +71,14 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( } ) -ATTR_ACTUAL_MOTOR_SPEED = "actual_speed" +ATTR_ACTUAL_SPEED = "actual_speed" ATTR_AIR_QUALITY = "air_quality" ATTR_CHARGING = "charging" ATTR_DISPLAY_CLOCK = "display_clock" ATTR_HUMIDITY = "humidity" ATTR_ILLUMINANCE = "illuminance" ATTR_LOAD_POWER = "load_power" +ATTR_MOTOR_SPEED = "motor_speed" ATTR_NIGHT_MODE = "night_mode" ATTR_NIGHT_TIME_BEGIN = "night_time_begin" ATTR_NIGHT_TIME_END = "night_time_end" @@ -130,14 +133,19 @@ SENSOR_TYPES = { valid_min_value=0.0, valid_max_value=100.0, ), - ATTR_ACTUAL_MOTOR_SPEED: XiaomiMiioSensorDescription( - key=ATTR_ACTUAL_MOTOR_SPEED, + ATTR_ACTUAL_SPEED: XiaomiMiioSensorDescription( + key=ATTR_ACTUAL_SPEED, name="Actual Speed", unit_of_measurement="rpm", icon="mdi:fast-forward", state_class=STATE_CLASS_MEASUREMENT, - valid_min_value=200.0, - valid_max_value=2000.0, + ), + ATTR_MOTOR_SPEED: XiaomiMiioSensorDescription( + key=ATTR_MOTOR_SPEED, + name="Motor Speed", + unit_of_measurement="rpm", + icon="mdi:fast-forward", + state_class=STATE_CLASS_MEASUREMENT, ), ATTR_ILLUMINANCE: XiaomiMiioSensorDescription( key=ATTR_ILLUMINANCE, @@ -154,22 +162,15 @@ SENSOR_TYPES = { ), } -HUMIDIFIER_MIIO_SENSORS = { - ATTR_HUMIDITY: "humidity", - ATTR_TEMPERATURE: "temperature", -} - -HUMIDIFIER_MIOT_SENSORS = { - ATTR_HUMIDITY: "humidity", - ATTR_TEMPERATURE: "temperature", - ATTR_WATER_LEVEL: "water_level", - ATTR_ACTUAL_MOTOR_SPEED: "actual_speed", -} - -HUMIDIFIER_MJJSQ_SENSORS = { - ATTR_HUMIDITY: "humidity", - ATTR_TEMPERATURE: "temperature", -} +HUMIDIFIER_MIIO_SENSORS = (ATTR_HUMIDITY, ATTR_TEMPERATURE) +HUMIDIFIER_CA1_CB1_SENSORS = (ATTR_HUMIDITY, ATTR_TEMPERATURE, ATTR_MOTOR_SPEED) +HUMIDIFIER_MIOT_SENSORS = ( + ATTR_HUMIDITY, + ATTR_TEMPERATURE, + ATTR_WATER_LEVEL, + ATTR_ACTUAL_SPEED, +) +HUMIDIFIER_MJJSQ_SENSORS = (ATTR_HUMIDITY, ATTR_TEMPERATURE) async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): @@ -225,7 +226,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities): model = config_entry.data[CONF_MODEL] device = None sensors = [] - if model in MODELS_HUMIDIFIER_MIOT: + if model in (MODEL_AIRHUMIDIFIER_CA1, MODEL_AIRHUMIDIFIER_CB1): + device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE] + sensors = HUMIDIFIER_CA1_CB1_SENSORS + elif model in MODELS_HUMIDIFIER_MIOT: device = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE] sensors = HUMIDIFIER_MIOT_SENSORS elif model in MODELS_HUMIDIFIER_MJJSQ: