From 258357c2cd0243ca89ad3aa25d1e696e9bd8a42b Mon Sep 17 00:00:00 2001 From: Kirill Kulakov Date: Mon, 6 Feb 2023 09:42:11 -0600 Subject: [PATCH] Xiaomi 2S air purifier mode selection support (#86649) * Xiaomi 2S air purifier mode selection support * Update homeassistant/components/xiaomi_miio/select.py Co-authored-by: Teemu R. * rename fix translation keys and rename key to be specific to airpurifiers Co-authored-by: Teemu R. --- homeassistant/components/xiaomi_miio/select.py | 16 +++++++++++++++- .../components/xiaomi_miio/strings.json | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/xiaomi_miio/select.py b/homeassistant/components/xiaomi_miio/select.py index 4d3c8bf0c85..e2a63bc4ee7 100644 --- a/homeassistant/components/xiaomi_miio/select.py +++ b/homeassistant/components/xiaomi_miio/select.py @@ -15,6 +15,7 @@ from miio.integrations.airpurifier.zhimi.airfresh import ( ) from miio.integrations.airpurifier.zhimi.airpurifier import ( LedBrightness as AirpurifierLedBrightness, + OperationMode as AirpurifierOperationMode, ) from miio.integrations.airpurifier.zhimi.airpurifier_miot import ( LedBrightness as AirpurifierMiotLedBrightness, @@ -52,6 +53,7 @@ from .const import ( MODEL_AIRPURIFIER_4_PRO, MODEL_AIRPURIFIER_M1, MODEL_AIRPURIFIER_M2, + MODEL_AIRPURIFIER_MA2, MODEL_AIRPURIFIER_PROH, MODEL_AIRPURIFIER_ZA1, MODEL_FAN_SA1, @@ -66,7 +68,7 @@ from .device import XiaomiCoordinatedMiioEntity ATTR_DISPLAY_ORIENTATION = "display_orientation" ATTR_LED_BRIGHTNESS = "led_brightness" ATTR_PTC_LEVEL = "ptc_level" - +ATTR_MODE = "mode" _LOGGER = logging.getLogger(__name__) @@ -111,6 +113,7 @@ MODEL_TO_ATTR_MAP: dict[str, list] = { MODEL_AIRHUMIDIFIER_V1: [ AttributeEnumMapping(ATTR_LED_BRIGHTNESS, AirhumidifierLedBrightness) ], + MODEL_AIRPURIFIER_MA2: [AttributeEnumMapping(ATTR_MODE, AirpurifierOperationMode)], MODEL_AIRPURIFIER_3: [ AttributeEnumMapping(ATTR_LED_BRIGHTNESS, AirpurifierMiotLedBrightness) ], @@ -160,6 +163,17 @@ SELECTOR_TYPES = ( options=["forward", "left", "right"], entity_category=EntityCategory.CONFIG, ), + XiaomiMiioSelectDescription( + key=ATTR_MODE, + attr_name=ATTR_MODE, + name="Mode", + set_method="set_mode", + set_method_error_message="Setting the mode of the fan failed.", + icon="mdi:fan", + translation_key="airpurifier_mode", + options=["silent", "auto", "favorite"], + entity_category=EntityCategory.CONFIG, + ), XiaomiMiioSelectDescription( key=ATTR_LED_BRIGHTNESS, attr_name=ATTR_LED_BRIGHTNESS, diff --git a/homeassistant/components/xiaomi_miio/strings.json b/homeassistant/components/xiaomi_miio/strings.json index bf722c3a1e5..c343fe9a5f1 100644 --- a/homeassistant/components/xiaomi_miio/strings.json +++ b/homeassistant/components/xiaomi_miio/strings.json @@ -79,6 +79,13 @@ "right": "Right" } }, + "airpurifier_mode": { + "state": { + "silent": "Silent", + "auto": "Auto", + "favorite": "Favorite" + } + }, "ptc_level": { "state": { "low": "Low",