Skip to content

Commit

Permalink
Attributes average_aqi and purify_volume introduced. Fixes syssi/xiao…
Browse files Browse the repository at this point in the history
…mi_airpurifier#14.

New service light.xiaomi_miio_set_child_lock_{on,off} added. Fixes syssi/xiaomi_airpurifier#13.
  • Loading branch information
syssi committed Nov 26, 2017
1 parent 3e96280 commit b02a3fa
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
52 changes: 38 additions & 14 deletions homeassistant/components/fan/xiaomi_miio.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})

REQUIREMENTS = ['python-miio==0.3.2']
REQUIREMENTS = ['python-miio==0.3.3']

ATTR_TEMPERATURE = 'temperature'
ATTR_HUMIDITY = 'humidity'
Expand All @@ -45,6 +45,8 @@
ATTR_LED = 'led'
ATTR_LED_BRIGHTNESS = 'led_brightness'
ATTR_MOTOR_SPEED = 'motor_speed'
ATTR_AVERAGE_AIR_QUALITY_INDEX = 'average_aqi'
ATTR_PURIFY_VOLUME = 'purify_volume'

ATTR_BRIGHTNESS = 'brightness'
ATTR_LEVEL = 'level'
Expand All @@ -55,6 +57,8 @@
SERVICE_SET_BUZZER_OFF = 'xiaomi_miio_set_buzzer_off'
SERVICE_SET_LED_ON = 'xiaomi_miio_set_led_on'
SERVICE_SET_LED_OFF = 'xiaomi_miio_set_led_off'
SERVICE_SET_CHILD_LOCK_ON = 'xiaomi_miio_set_child_lock_on'
SERVICE_SET_CHILD_LOCK_OFF = 'xiaomi_miio_set_child_lock_off'
SERVICE_SET_FAVORITE_LEVEL = 'xiaomi_miio_set_favorite_level'
SERVICE_SET_LED_BRIGHTNESS = 'xiaomi_miio_set_led_brightness'

Expand All @@ -77,6 +81,8 @@
SERVICE_SET_BUZZER_OFF: {'method': 'async_set_buzzer_off'},
SERVICE_SET_LED_ON: {'method': 'async_set_led_on'},
SERVICE_SET_LED_OFF: {'method': 'async_set_led_off'},
SERVICE_SET_CHILD_LOCK_ON: {'method': 'async_set_child_lock_on'},
SERVICE_SET_CHILD_LOCK_OFF: {'method': 'async_set_child_lock_off'},
SERVICE_SET_FAVORITE_LEVEL: {
'method': 'async_set_favorite_level',
'schema': SERVICE_SCHEMA_FAVORITE_LEVEL},
Expand Down Expand Up @@ -118,15 +124,15 @@ def async_service_handler(service):
if key != ATTR_ENTITY_ID}
entity_ids = service.data.get(ATTR_ENTITY_ID)
if entity_ids:
target_air_purifiers = [air for air in hass.data[PLATFORM].values()
if air.entity_id in entity_ids]
devices = [device for device in hass.data[PLATFORM].values() if
device.entity_id in entity_ids]
else:
target_air_purifiers = hass.data[PLATFORM].values()
devices = hass.data[PLATFORM].values()

update_tasks = []
for air_purifier in target_air_purifiers:
yield from getattr(air_purifier, method['method'])(**params)
update_tasks.append(air_purifier.async_update_ha_state(True))
for device in devices:
yield from getattr(device, method['method'])(**params)
update_tasks.append(device.async_update_ha_state(True))

if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop)
Expand Down Expand Up @@ -164,7 +170,9 @@ def __init__(self, name, air_purifier):
ATTR_CHILD_LOCK: None,
ATTR_LED: None,
ATTR_LED_BRIGHTNESS: None,
ATTR_MOTOR_SPEED: None
ATTR_MOTOR_SPEED: None,
ATTR_AVERAGE_AIR_QUALITY_INDEX: None,
ATTR_PURIFY_VOLUME: None,
}

