Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zhimi.fan.za4 support #512

Merged
merged 2 commits into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
3 changes: 2 additions & 1 deletion miio/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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),
Expand Down
20 changes: 17 additions & 3 deletions miio/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
}


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)