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:
Julius Mittenzwei authored and Paulus Schoutsen committed 2018-02-24 10:24:33 -08:00
1 parent c076b805e7
commit 3713dfe139
17 files changed
+140 -199

No files matched your search

+7 -9
View File
@@ -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,
+8 -12
View File
@@ -4,7 +4,6 @@ Support for KNX/IP switches.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.knx/
"""
import asyncio
import voluptuous as vol
@@ -27,8 +26,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
async def async_setup_platform(hass, config, async_add_devices,
discovery_info=None):
"""Set up switch(es) for KNX platform."""
if discovery_info is not None:
async_add_devices_discovery(hass, discovery_info, async_add_devices)
@@ -71,11 +70,10 @@ class KNXSwitch(SwitchDevice):
@callback
def async_register_callbacks(self):
"""Register callbacks to update hass after device was changed."""
@asyncio.coroutine
def after_update_callback(device):
async def after_update_callback(device):
"""Call after device was updated."""
# pylint: disable=unused-argument
yield from self.async_update_ha_state()
await self.async_update_ha_state()
self.device.register_device_updated_cb(after_update_callback)
@property
@@ -98,12 +96,10 @@ class KNXSwitch(SwitchDevice):
"""Return true if device is on."""
return self.device.state
@asyncio.coroutine
def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs):
"""Turn the device on."""
yield from self.device.set_on()
await self.device.set_on()
@asyncio.coroutine
def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs):
"""Turn the device off."""
yield from self.device.set_off()
await self.device.set_off()