Update after service calls (#4795)

* Update after service calls

* Service update: wrap async_update in create_task
This commit is contained in:
Paulus Schoutsen 2016-12-06 22:30:47 -08:00 committed by GitHub
parent 37e3c2a133
commit 98fe50d5ad
6 changed files with 57 additions and 30 deletions

View file

@ -82,7 +82,6 @@ def async_setup(hass, config):
"""Handle calls to the switch services."""
target_switches = component.async_extract_from_service(service)
update_tasks = []
for switch in target_switches:
if service.service == SERVICE_TURN_ON:
yield from switch.async_turn_on()
@ -91,12 +90,17 @@ def async_setup(hass, config):
else:
yield from switch.async_turn_off()
if switch.should_poll:
update_coro = 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
update_tasks = []
for switch in target_switches:
if not switch.should_poll:
continue
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:
yield from asyncio.wait(update_tasks, loop=hass.loop)