Additional attributes and services of the Xiaomi Air Purifier introduced (#11249)
* Attributes average_aqi and purify_volume introduced. Fixes https://github.com/syssi/xiaomi_airpurifier/issues/14. New service light.xiaomi_miio_set_child_lock_{on,off} added. Fixes https://github.com/syssi/xiaomi_airpurifier/issues/13. * Lazy loading of service descriptions. * Merge conflict resolved.pull/11792/head
parent
5de828d6e2
commit
03a5d4e131
|
@ -63,3 +63,65 @@ dyson_set_night_mode:
|
|||
night_mode:
|
||||
description: Night mode status
|
||||
example: true
|
||||
|
||||
xiaomi_miio_set_buzzer_on:
|
||||
description: Turn the buzzer on.
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the air purifier entity.
|
||||
example: 'fan.xiaomi_air_purifier'
|
||||
|
||||
xiaomi_miio_set_buzzer_off:
|
||||
description: Turn the buzzer off.
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the air purifier entity.
|
||||
example: 'fan.xiaomi_air_purifier'
|
||||
|
||||
xiaomi_miio_set_led_on:
|
||||
description: Turn the led on.
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the air purifier entity.
|
||||
example: 'fan.xiaomi_air_purifier'
|
||||
|
||||
xiaomi_miio_set_led_off:
|
||||
description: Turn the led off.
|
||||
fields:
|
||||
entity_id:
|
||||
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.
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the air purifier entity.
|
||||
example: 'fan.xiaomi_air_purifier'
|
||||
level:
|
||||
description: Level, between 0 and 16.
|
||||
example: 1
|
||||
|
||||
xiaomi_miio_set_led_brightness:
|
||||
description: Set the led brightness.
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the air purifier entity.
|
||||
example: 'fan.xiaomi_air_purifier'
|
||||
brightness:
|
||||
description: Brightness (0 = Bright, 1 = Dim, 2 = Off)
|
||||
example: 1
|
||||
|
|
|
@ -43,6 +43,8 @@ ATTR_CHILD_LOCK = 'child_lock'
|
|||
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'
|
||||
|
@ -53,6 +55,8 @@ SERVICE_SET_BUZZER_ON = 'xiaomi_miio_set_buzzer_on'
|
|||
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'
|
||||
|
||||
|
@ -75,6 +79,8 @@ SERVICE_TO_METHOD = {
|
|||
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},
|
||||
|
@ -116,15 +122,15 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||
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)
|
||||
|
@ -157,7 +163,9 @@ class XiaomiAirPurifier(FanEntity):
|
|||
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
|
||||
|
@ -244,7 +252,9 @@ class XiaomiAirPurifier(FanEntity):
|
|||
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:
|
||||
|
@ -284,30 +294,44 @@ class XiaomiAirPurifier(FanEntity):
|
|||
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."""
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
|
||||
xiaomi_miio_set_buzzer_on:
|
||||
description: Turn the buzzer on.
|
||||
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the air purifier entity.
|
||||
example: 'fan.xiaomi_air_purifier'
|
||||
|
||||
xiaomi_miio_set_buzzer_off:
|
||||
description: Turn the buzzer off.
|
||||
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the air purifier entity.
|
||||
example: 'fan.xiaomi_air_purifier'
|
||||
|
||||
xiaomi_miio_set_led_on:
|
||||
description: Turn the led on.
|
||||
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the air purifier entity.
|
||||
example: 'fan.xiaomi_air_purifier'
|
||||
|
||||
xiaomi_miio_set_led_off:
|
||||
description: Turn the led 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.
|
||||
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the air purifier entity.
|
||||
example: 'fan.xiaomi_air_purifier'
|
||||
|
||||
level:
|
||||
description: Level, between 0 and 16.
|
||||
example: '1'
|
||||
|
||||
xiaomi_miio_set_led_brightness:
|
||||
description: Set the led brightness.
|
||||
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the air purifier entity.
|
||||
example: 'fan.xiaomi_air_purifier'
|
||||
|
||||
brightness:
|
||||
description: Brightness (0 = Bright, 1 = Dim, 2 = Off)
|
||||
example: '1'
|
Loading…
Reference in New Issue