Use blocking light.async_turn_*
parent
ff0386d773
commit
9e83198552
|
@ -162,8 +162,12 @@ def turn_on(hass, entity_id=None, transition=None, brightness=None,
|
||||||
def async_turn_on(hass, entity_id=None, transition=None, brightness=None,
|
def async_turn_on(hass, entity_id=None, transition=None, brightness=None,
|
||||||
brightness_pct=None, rgb_color=None, xy_color=None,
|
brightness_pct=None, rgb_color=None, xy_color=None,
|
||||||
color_temp=None, kelvin=None, white_value=None,
|
color_temp=None, kelvin=None, white_value=None,
|
||||||
profile=None, flash=None, effect=None, color_name=None):
|
profile=None, flash=None, effect=None, color_name=None,
|
||||||
"""Turn all or specified light on."""
|
blocking=False):
|
||||||
|
"""Turn all or specified light on.
|
||||||
|
|
||||||
|
This method must be run in the event loop and returns a coroutine.
|
||||||
|
"""
|
||||||
data = {
|
data = {
|
||||||
key: value for key, value in [
|
key: value for key, value in [
|
||||||
(ATTR_ENTITY_ID, entity_id),
|
(ATTR_ENTITY_ID, entity_id),
|
||||||
|
@ -182,7 +186,8 @@ def async_turn_on(hass, entity_id=None, transition=None, brightness=None,
|
||||||
] if value is not None
|
] if value is not None
|
||||||
}
|
}
|
||||||
|
|
||||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data))
|
return hass.async_add_job(hass.services.async_call(
|
||||||
|
DOMAIN, SERVICE_TURN_ON, data, blocking=blocking))
|
||||||
|
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
|
@ -193,8 +198,11 @@ def turn_off(hass, entity_id=None, transition=None):
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def async_turn_off(hass, entity_id=None, transition=None):
|
def async_turn_off(hass, entity_id=None, transition=None, blocking=False):
|
||||||
"""Turn all or specified light off."""
|
"""Turn all or specified light off.
|
||||||
|
|
||||||
|
This method must be run in the event loop and returns a coroutine.
|
||||||
|
"""
|
||||||
data = {
|
data = {
|
||||||
key: value for key, value in [
|
key: value for key, value in [
|
||||||
(ATTR_ENTITY_ID, entity_id),
|
(ATTR_ENTITY_ID, entity_id),
|
||||||
|
@ -202,14 +210,17 @@ def async_turn_off(hass, entity_id=None, transition=None):
|
||||||
] if value is not None
|
] if value is not None
|
||||||
}
|
}
|
||||||
|
|
||||||
hass.async_add_job(hass.services.async_call(
|
return hass.async_add_job(hass.services.async_call(
|
||||||
DOMAIN, SERVICE_TURN_OFF, data))
|
DOMAIN, SERVICE_TURN_OFF, data, blocking=blocking))
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def async_toggle(hass, entity_id=None, transition=None):
|
def async_toggle(hass, entity_id=None, transition=None, blocking=False):
|
||||||
"""Toggle all or specified light."""
|
"""Toggle all or specified light.
|
||||||
|
|
||||||
|
This method must be run in the event loop and returns a coroutine.
|
||||||
|
"""
|
||||||
data = {
|
data = {
|
||||||
key: value for key, value in [
|
key: value for key, value in [
|
||||||
(ATTR_ENTITY_ID, entity_id),
|
(ATTR_ENTITY_ID, entity_id),
|
||||||
|
@ -217,8 +228,8 @@ def async_toggle(hass, entity_id=None, transition=None):
|
||||||
] if value is not None
|
] if value is not None
|
||||||
}
|
}
|
||||||
|
|
||||||
hass.async_add_job(hass.services.async_call(
|
return hass.async_add_job(hass.services.async_call(
|
||||||
DOMAIN, SERVICE_TOGGLE, data))
|
DOMAIN, SERVICE_TOGGLE, data, blocking=blocking))
|
||||||
|
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
|
|
|
@ -158,17 +158,13 @@ class GroupLight(light.Light):
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Forward the turn_on command to all lights in the group."""
|
"""Forward the turn_on command to all lights in the group."""
|
||||||
for entity_id in self._entity_ids:
|
kwargs[ATTR_ENTITY_ID] = self._entity_ids
|
||||||
payload = dict(kwargs)
|
await light.async_turn_on(self.hass, blocking=True, **kwargs)
|
||||||
payload[ATTR_ENTITY_ID] = entity_id
|
|
||||||
light.async_turn_on(self.hass, **payload)
|
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Forward the turn_off command to all lights in the group."""
|
"""Forward the turn_off command to all lights in the group."""
|
||||||
for entity_id in self._entity_ids:
|
kwargs[ATTR_ENTITY_ID] = self._entity_ids
|
||||||
payload = dict(kwargs)
|
await light.async_turn_off(self.hass, blocking=True, **kwargs)
|
||||||
payload[ATTR_ENTITY_ID] = entity_id
|
|
||||||
light.async_turn_off(self.hass, **payload)
|
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Query all members and determine the group state."""
|
"""Query all members and determine the group state."""
|
||||||
|
|
Loading…
Reference in New Issue