Skip to content

Commit

Permalink
Air Purifier: Properties "use_time" and "button_pressed" added.
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Mar 7, 2018
1 parent c78e9cd commit 3921386
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def hardware_version(self) -> Optional[str]:

@property
def button_pressed(self) -> Optional[str]:
"""Button pressed."""
"""Last pressed button."""
return self.data["button_pressed"]

def __str__(self) -> str:
Expand Down
21 changes: 18 additions & 3 deletions miio/airpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ def auto_detect(self) -> Optional[bool]:

return None

@property
def use_time(self) -> Optional[int]:
"""How long the device has been active in seconds."""
return self.data["use_time"]

@property
def button_pressed(self) -> Optional[str]:
"""Last pressed button."""
return self.data["button_pressed"]

@classmethod
def _get_filter_type(cls, product_id: str) -> FilterType:
ft = cls._filter_type_cache.get(product_id, None)
Expand Down Expand Up @@ -290,7 +300,9 @@ def __repr__(self) -> str:
"sleep_mode_learn_count=%s, " \
"extra_features=%s, " \
"turbo_mode_supported=%s, " \
"auto_detect=%s>" % \
"auto_detect=%s, " % \
"use_time=%s, " % \
"button_pressed=%s>" % \
(self.power,
self.aqi,
self.average_aqi,
Expand Down Expand Up @@ -319,7 +331,9 @@ def __repr__(self) -> str:
self.sleep_mode_learn_count,
self.extra_features,
self.turbo_mode_supported,
self.auto_detect)
self.auto_detect,
self.use_time,
self.button_pressed)
return s


Expand All @@ -336,7 +350,8 @@ def status(self) -> AirPurifierStatus:
# Second request
'led_b', 'bright', 'buzzer', 'child_lock', 'volume',
'rfid_product_id', 'rfid_tag', 'act_sleep', 'sleep_mode',
'sleep_time', 'sleep_data_num', 'app_extra', 'act_det']
'sleep_time', 'sleep_data_num', 'app_extra', 'act_det',
'use_time', 'button_pressed']

# A single request is limited to 16 properties. Therefore the
# properties are divided into multiple requests
Expand Down
6 changes: 5 additions & 1 deletion miio/tests/test_airpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def __init__(self, *args, **kwargs):
'sleep_time': 83890,
'sleep_data_num': 22,
'app_extra': 1,
'act_det': 'off'
'act_det': 'off',
'use_time': '4862700',
'button_pressed': 'power',
}
self.return_values = {
'get_prop': self._get_state,
Expand Down Expand Up @@ -120,6 +122,8 @@ def test_status(self):
assert self.state().extra_features == self.device.start_state["app_extra"]
assert self.state().turbo_mode_supported == (self.device.start_state["app_extra"] == 1)
assert self.state().auto_detect == (self.device.start_state["act_det"] == 'on')
assert self.state().use_time == self.device.start_state["use_time"]
assert self.state().button_pressed == self.device.start_state["button_pressed"]

def test_set_mode(self):
def mode():
Expand Down

0 comments on commit 3921386

Please sign in to comment.