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

Air Quality Monitor: New property "time_state" added #187

Merged
merged 3 commits into from
Jan 28, 2018
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
24 changes: 21 additions & 3 deletions miio/airqualitymonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,39 @@ def usb_power(self) -> bool:

@property
def aqi(self) -> int:
"""Air quality index value."""
"""Air quality index value. (0...600)."""
return self.data["aqi"]

@property
def battery(self) -> int:
"""Current battery level."""
"""Current battery level (0...100)."""
return self.data["battery"]

@property
def time_state(self) -> str:
"""Current time state."""
return self.data["time_state"]

def __repr__(self) -> str:
s = "<AirQualityMonitorStatus power=%s, " \
"aqi=%s, " \
"battery=%s, " \
"usb=%s, " \
"time_state=%s>" % \
(self.power,
self.aqi,
self.battery,
self.usb,
self.time_state)
return s


class AirQualityMonitor(Device):
"""Xiaomi PM2.5 Air Quality Monitor."""
def status(self) -> AirQualityMonitorStatus:
"""Return device status."""

properties = ['power', 'aqi', 'battery', 'usb_state']
properties = ['power', 'aqi', 'battery', 'usb_state', 'time_state']

values = self.send(
"get_prop",
Expand Down
4 changes: 3 additions & 1 deletion miio/tests/test_airqualitymonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def __init__(self, *args, **kwargs):
'power': 'on',
'aqi': 34,
'battery': 100,
'usb_state': 'off'
'usb_state': 'off',
'time_state': 'format unknown'
}
self.return_values = {
'get_prop': self._get_state,
Expand Down Expand Up @@ -56,3 +57,4 @@ def test_status(self):
assert self.state().aqi == self.device.start_state["aqi"]
assert self.state().battery == self.device.start_state["battery"]
assert self.state().usb_power == (self.device.start_state["usb_state"] == 'on')
assert self.state().time_state == self.device.start_state["time_state"]