Skip to content

Commit

Permalink
Air Purifier Pro: support for sound volume level and fix for bright p…
Browse files Browse the repository at this point in the history
…ropery (#157)

* Air Purifier Pro sound notifications volume support

* Air Purifier Pro: proper use of bright property as environment brightness

Air Purifier Pro contains a brightness level sensor (on top, right next
to the mode selection button). The bright propery contains the value
based on this sensor. Value ranges from 0 to 200.

* Air Purifier: consistent use of white spaces in status __repr__

* Change brightness property name to illuminance

The name illuminance is more appropriate to the function of the value than
brightness

* Air Purifier: updated docstrings to better describe illuminance and volume properties
  • Loading branch information
yawor authored and rytilahti committed Jan 16, 2018
1 parent dd76fcd commit 74155d7
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions miio/airpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ def led_brightness(self) -> Optional[LedBrightness]:
if self.data["led_b"] is not None:
return LedBrightness(self.data["led_b"])

# This is the property name of the Air Purifier Pro
if self.data["bright"] is not None:
return LedBrightness(self.data["bright"])

return None

@property
def illuminance(self) -> Optional[int]:
"""Environment illuminance level in lux [0-200].
Sensor value is updated only when device is turned on."""
return self.data["bright"]

@property
def buzzer(self) -> bool:
"""Return True if buzzer is on."""
Expand Down Expand Up @@ -147,23 +149,30 @@ def motor_speed(self) -> int:
"""Speed of the motor."""
return self.data["motor1_speed"]

@property
def volume(self) -> int:
"""Volume of sound notifications [0-100]."""
return self.data["volume"]

def __repr__(self) -> str:
s = "<AirPurifierStatus power=%s, " \
"aqi=%s," \
"average_aqi=%s," \
"aqi=%s, " \
"average_aqi=%s, " \
"temperature=%s, " \
"humidity=%s%%," \
"mode=%s," \
"led=%s," \
"led_brightness=%s," \
"humidity=%s%%, " \
"mode=%s, " \
"led=%s, " \
"led_brightness=%s, " \
"illuminance=%s, " \
"buzzer=%s, " \
"child_lock=%s," \
"favorite_level=%s," \
"child_lock=%s, " \
"favorite_level=%s, " \
"filter_life_remaining=%s, " \
"filter_hours_used=%s, " \
"use_time=%s, " \
"purify_volume=%s, " \
"motor_speed=%s>" % \
"motor_speed=%s, " \
"volume=%s>" % \
(self.power,
self.aqi,
self.average_aqi,
Expand All @@ -172,14 +181,16 @@ def __repr__(self) -> str:
self.mode,
self.led,
self.led_brightness,
self.illuminance,
self.buzzer,
self.child_lock,
self.favorite_level,
self.filter_life_remaining,
self.filter_hours_used,
self.use_time,
self.purify_volume,
self.motor_speed)
self.motor_speed,
self.volume)
return s


Expand All @@ -193,7 +204,8 @@ def status(self) -> AirPurifierStatus:
'mode', 'favorite_level', 'filter1_life', 'f1_hour_used',
'use_time', 'motor1_speed', 'purify_volume', 'f1_hour',
# Second request
'led', 'led_b', 'bright', 'buzzer', 'child_lock', ]
'led', 'led_b', 'bright', 'buzzer', 'child_lock',
'volume', ]

# A single request is limited to 16 properties. Therefore the
# properties are divided in two groups here. The second group contains
Expand Down Expand Up @@ -264,3 +276,7 @@ def set_child_lock(self, lock: bool):
return self.send("set_child_lock", ["on"])
else:
return self.send("set_child_lock", ["off"])

def set_volume(self, volume: int):
"""Set volume of sound notifications [0-100]."""
return self.send("set_volume", [volume])

0 comments on commit 74155d7

Please sign in to comment.