@property
Expand Down Expand Up @@ -251,7 +259,9 @@ def async_update(self):
ATTR_BUZZER: state.buzzer,
ATTR_CHILD_LOCK: state.child_lock,
ATTR_LED: state.led,
ATTR_MOTOR_SPEED: state.motor_speed
ATTR_MOTOR_SPEED: state.motor_speed,
ATTR_AVERAGE_AIR_QUALITY_INDEX: state.average_aqi,
ATTR_PURIFY_VOLUME: state.purify_volume,
}

if state.led_brightness:
Expand Down Expand Up @@ -291,30 +301,44 @@ def async_set_speed(self: ToggleEntity, speed: str) -> None:
def async_set_buzzer_on(self):
"""Turn the buzzer on."""
yield from self._try_command(
"Turning the buzzer of air purifier on failed.",
"Turning the buzzer of the air purifier on failed.",
self._air_purifier.set_buzzer, True)

@asyncio.coroutine
def async_set_buzzer_off(self):
"""Turn the buzzer on."""
"""Turn the buzzer off."""
yield from self._try_command(
"Turning the buzzer of air purifier off failed.",
"Turning the buzzer of the air purifier off failed.",
self._air_purifier.set_buzzer, False)

@asyncio.coroutine
def async_set_led_on(self):
"""Turn the led on."""
yield from self._try_command(
"Turning the led of air purifier off failed.",
"Turning the led of the air purifier off failed.",
self._air_purifier.set_led, True)

@asyncio.coroutine
def async_set_led_off(self):
"""Turn the led off."""
yield from self._try_command(
"Turning the led of air purifier off failed.",
"Turning the led of the air purifier off failed.",
self._air_purifier.set_led, False)

@asyncio.coroutine
def async_set_child_lock_on(self):
"""Turn the child lock on."""
yield from self._try_command(
"Turning the child lock of the air purifier on failed.",
self._air_purifier.set_child_lock, True)

@asyncio.coroutine
def async_set_child_lock_off(self):
"""Turn the child lock off."""
yield from self._try_command(
"Turning the child lock of the air purifier off failed.",
self._air_purifier.set_child_lock, False)

@asyncio.coroutine
def async_set_led_brightness(self, brightness: int=2):
"""Set the led brightness."""
Expand Down
16 changes: 16 additions & 0 deletions homeassistant/components/fan/xiaomi_miio_services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ xiaomi_miio_set_led_off:
description: Name of the air purifier entity.
example: 'fan.xiaomi_air_purifier'

xiaomi_miio_set_child_lock_on:
description: Turn the child lock on.

fields:
entity_id:
description: Name of the air purifier entity.
example: 'fan.xiaomi_air_purifier'

xiaomi_miio_set_child_lock_off:
description: Turn the child lock off.

fields:
entity_id:
description: Name of the air purifier entity.
example: 'fan.xiaomi_air_purifier'

xiaomi_miio_set_favorite_level:
description: Set the favorite level.

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/light/xiaomi_miio.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})

REQUIREMENTS = ['python-miio==0.3.2']
REQUIREMENTS = ['python-miio==0.3.3']

# The light does not accept cct values < 1
CCT_MIN = 1
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/switch/xiaomi_miio.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
})

REQUIREMENTS = ['python-miio==0.3.2']
REQUIREMENTS = ['python-miio==0.3.3']

ATTR_POWER = 'power'
ATTR_TEMPERATURE = 'temperature'
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/vacuum/xiaomi_miio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ATTR_ENTITY_ID, CONF_HOST, CONF_NAME, CONF_TOKEN, STATE_OFF, STATE_ON)
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['python-miio==0.3.2']
REQUIREMENTS = ['python-miio==0.3.3']

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ python-juicenet==0.0.5
# homeassistant.components.light.xiaomi_miio
# homeassistant.components.switch.xiaomi_miio
# homeassistant.components.vacuum.xiaomi_miio
python-miio==0.3.2
python-miio==0.3.3

# homeassistant.components.media_player.mpd
python-mpd2==0.5.5
Expand Down

0 comments on commit b02a3fa

Please sign in to comment.