Update after service calls (#4795)

* Update after service calls

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

No files matched your search

+11 -7
View File
@@ -98,7 +98,6 @@ def async_setup(hass, config):
device = service.data.get(ATTR_DEVICE)
command = service.data.get(ATTR_COMMAND)
update_tasks = []
for remote in target_remotes:
if service.service == SERVICE_TURN_ON:
yield from remote.async_turn_on(activity=activity_id)
@@ -108,12 +107,17 @@ def async_setup(hass, config):
else:
yield from remote.async_turn_off()
if remote.should_poll:
update_coro = 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
update_tasks = []
for remote in target_remotes:
if not remote.should_poll:
continue
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:
yield from asyncio.wait(update_tasks, loop=hass.loop)