Skip to content
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
25 changes: 24 additions & 1 deletion miio/airpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ class AirPurifierException(DeviceException):


class OperationMode(enum.Enum):
# Supported modes of the Air Purifier Pro, 2, V3
Auto = 'auto'
Silent = 'silent'
Favorite = 'favorite'
# Additional supported modes of the Air Purifier 2 and V3
Idle = 'idle'
# Additional supported modes of the Air Purifier V3
Medium = 'medium'
High = 'high'
Strong = 'strong'


class SleepMode(enum.Enum):
Expand Down Expand Up @@ -74,6 +80,20 @@ def __init__(self, data: Dict[str, Any]) -> None:
'rfid_product_id': None, 'rfid_tag': None,
'act_sleep': 'close'}

Response of a Air Purifier V3 (zhimi.airpurifier.v3)

{'power': 'off', 'aqi': 0, 'humidity': None, 'temp_dec': None,
'mode': 'idle', 'led': 'off', 'led_b': 10, 'buzzer': 'on',
'child_lock': 'off', 'bright': 43, 'favorite_level': None,
'filter1_life': 26, 'f1_hour_used': 2573, 'use_time': None,
'motor1_speed': 0}

{‘power’: 'on', ‘aqi’: 18, ‘humidity’: None, ‘temp_dec’: None,
‘mode’: 'silent', ‘led’: 'off', ‘led_b’: 10, ‘buzzer’: 'on',
‘child_lock’: 'off', ‘bright’: 4, ‘favorite_level’: None,
‘filter1_life’: 26, ‘f1_hour_used’: 2574, ‘use_time’: None,
‘motor1_speed’: 648}

A request is limited to 16 properties.
"""

Expand Down Expand Up @@ -134,7 +154,10 @@ def led(self) -> bool:
def led_brightness(self) -> Optional[LedBrightness]:
"""Brightness of the LED."""
if self.data["led_b"] is not None:
return LedBrightness(self.data["led_b"])
try:
return LedBrightness(self.data["led_b"])
except ValueError:
return None

return None

Expand Down
7 changes: 7 additions & 0 deletions miio/tests/test_airpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ def test_status_without_led_brightness(self):
self.device.state["led_b"] = None
assert self.state().led_brightness is None

def test_status_unknown_led_brightness(self):
self.device._reset_state()

# The Air Purifier V3 returns a led brightness of 10 f.e.
self.device.state["led_b"] = 10
assert self.state().led_brightness is None

def test_status_without_temperature(self):
self.device._reset_state()
self.device.state["temp_dec"] = None
Expand Down