Update after service calls (#4795)
* Update after service calls * Service update: wrap async_update in create_task
This commit is contained in:
parent
37e3c2a133
commit
98fe50d5ad
6 changed files with 57 additions and 30 deletions
|
@ -59,8 +59,12 @@ def setup(hass, config):
|
||||||
|
|
||||||
for alarm in target_alarms:
|
for alarm in target_alarms:
|
||||||
getattr(alarm, method)(code)
|
getattr(alarm, method)(code)
|
||||||
if alarm.should_poll:
|
|
||||||
alarm.update_ha_state(True)
|
for alarm in target_alarms:
|
||||||
|
if not alarm.should_poll:
|
||||||
|
continue
|
||||||
|
|
||||||
|
alarm.update_ha_state(True)
|
||||||
|
|
||||||
descriptions = load_yaml_config_file(
|
descriptions = load_yaml_config_file(
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
|
@ -135,12 +135,19 @@ def setup(hass, config):
|
||||||
params = service.data.copy()
|
params = service.data.copy()
|
||||||
params.pop(ATTR_ENTITY_ID, None)
|
params.pop(ATTR_ENTITY_ID, None)
|
||||||
|
|
||||||
if method:
|
if not method:
|
||||||
for cover in component.extract_from_service(service):
|
return
|
||||||
getattr(cover, method['method'])(**params)
|
|
||||||
|
|
||||||
if cover.should_poll:
|
covers = component.extract_from_service(service)
|
||||||
cover.update_ha_state(True)
|
|
||||||
|
for cover in covers:
|
||||||
|
getattr(cover, method['method'])(**params)
|
||||||
|
|
||||||
|
for cover in covers:
|
||||||
|
if not cover.should_poll:
|
||||||
|
continue
|
||||||
|
|
||||||
|
cover.update_ha_state(True)
|
||||||
|
|
||||||
descriptions = load_yaml_config_file(
|
descriptions = load_yaml_config_file(
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
|
@ -236,7 +236,6 @@ def async_setup(hass, config):
|
||||||
if color_name is not None:
|
if color_name is not None:
|
||||||
params[ATTR_RGB_COLOR] = color_util.color_name_to_rgb(color_name)
|
params[ATTR_RGB_COLOR] = color_util.color_name_to_rgb(color_name)
|
||||||
|
|
||||||
update_tasks = []
|
|
||||||
for light in target_lights:
|
for light in target_lights:
|
||||||
if service.service == SERVICE_TURN_ON:
|
if service.service == SERVICE_TURN_ON:
|
||||||
yield from light.async_turn_on(**params)
|
yield from light.async_turn_on(**params)
|
||||||
|
@ -245,12 +244,18 @@ def async_setup(hass, config):
|
||||||
else:
|
else:
|
||||||
yield from light.async_toggle(**params)
|
yield from light.async_toggle(**params)
|
||||||
|
|
||||||
if light.should_poll:
|
update_tasks = []
|
||||||
update_coro = light.async_update_ha_state(True)
|
|
||||||
if hasattr(light, 'async_update'):
|
for light in target_lights:
|
||||||
update_tasks.append(hass.loop.create_task(update_coro))
|
if not light.should_poll:
|
||||||
else:
|
continue
|
||||||
yield from update_coro
|
|
||||||
|
update_coro = hass.loop.create_task(
|
||||||
|
light.async_update_ha_state(True))
|
||||||
|
if hasattr(light, 'async_update'):
|
||||||
|
update_tasks.append(hass.loop.create_task(update_coro))
|
||||||
|
else:
|
||||||
|
yield from update_coro
|
||||||
|
|
||||||
if update_tasks:
|
if update_tasks:
|
||||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||||
|
|
|
@ -85,8 +85,11 @@ def setup(hass, config):
|
||||||
else:
|
else:
|
||||||
item.unlock(code=code)
|
item.unlock(code=code)
|
||||||
|
|
||||||
if item.should_poll:
|
for item in target_locks:
|
||||||
item.update_ha_state(True)
|
if not item.should_poll:
|
||||||
|
continue
|
||||||
|
|
||||||
|
item.update_ha_state(True)
|
||||||
|
|
||||||
descriptions = load_yaml_config_file(
|
descriptions = load_yaml_config_file(
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
|
@ -98,7 +98,6 @@ def async_setup(hass, config):
|
||||||
device = service.data.get(ATTR_DEVICE)
|
device = service.data.get(ATTR_DEVICE)
|
||||||
command = service.data.get(ATTR_COMMAND)
|
command = service.data.get(ATTR_COMMAND)
|
||||||
|
|
||||||
update_tasks = []
|
|
||||||
for remote in target_remotes:
|
for remote in target_remotes:
|
||||||
if service.service == SERVICE_TURN_ON:
|
if service.service == SERVICE_TURN_ON:
|
||||||
yield from remote.async_turn_on(activity=activity_id)
|
yield from remote.async_turn_on(activity=activity_id)
|
||||||
|
@ -108,12 +107,17 @@ def async_setup(hass, config):
|
||||||
else:
|
else:
|
||||||
yield from remote.async_turn_off()
|
yield from remote.async_turn_off()
|
||||||
|
|
||||||
if remote.should_poll:
|
update_tasks = []
|
||||||
update_coro = remote.async_update_ha_state(True)
|
for remote in target_remotes:
|
||||||
if hasattr(remote, 'async_update'):
|
if not remote.should_poll:
|
||||||
update_tasks.append(hass.loop.create_task(update_coro))
|
continue
|
||||||
else:
|
|
||||||
yield from update_coro
|
update_coro = hass.loop.create_task(
|
||||||
|
remote.async_update_ha_state(True))
|
||||||
|
if hasattr(remote, 'async_update'):
|
||||||
|
update_tasks.append(hass.loop.create_task(update_coro))
|
||||||
|
else:
|
||||||
|
yield from update_coro
|
||||||
|
|
||||||
if update_tasks:
|
if update_tasks:
|
||||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||||
|
|
|
@ -82,7 +82,6 @@ def async_setup(hass, config):
|
||||||
"""Handle calls to the switch services."""
|
"""Handle calls to the switch services."""
|
||||||
target_switches = component.async_extract_from_service(service)
|
target_switches = component.async_extract_from_service(service)
|
||||||
|
|
||||||
update_tasks = []
|
|
||||||
for switch in target_switches:
|
for switch in target_switches:
|
||||||
if service.service == SERVICE_TURN_ON:
|
if service.service == SERVICE_TURN_ON:
|
||||||
yield from switch.async_turn_on()
|
yield from switch.async_turn_on()
|
||||||
|
@ -91,12 +90,17 @@ def async_setup(hass, config):
|
||||||
else:
|
else:
|
||||||
yield from switch.async_turn_off()
|
yield from switch.async_turn_off()
|
||||||
|
|
||||||
if switch.should_poll:
|
update_tasks = []
|
||||||
update_coro = switch.async_update_ha_state(True)
|
for switch in target_switches:
|
||||||
if hasattr(switch, 'async_update'):
|
if not switch.should_poll:
|
||||||
update_tasks.append(hass.loop.create_task(update_coro))
|
continue
|
||||||
else:
|
|
||||||
yield from update_coro
|
update_coro = hass.loop.create_task(
|
||||||
|
switch.async_update_ha_state(True))
|
||||||
|
if hasattr(switch, 'async_update'):
|
||||||
|
update_tasks.append(hass.loop.create_task(update_coro))
|
||||||
|
else:
|
||||||
|
yield from update_coro
|
||||||
|
|
||||||
if update_tasks:
|
if update_tasks:
|
||||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||||
|
|
Loading…
Add table
Reference in a new issue