Removing asyncio.coroutine syntax from some components (#12507)
* Removing asyncio.coroutine syntax (first steps) * merge conflict * fixed small bug * pylint
This commit is contained in:
1 parent
c076b805e7
commit
3713dfe139
17 files changed
+140
-199
No files matched your search
@@ -93,33 +93,31 @@ def toggle(hass, entity_id=None):
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, data)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
async def async_setup(hass, config):
|
||||
"""Track states and offer events for switches."""
|
||||
component = EntityComponent(
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_SWITCHES)
|
||||
yield from component.async_setup(config)
|
||||
await component.async_setup(config)
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_handle_switch_service(service):
|
||||
async def async_handle_switch_service(service):
|
||||
"""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()
|
||||
await switch.async_turn_on()
|
||||
elif service.service == SERVICE_TOGGLE:
|
||||
yield from switch.async_toggle()
|
||||
await switch.async_toggle()
|
||||
else:
|
||||
yield from switch.async_turn_off()
|
||||
await switch.async_turn_off()
|
||||
|
||||
if not switch.should_poll:
|
||||
continue
|
||||
update_tasks.append(switch.async_update_ha_state(True))
|
||||
|
||||
if update_tasks:
|
||||
yield from asyncio.wait(update_tasks, loop=hass.loop)
|
||||
await asyncio.wait(update_tasks, loop=hass.loop)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_TURN_OFF, async_handle_switch_service,
|
||||
|
||||
Reference in new issue
Block a user