From a5890b237420bd70194e1bdb84d35380d45fb2dc Mon Sep 17 00:00:00 2001 From: an0nfunc <40771419+an0nfunc@users.noreply.github.com> Date: Tue, 29 Nov 2022 10:29:34 +0100 Subject: [PATCH] Support xiaomi_miio Smartmi Air Purifier (zhimi.airpurifier.za1) (#80387) --- homeassistant/components/xiaomi_miio/const.py | 19 ++++++++++++------- homeassistant/components/xiaomi_miio/fan.py | 9 +++++++++ .../components/xiaomi_miio/number.py | 3 +++ .../components/xiaomi_miio/select.py | 4 ++++ .../components/xiaomi_miio/sensor.py | 19 +++++++++++++++++++ .../components/xiaomi_miio/switch.py | 3 +++ 6 files changed, 50 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/xiaomi_miio/const.py b/homeassistant/components/xiaomi_miio/const.py index 0c090a58e02..6621e41e7aa 100644 --- a/homeassistant/components/xiaomi_miio/const.py +++ b/homeassistant/components/xiaomi_miio/const.py @@ -1,8 +1,13 @@ """Constants for the Xiaomi Miio component.""" -from miio.vacuum import ( +from miio.integrations.vacuum.roborock.vacuum import ( + ROCKROBO_E2, + ROCKROBO_S4, + ROCKROBO_S4_MAX, ROCKROBO_S5, + ROCKROBO_S5_MAX, ROCKROBO_S6, ROCKROBO_S6_MAXV, + ROCKROBO_S6_PURE, ROCKROBO_S7, ROCKROBO_S7_MAXV, ROCKROBO_V1, @@ -70,6 +75,7 @@ MODEL_AIRPURIFIER_V1 = "zhimi.airpurifier.v1" MODEL_AIRPURIFIER_V2 = "zhimi.airpurifier.v2" MODEL_AIRPURIFIER_V3 = "zhimi.airpurifier.v3" MODEL_AIRPURIFIER_V5 = "zhimi.airpurifier.v5" +MODEL_AIRPURIFIER_ZA1 = "zhimi.airpurifier.za1" MODEL_AIRHUMIDIFIER_V1 = "zhimi.humidifier.v1" MODEL_AIRHUMIDIFIER_CA1 = "zhimi.humidifier.ca1" @@ -124,6 +130,7 @@ MODELS_PURIFIER_MIOT = [ MODEL_AIRPURIFIER_4_LITE_RMB1, MODEL_AIRPURIFIER_4, MODEL_AIRPURIFIER_4_PRO, + MODEL_AIRPURIFIER_ZA1, ] MODELS_PURIFIER_MIIO = [ MODEL_AIRPURIFIER_V1, @@ -213,12 +220,6 @@ MODELS_LIGHT = ( + MODELS_LIGHT_MONO ) -# TODO: use const from pythonmiio once new release with the constant has been published. # pylint: disable=fixme -ROCKROBO_S4 = "roborock.vacuum.s4" -ROCKROBO_S4_MAX = "roborock.vacuum.a19" -ROCKROBO_S5_MAX = "roborock.vacuum.s5e" -ROCKROBO_S6_PURE = "roborock.vacuum.a08" -ROCKROBO_E2 = "roborock.vacuum.e2" ROBOROCK_GENERIC = "roborock.vacuum" ROCKROBO_GENERIC = "rockrobo.vacuum" MODELS_VACUUM = [ @@ -397,6 +398,10 @@ FEATURE_FLAGS_AIRPURIFIER_V3 = ( FEATURE_SET_BUZZER | FEATURE_SET_CHILD_LOCK | FEATURE_SET_LED ) +FEATURE_FLAGS_AIRPURIFIER_ZA1 = ( + FEATURE_SET_BUZZER | FEATURE_SET_CHILD_LOCK | FEATURE_SET_FAVORITE_LEVEL +) + FEATURE_FLAGS_AIRHUMIDIFIER = ( FEATURE_SET_BUZZER | FEATURE_SET_CHILD_LOCK | FEATURE_SET_TARGET_HUMIDITY ) diff --git a/homeassistant/components/xiaomi_miio/fan.py b/homeassistant/components/xiaomi_miio/fan.py index dbc8c7a66d9..7153247e7d2 100644 --- a/homeassistant/components/xiaomi_miio/fan.py +++ b/homeassistant/components/xiaomi_miio/fan.py @@ -55,6 +55,7 @@ from .const import ( FEATURE_FLAGS_AIRPURIFIER_PRO, FEATURE_FLAGS_AIRPURIFIER_PRO_V7, FEATURE_FLAGS_AIRPURIFIER_V3, + FEATURE_FLAGS_AIRPURIFIER_ZA1, FEATURE_FLAGS_FAN, FEATURE_FLAGS_FAN_1C, FEATURE_FLAGS_FAN_P5, @@ -77,6 +78,7 @@ from .const import ( MODEL_AIRPURIFIER_PRO, MODEL_AIRPURIFIER_PRO_V7, MODEL_AIRPURIFIER_V3, + MODEL_AIRPURIFIER_ZA1, MODEL_FAN_1C, MODEL_FAN_P5, MODEL_FAN_P9, @@ -160,6 +162,7 @@ PRESET_MODES_AIRPURIFIER_PRO = ["Auto", "Silent", "Favorite"] PRESET_MODES_AIRPURIFIER_PRO_V7 = PRESET_MODES_AIRPURIFIER_PRO PRESET_MODES_AIRPURIFIER_2S = ["Auto", "Silent", "Favorite"] PRESET_MODES_AIRPURIFIER_3C = ["Auto", "Silent", "Favorite"] +PRESET_MODES_AIRPURIFIER_ZA1 = ["Auto", "Silent", "Favorite"] PRESET_MODES_AIRPURIFIER_V3 = [ "Auto", "Silent", @@ -449,6 +452,12 @@ class XiaomiAirPurifier(XiaomiGenericAirPurifier): self._preset_modes = PRESET_MODES_AIRPURIFIER_2S self._attr_supported_features = FanEntityFeature.PRESET_MODE self._speed_count = 1 + elif self._model == MODEL_AIRPURIFIER_ZA1: + self._device_features = FEATURE_FLAGS_AIRPURIFIER_ZA1 + self._available_attributes = AVAILABLE_ATTRIBUTES_AIRPURIFIER_MIOT + self._preset_modes = PRESET_MODES_AIRPURIFIER_ZA1 + self._attr_supported_features = FanEntityFeature.PRESET_MODE + self._speed_count = 1 elif self._model in MODELS_PURIFIER_MIOT: self._device_features = FEATURE_FLAGS_AIRPURIFIER_MIOT self._available_attributes = AVAILABLE_ATTRIBUTES_AIRPURIFIER_MIOT diff --git a/homeassistant/components/xiaomi_miio/number.py b/homeassistant/components/xiaomi_miio/number.py index 7c5439d8d35..869379530fc 100644 --- a/homeassistant/components/xiaomi_miio/number.py +++ b/homeassistant/components/xiaomi_miio/number.py @@ -39,6 +39,7 @@ from .const import ( FEATURE_FLAGS_AIRPURIFIER_PRO_V7, FEATURE_FLAGS_AIRPURIFIER_V1, FEATURE_FLAGS_AIRPURIFIER_V3, + FEATURE_FLAGS_AIRPURIFIER_ZA1, FEATURE_FLAGS_FAN, FEATURE_FLAGS_FAN_1C, FEATURE_FLAGS_FAN_P5, @@ -73,6 +74,7 @@ from .const import ( MODEL_AIRPURIFIER_PRO_V7, MODEL_AIRPURIFIER_V1, MODEL_AIRPURIFIER_V3, + MODEL_AIRPURIFIER_ZA1, MODEL_FAN_1C, MODEL_FAN_P5, MODEL_FAN_P9, @@ -249,6 +251,7 @@ MODEL_TO_FEATURES_MAP = { MODEL_AIRPURIFIER_4_LITE_RMB1: FEATURE_FLAGS_AIRPURIFIER_4_LITE, MODEL_AIRPURIFIER_4: FEATURE_FLAGS_AIRPURIFIER_4, MODEL_AIRPURIFIER_4_PRO: FEATURE_FLAGS_AIRPURIFIER_4, + MODEL_AIRPURIFIER_ZA1: FEATURE_FLAGS_AIRPURIFIER_ZA1, MODEL_FAN_1C: FEATURE_FLAGS_FAN_1C, MODEL_FAN_P10: FEATURE_FLAGS_FAN_P10_P11, MODEL_FAN_P11: FEATURE_FLAGS_FAN_P10_P11, diff --git a/homeassistant/components/xiaomi_miio/select.py b/homeassistant/components/xiaomi_miio/select.py index 9b5f0f50a06..87cafe3c58a 100644 --- a/homeassistant/components/xiaomi_miio/select.py +++ b/homeassistant/components/xiaomi_miio/select.py @@ -53,6 +53,7 @@ from .const import ( MODEL_AIRPURIFIER_M1, MODEL_AIRPURIFIER_M2, MODEL_AIRPURIFIER_PROH, + MODEL_AIRPURIFIER_ZA1, MODEL_FAN_SA1, MODEL_FAN_V2, MODEL_FAN_V3, @@ -113,6 +114,9 @@ MODEL_TO_ATTR_MAP: dict[str, list] = { MODEL_AIRPURIFIER_3: [ AttributeEnumMapping(ATTR_LED_BRIGHTNESS, AirpurifierMiotLedBrightness) ], + MODEL_AIRPURIFIER_ZA1: [ + AttributeEnumMapping(ATTR_LED_BRIGHTNESS, AirpurifierMiotLedBrightness) + ], MODEL_AIRPURIFIER_3H: [ AttributeEnumMapping(ATTR_LED_BRIGHTNESS, AirpurifierMiotLedBrightness) ], diff --git a/homeassistant/components/xiaomi_miio/sensor.py b/homeassistant/components/xiaomi_miio/sensor.py index 56938a4bd34..a83f3ef528d 100644 --- a/homeassistant/components/xiaomi_miio/sensor.py +++ b/homeassistant/components/xiaomi_miio/sensor.py @@ -70,6 +70,7 @@ from .const import ( MODEL_AIRPURIFIER_PRO_V7, MODEL_AIRPURIFIER_V2, MODEL_AIRPURIFIER_V3, + MODEL_AIRPURIFIER_ZA1, MODEL_FAN_P5, MODEL_FAN_V2, MODEL_FAN_V3, @@ -97,6 +98,7 @@ UNIT_LUMEN = "lm" ATTR_ACTUAL_SPEED = "actual_speed" ATTR_AIR_QUALITY = "air_quality" +ATTR_TVOC = "tvoc" ATTR_AQI = "aqi" ATTR_BATTERY = "battery" ATTR_CARBON_DIOXIDE = "co2" @@ -262,6 +264,13 @@ SENSOR_TYPES = { icon="mdi:cloud", state_class=SensorStateClass.MEASUREMENT, ), + ATTR_TVOC: XiaomiMiioSensorDescription( + key=ATTR_TVOC, + name="TVOC", + state_class=SensorStateClass.MEASUREMENT, + native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS, + ), ATTR_PM10: XiaomiMiioSensorDescription( key=ATTR_PM10, name="PM10", @@ -452,6 +461,15 @@ PURIFIER_3C_SENSORS = ( ATTR_MOTOR_SPEED, ATTR_PM25, ) +PURIFIER_ZA1_SENSORS = ( + ATTR_FILTER_LIFE_REMAINING, + ATTR_FILTER_USE, + ATTR_MOTOR_SPEED, + ATTR_PM25, + ATTR_TVOC, + ATTR_HUMIDITY, + ATTR_TEMPERATURE, +) PURIFIER_V2_SENSORS = ( ATTR_FILTER_LIFE_REMAINING, ATTR_FILTER_USE, @@ -548,6 +566,7 @@ MODEL_TO_SENSORS_MAP: dict[str, tuple[str, ...]] = { MODEL_AIRPURIFIER_PRO_V7: PURIFIER_PRO_V7_SENSORS, MODEL_AIRPURIFIER_V2: PURIFIER_V2_SENSORS, MODEL_AIRPURIFIER_V3: PURIFIER_V3_SENSORS, + MODEL_AIRPURIFIER_ZA1: PURIFIER_ZA1_SENSORS, MODEL_FAN_V2: FAN_V2_V3_SENSORS, MODEL_FAN_V3: FAN_V2_V3_SENSORS, MODEL_FAN_ZA5: FAN_ZA5_SENSORS, diff --git a/homeassistant/components/xiaomi_miio/switch.py b/homeassistant/components/xiaomi_miio/switch.py index 2f45ba0adca..f2b7b071923 100644 --- a/homeassistant/components/xiaomi_miio/switch.py +++ b/homeassistant/components/xiaomi_miio/switch.py @@ -53,6 +53,7 @@ from .const import ( FEATURE_FLAGS_AIRPURIFIER_PRO_V7, FEATURE_FLAGS_AIRPURIFIER_V1, FEATURE_FLAGS_AIRPURIFIER_V3, + FEATURE_FLAGS_AIRPURIFIER_ZA1, FEATURE_FLAGS_FAN, FEATURE_FLAGS_FAN_1C, FEATURE_FLAGS_FAN_P5, @@ -90,6 +91,7 @@ from .const import ( MODEL_AIRPURIFIER_PRO_V7, MODEL_AIRPURIFIER_V1, MODEL_AIRPURIFIER_V3, + MODEL_AIRPURIFIER_ZA1, MODEL_FAN_1C, MODEL_FAN_P5, MODEL_FAN_P9, @@ -204,6 +206,7 @@ MODEL_TO_FEATURES_MAP = { MODEL_AIRPURIFIER_4_LITE_RMB1: FEATURE_FLAGS_AIRPURIFIER_4_LITE, MODEL_AIRPURIFIER_4: FEATURE_FLAGS_AIRPURIFIER_4, MODEL_AIRPURIFIER_4_PRO: FEATURE_FLAGS_AIRPURIFIER_4, + MODEL_AIRPURIFIER_ZA1: FEATURE_FLAGS_AIRPURIFIER_ZA1, MODEL_FAN_1C: FEATURE_FLAGS_FAN_1C, MODEL_FAN_P10: FEATURE_FLAGS_FAN_P10_P11, MODEL_FAN_P11: FEATURE_FLAGS_FAN_P10_P11,