From 9e3ab1584e89e533a35965528f3983235e117806 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sun, 2 Jun 2019 10:42:14 +0200 Subject: [PATCH 1/2] Add zhimi.fan.za4 support --- miio/fan.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/miio/fan.py b/miio/fan.py index 228d8dd21..86ee0aa5e 100644 --- a/miio/fan.py +++ b/miio/fan.py @@ -13,6 +13,7 @@ MODEL_FAN_V3 = 'zhimi.fan.v3' MODEL_FAN_SA1 = 'zhimi.fan.sa1' MODEL_FAN_ZA1 = 'zhimi.fan.za1' +MODEL_FAN_ZA4 = 'zhimi.fan.za4' AVAILABLE_PROPERTIES_COMMON = [ 'angle', @@ -42,6 +43,7 @@ MODEL_FAN_V3: AVAILABLE_PROPERTIES_COMMON_V2_V3, MODEL_FAN_SA1: AVAILABLE_PROPERTIES_COMMON, MODEL_FAN_ZA1: AVAILABLE_PROPERTIES_COMMON, + MODEL_FAN_ZA4: AVAILABLE_PROPERTIES_COMMON, } @@ -78,6 +80,11 @@ def __init__(self, data: Dict[str, Any]) -> None: {'angle': 120, 'speed': 277, 'poweroff_time': 0, 'power': 'on', 'ac_power': 'on', 'angle_enable': 'off', 'speed_level': 1, 'natural_level': 2, 'child_lock': 'off', 'buzzer': 0, 'led_b': 0, 'use_time': 2318} + + Response of a Fan (zhimi.fan.sa4): + {'angle': 120, 'speed': 327, 'poweroff_time': 0, 'power': 'on', + 'ac_power': 'on', 'angle_enable': 'off', 'speed_level': 1, 'natural_level': 0, + 'child_lock': 'off', 'buzzer': 2, 'led_b': 0, 'use_time': 85} """ self.data = data @@ -284,8 +291,8 @@ def status(self) -> FanStatus: # properties are divided into multiple requests _props_per_request = 15 - # The SA1 and ZA1 is limited to a single property per request - if self.model in [MODEL_FAN_SA1, MODEL_FAN_ZA1]: + # The SA1, ZA1 and ZA4 is limited to a single property per request + if self.model in [MODEL_FAN_SA1, MODEL_FAN_ZA1, MODEL_FAN_ZA4]: _props_per_request = 1 _props = properties.copy() @@ -408,7 +415,7 @@ def set_led(self, led: bool): ) def set_buzzer(self, buzzer: bool): """Set buzzer on/off.""" - if self.model in [MODEL_FAN_SA1, MODEL_FAN_ZA1]: + if self.model in [MODEL_FAN_SA1, MODEL_FAN_ZA1, MODEL_FAN_ZA4]: if buzzer: return self.send("set_buzzer", [2]) else: @@ -467,3 +474,10 @@ def __init__(self, ip: str = None, token: str = None, start_id: int = 0, debug: int = 0, lazy_discover: bool = True) -> None: super().__init__(ip, token, start_id, debug, lazy_discover, model=MODEL_FAN_ZA1) + + +class FanZA4(Fan): + def __init__(self, ip: str = None, token: str = None, start_id: int = 0, + debug: int = 0, lazy_discover: bool = True) -> None: + super().__init__(ip, token, start_id, debug, lazy_discover, + model=MODEL_FAN_ZA4) From 73baa9ae3d07831c50e6a947cc714b6cb4ea3522 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sun, 2 Jun 2019 10:44:05 +0200 Subject: [PATCH 2/2] Add zhimi.fan.za4 support --- README.rst | 2 +- miio/discovery.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 3e96fb593..a4c5de760 100644 --- a/README.rst +++ b/README.rst @@ -23,7 +23,7 @@ Supported devices - Xiaomi Philips Zhirui Smart LED Bulb E14 Candle Lamp (:class:`miio.philips_bulb`) - Xiaomi Philips Zhirui Bedroom Smart Lamp (:class:`miio.philips_moonlight`) - Xiaomi Universal IR Remote Controller (Chuangmi IR) (:class:`miio.chuangmi_ir`) -- Xiaomi Mi Smart Pedestal Fan V2, V3, SA1 and ZA1 (:class:`miio.fan`) +- Xiaomi Mi Smart Pedestal Fan V2, V3, SA1, ZA1, ZA4 (:class:`miio.fan`) - Xiaomi Mi Air Humidifier (:class:`miio.airhumidifier`) - Xiaomi Mi Water Purifier (Basic support: Turn on & off) (:class:`miio.waterpurifier`) - Xiaomi PM2.5 Air Quality Monitor (:class:`miio.airqualitymonitor`) diff --git a/miio/discovery.py b/miio/discovery.py index e1b98786a..291fd8222 100644 --- a/miio/discovery.py +++ b/miio/discovery.py @@ -19,7 +19,7 @@ MODEL_CHUANGMI_PLUG_M1, MODEL_CHUANGMI_PLUG_M3, MODEL_CHUANGMI_PLUG_HMI205, ) -from .fan import (MODEL_FAN_V2, MODEL_FAN_V3, MODEL_FAN_SA1, MODEL_FAN_ZA1, ) +from .fan import (MODEL_FAN_V2, MODEL_FAN_V3, MODEL_FAN_SA1, MODEL_FAN_ZA1, MODEL_FAN_ZA4, ) from .powerstrip import (MODEL_POWER_STRIP_V1, MODEL_POWER_STRIP_V2, ) _LOGGER = logging.getLogger(__name__) @@ -82,6 +82,7 @@ "zhimi-fan-v3": partial(Fan, model=MODEL_FAN_V3), "zhimi-fan-sa1": partial(Fan, model=MODEL_FAN_SA1), "zhimi-fan-za1": partial(Fan, model=MODEL_FAN_ZA1), + "zhimi-fan-za4": partial(Fan, model=MODEL_FAN_ZA4), "zhimi-airfresh-va2": AirFresh, "zhimi-airmonitor-v1": partial(AirQualityMonitor, model=MODEL_AIRQUALITYMONITOR_V1), "cgllc-airmonitor-b1": partial(AirQualityMonitor, model=MODEL_AIRQUALITYMONITOR_B1),