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 2018-02-24 19:24:33 +01:00 committed by Paulus Schoutsen
parent c076b805e7
commit 3713dfe139
17 changed files with 140 additions and 199 deletions

View file

@ -4,7 +4,7 @@ Component to interface with binary sensors.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/binary_sensor/ https://home-assistant.io/components/binary_sensor/
""" """
import asyncio
from datetime import timedelta from datetime import timedelta
import logging import logging
@ -47,13 +47,12 @@ DEVICE_CLASSES = [
DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.In(DEVICE_CLASSES)) DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.In(DEVICE_CLASSES))
@asyncio.coroutine async def async_setup(hass, config):
def async_setup(hass, config):
"""Track states and offer events for binary sensors.""" """Track states and offer events for binary sensors."""
component = EntityComponent( component = EntityComponent(
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL) logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL)
yield from component.async_setup(config) await component.async_setup(config)
return True return True

View file

@ -4,7 +4,6 @@ Support for KNX/IP binary sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.knx/ https://home-assistant.io/components/binary_sensor.knx/
""" """
import asyncio
import voluptuous as vol import voluptuous as vol
@ -53,8 +52,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
}) })
@asyncio.coroutine async def async_setup_platform(hass, config, async_add_devices,
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): discovery_info=None):
"""Set up binary sensor(s) for KNX platform.""" """Set up binary sensor(s) for KNX platform."""
if discovery_info is not None: if discovery_info is not None:
async_add_devices_discovery(hass, discovery_info, async_add_devices) async_add_devices_discovery(hass, discovery_info, async_add_devices)
@ -111,11 +110,10 @@ class KNXBinarySensor(BinarySensorDevice):
@callback @callback
def async_register_callbacks(self): def async_register_callbacks(self):
"""Register callbacks to update hass after device was changed.""" """Register callbacks to update hass after device was changed."""
@asyncio.coroutine async def after_update_callback(device):
def after_update_callback(device):
"""Call after device was updated.""" """Call after device was updated."""
# pylint: disable=unused-argument # 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) self.device.register_device_updated_cb(after_update_callback)
@property @property

View file

@ -237,14 +237,12 @@ def set_swing_mode(hass, swing_mode, entity_id=None):
hass.services.call(DOMAIN, SERVICE_SET_SWING_MODE, data) hass.services.call(DOMAIN, SERVICE_SET_SWING_MODE, data)
@asyncio.coroutine async def async_setup(hass, config):
def async_setup(hass, config):
"""Set up climate devices.""" """Set up climate devices."""
component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL) component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
yield from component.async_setup(config) await component.async_setup(config)
@asyncio.coroutine async def async_away_mode_set_service(service):
def async_away_mode_set_service(service):
"""Set away mode on target climate devices.""" """Set away mode on target climate devices."""
target_climate = component.async_extract_from_service(service) target_climate = component.async_extract_from_service(service)
@ -253,23 +251,22 @@ def async_setup(hass, config):
update_tasks = [] update_tasks = []
for climate in target_climate: for climate in target_climate:
if away_mode: if away_mode:
yield from climate.async_turn_away_mode_on() await climate.async_turn_away_mode_on()
else: else:
yield from climate.async_turn_away_mode_off() await climate.async_turn_away_mode_off()
if not climate.should_poll: if not climate.should_poll:
continue continue
update_tasks.append(climate.async_update_ha_state(True)) update_tasks.append(climate.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_SET_AWAY_MODE, async_away_mode_set_service, DOMAIN, SERVICE_SET_AWAY_MODE, async_away_mode_set_service,
schema=SET_AWAY_MODE_SCHEMA) schema=SET_AWAY_MODE_SCHEMA)
@asyncio.coroutine async def async_hold_mode_set_service(service):
def async_hold_mode_set_service(service):
"""Set hold mode on target climate devices.""" """Set hold mode on target climate devices."""
target_climate = component.async_extract_from_service(service) target_climate = component.async_extract_from_service(service)
@ -277,21 +274,20 @@ def async_setup(hass, config):
update_tasks = [] update_tasks = []
for climate in target_climate: for climate in target_climate:
yield from climate.async_set_hold_mode(hold_mode) await climate.async_set_hold_mode(hold_mode)
if not climate.should_poll: if not climate.should_poll:
continue continue
update_tasks.append(climate.async_update_ha_state(True)) update_tasks.append(climate.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_SET_HOLD_MODE, async_hold_mode_set_service, DOMAIN, SERVICE_SET_HOLD_MODE, async_hold_mode_set_service,
schema=SET_HOLD_MODE_SCHEMA) schema=SET_HOLD_MODE_SCHEMA)
@asyncio.coroutine async def async_aux_heat_set_service(service):
def async_aux_heat_set_service(service):
"""Set auxiliary heater on target climate devices.""" """Set auxiliary heater on target climate devices."""
target_climate = component.async_extract_from_service(service) target_climate = component.async_extract_from_service(service)
@ -300,23 +296,22 @@ def async_setup(hass, config):
update_tasks = [] update_tasks = []
for climate in target_climate: for climate in target_climate:
if aux_heat: if aux_heat:
yield from climate.async_turn_aux_heat_on() await climate.async_turn_aux_heat_on()
else: else:
yield from climate.async_turn_aux_heat_off() await climate.async_turn_aux_heat_off()
if not climate.should_poll: if not climate.should_poll:
continue continue
update_tasks.append(climate.async_update_ha_state(True)) update_tasks.append(climate.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_SET_AUX_HEAT, async_aux_heat_set_service, DOMAIN, SERVICE_SET_AUX_HEAT, async_aux_heat_set_service,
schema=SET_AUX_HEAT_SCHEMA) schema=SET_AUX_HEAT_SCHEMA)
@asyncio.coroutine async def async_temperature_set_service(service):
def async_temperature_set_service(service):
"""Set temperature on the target climate devices.""" """Set temperature on the target climate devices."""
target_climate = component.async_extract_from_service(service) target_climate = component.async_extract_from_service(service)
@ -333,21 +328,20 @@ def async_setup(hass, config):
else: else:
kwargs[value] = temp kwargs[value] = temp
yield from climate.async_set_temperature(**kwargs) await climate.async_set_temperature(**kwargs)
if not climate.should_poll: if not climate.should_poll:
continue continue
update_tasks.append(climate.async_update_ha_state(True)) update_tasks.append(climate.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_SET_TEMPERATURE, async_temperature_set_service, DOMAIN, SERVICE_SET_TEMPERATURE, async_temperature_set_service,
schema=SET_TEMPERATURE_SCHEMA) schema=SET_TEMPERATURE_SCHEMA)
@asyncio.coroutine async def async_humidity_set_service(service):
def async_humidity_set_service(service):
"""Set humidity on the target climate devices.""" """Set humidity on the target climate devices."""
target_climate = component.async_extract_from_service(service) target_climate = component.async_extract_from_service(service)
@ -355,20 +349,19 @@ def async_setup(hass, config):
update_tasks = [] update_tasks = []
for climate in target_climate: for climate in target_climate:
yield from climate.async_set_humidity(humidity) await climate.async_set_humidity(humidity)
if not climate.should_poll: if not climate.should_poll:
continue continue
update_tasks.append(climate.async_update_ha_state(True)) update_tasks.append(climate.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_SET_HUMIDITY, async_humidity_set_service, DOMAIN, SERVICE_SET_HUMIDITY, async_humidity_set_service,
schema=SET_HUMIDITY_SCHEMA) schema=SET_HUMIDITY_SCHEMA)
@asyncio.coroutine async def async_fan_mode_set_service(service):
def async_fan_mode_set_service(service):
"""Set fan mode on target climate devices.""" """Set fan mode on target climate devices."""
target_climate = component.async_extract_from_service(service) target_climate = component.async_extract_from_service(service)
@ -376,20 +369,19 @@ def async_setup(hass, config):
update_tasks = [] update_tasks = []
for climate in target_climate: for climate in target_climate:
yield from climate.async_set_fan_mode(fan) await climate.async_set_fan_mode(fan)
if not climate.should_poll: if not climate.should_poll:
continue continue
update_tasks.append(climate.async_update_ha_state(True)) update_tasks.append(climate.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_SET_FAN_MODE, async_fan_mode_set_service, DOMAIN, SERVICE_SET_FAN_MODE, async_fan_mode_set_service,
schema=SET_FAN_MODE_SCHEMA) schema=SET_FAN_MODE_SCHEMA)
@asyncio.coroutine async def async_operation_set_service(service):
def async_operation_set_service(service):
"""Set operating mode on the target climate devices.""" """Set operating mode on the target climate devices."""
target_climate = component.async_extract_from_service(service) target_climate = component.async_extract_from_service(service)
@ -397,20 +389,19 @@ def async_setup(hass, config):
update_tasks = [] update_tasks = []
for climate in target_climate: for climate in target_climate:
yield from climate.async_set_operation_mode(operation_mode) await climate.async_set_operation_mode(operation_mode)
if not climate.should_poll: if not climate.should_poll:
continue continue
update_tasks.append(climate.async_update_ha_state(True)) update_tasks.append(climate.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_SET_OPERATION_MODE, async_operation_set_service, DOMAIN, SERVICE_SET_OPERATION_MODE, async_operation_set_service,
schema=SET_OPERATION_MODE_SCHEMA) schema=SET_OPERATION_MODE_SCHEMA)
@asyncio.coroutine async def async_swing_set_service(service):
def async_swing_set_service(service):
"""Set swing mode on the target climate devices.""" """Set swing mode on the target climate devices."""
target_climate = component.async_extract_from_service(service) target_climate = component.async_extract_from_service(service)
@ -418,36 +409,35 @@ def async_setup(hass, config):
update_tasks = [] update_tasks = []
for climate in target_climate: for climate in target_climate:
yield from climate.async_set_swing_mode(swing_mode) await climate.async_set_swing_mode(swing_mode)
if not climate.should_poll: if not climate.should_poll:
continue continue
update_tasks.append(climate.async_update_ha_state(True)) update_tasks.append(climate.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_SET_SWING_MODE, async_swing_set_service, DOMAIN, SERVICE_SET_SWING_MODE, async_swing_set_service,
schema=SET_SWING_MODE_SCHEMA) schema=SET_SWING_MODE_SCHEMA)
@asyncio.coroutine async def async_on_off_service(service):
def async_on_off_service(service):
"""Handle on/off calls.""" """Handle on/off calls."""
target_climate = component.async_extract_from_service(service) target_climate = component.async_extract_from_service(service)
update_tasks = [] update_tasks = []
for climate in target_climate: for climate in target_climate:
if service.service == SERVICE_TURN_ON: if service.service == SERVICE_TURN_ON:
yield from climate.async_turn_on() await climate.async_turn_on()
elif service.service == SERVICE_TURN_OFF: elif service.service == SERVICE_TURN_OFF:
yield from climate.async_turn_off() await climate.async_turn_off()
if not climate.should_poll: if not climate.should_poll:
continue continue
update_tasks.append(climate.async_update_ha_state(True)) update_tasks.append(climate.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_TURN_OFF, async_on_off_service, DOMAIN, SERVICE_TURN_OFF, async_on_off_service,

View file

@ -4,7 +4,6 @@ Support for KNX/IP climate devices.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/climate.knx/ https://home-assistant.io/components/climate.knx/
""" """
import asyncio
import voluptuous as vol import voluptuous as vol
@ -61,8 +60,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
}) })
@asyncio.coroutine async def async_setup_platform(hass, config, async_add_devices,
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): discovery_info=None):
"""Set up climate(s) for KNX platform.""" """Set up climate(s) for KNX platform."""
if discovery_info is not None: if discovery_info is not None:
async_add_devices_discovery(hass, discovery_info, async_add_devices) async_add_devices_discovery(hass, discovery_info, async_add_devices)
@ -135,11 +134,10 @@ class KNXClimate(ClimateDevice):
def async_register_callbacks(self): def async_register_callbacks(self):
"""Register callbacks to update hass after device was changed.""" """Register callbacks to update hass after device was changed."""
@asyncio.coroutine async def after_update_callback(device):
def after_update_callback(device):
"""Call after device was updated.""" """Call after device was updated."""
# pylint: disable=unused-argument # 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) self.device.register_device_updated_cb(after_update_callback)
@property @property
@ -187,14 +185,13 @@ class KNXClimate(ClimateDevice):
"""Return the maximum temperature.""" """Return the maximum temperature."""
return self.device.target_temperature_max return self.device.target_temperature_max
@asyncio.coroutine async def async_set_temperature(self, **kwargs):
def async_set_temperature(self, **kwargs):
"""Set new target temperature.""" """Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE) temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None: if temperature is None:
return return
yield from self.device.set_target_temperature(temperature) await self.device.set_target_temperature(temperature)
yield from self.async_update_ha_state() await self.async_update_ha_state()
@property @property
def current_operation(self): def current_operation(self):
@ -210,10 +207,9 @@ class KNXClimate(ClimateDevice):
operation_mode in operation_mode in
self.device.get_supported_operation_modes()] self.device.get_supported_operation_modes()]
@asyncio.coroutine async def async_set_operation_mode(self, operation_mode):
def async_set_operation_mode(self, operation_mode):
"""Set operation mode.""" """Set operation mode."""
if self.device.supports_operation_mode: if self.device.supports_operation_mode:
from xknx.knx import HVACOperationMode from xknx.knx import HVACOperationMode
knx_operation_mode = HVACOperationMode(operation_mode) knx_operation_mode = HVACOperationMode(operation_mode)
yield from self.device.set_operation_mode(knx_operation_mode) await self.device.set_operation_mode(knx_operation_mode)

View file

@ -150,16 +150,14 @@ def stop_cover_tilt(hass, entity_id=None):
hass.services.call(DOMAIN, SERVICE_STOP_COVER_TILT, data) hass.services.call(DOMAIN, SERVICE_STOP_COVER_TILT, data)
@asyncio.coroutine async def async_setup(hass, config):
def async_setup(hass, config):
"""Track states and offer events for covers.""" """Track states and offer events for covers."""
component = EntityComponent( component = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_COVERS) _LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_COVERS)
yield from component.async_setup(config) await component.async_setup(config)
@asyncio.coroutine async def async_handle_cover_service(service):
def async_handle_cover_service(service):
"""Handle calls to the cover services.""" """Handle calls to the cover services."""
covers = component.async_extract_from_service(service) covers = component.async_extract_from_service(service)
method = SERVICE_TO_METHOD.get(service.service) method = SERVICE_TO_METHOD.get(service.service)
@ -169,13 +167,13 @@ def async_setup(hass, config):
# call method # call method
update_tasks = [] update_tasks = []
for cover in covers: for cover in covers:
yield from getattr(cover, method['method'])(**params) await getattr(cover, method['method'])(**params)
if not cover.should_poll: if not cover.should_poll:
continue continue
update_tasks.append(cover.async_update_ha_state(True)) update_tasks.append(cover.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
for service_name in SERVICE_TO_METHOD: for service_name in SERVICE_TO_METHOD:
schema = SERVICE_TO_METHOD[service_name].get( schema = SERVICE_TO_METHOD[service_name].get(

View file

@ -4,7 +4,6 @@ Support for KNX/IP covers.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/cover.knx/ https://home-assistant.io/components/cover.knx/
""" """
import asyncio
import voluptuous as vol import voluptuous as vol
@ -50,8 +49,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
}) })
@asyncio.coroutine async def async_setup_platform(hass, config, async_add_devices,
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): discovery_info=None):
"""Set up cover(s) for KNX platform.""" """Set up cover(s) for KNX platform."""
if discovery_info is not None: if discovery_info is not None:
async_add_devices_discovery(hass, discovery_info, async_add_devices) async_add_devices_discovery(hass, discovery_info, async_add_devices)
@ -106,11 +105,10 @@ class KNXCover(CoverDevice):
@callback @callback
def async_register_callbacks(self): def async_register_callbacks(self):
"""Register callbacks to update hass after device was changed.""" """Register callbacks to update hass after device was changed."""
@asyncio.coroutine async def after_update_callback(device):
def after_update_callback(device):
"""Call after device was updated.""" """Call after device was updated."""
# pylint: disable=unused-argument # 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) self.device.register_device_updated_cb(after_update_callback)
@property @property
@ -147,32 +145,28 @@ class KNXCover(CoverDevice):
"""Return if the cover is closed.""" """Return if the cover is closed."""
return self.device.is_closed() return self.device.is_closed()
@asyncio.coroutine async def async_close_cover(self, **kwargs):
def async_close_cover(self, **kwargs):
"""Close the cover.""" """Close the cover."""
if not self.device.is_closed(): if not self.device.is_closed():
yield from self.device.set_down() await self.device.set_down()
self.start_auto_updater() self.start_auto_updater()
@asyncio.coroutine async def async_open_cover(self, **kwargs):
def async_open_cover(self, **kwargs):
"""Open the cover.""" """Open the cover."""
if not self.device.is_open(): if not self.device.is_open():
yield from self.device.set_up() await self.device.set_up()
self.start_auto_updater() self.start_auto_updater()
@asyncio.coroutine async def async_set_cover_position(self, **kwargs):
def async_set_cover_position(self, **kwargs):
"""Move the cover to a specific position.""" """Move the cover to a specific position."""
if ATTR_POSITION in kwargs: if ATTR_POSITION in kwargs:
position = kwargs[ATTR_POSITION] position = kwargs[ATTR_POSITION]
yield from self.device.set_position(position) await self.device.set_position(position)
self.start_auto_updater() self.start_auto_updater()
@asyncio.coroutine async def async_stop_cover(self, **kwargs):
def async_stop_cover(self, **kwargs):
"""Stop the cover.""" """Stop the cover."""
yield from self.device.stop() await self.device.stop()
self.stop_auto_updater() self.stop_auto_updater()
@property @property
@ -182,12 +176,11 @@ class KNXCover(CoverDevice):
return None return None
return self.device.current_angle() return self.device.current_angle()
@asyncio.coroutine async def async_set_cover_tilt_position(self, **kwargs):
def async_set_cover_tilt_position(self, **kwargs):
"""Move the cover tilt to a specific position.""" """Move the cover tilt to a specific position."""
if ATTR_TILT_POSITION in kwargs: if ATTR_TILT_POSITION in kwargs:
tilt_position = kwargs[ATTR_TILT_POSITION] tilt_position = kwargs[ATTR_TILT_POSITION]
yield from self.device.set_angle(tilt_position) await self.device.set_angle(tilt_position)
def start_auto_updater(self): def start_auto_updater(self):
"""Start the autoupdater to update HASS while cover is moving.""" """Start the autoupdater to update HASS while cover is moving."""

View file

@ -4,7 +4,7 @@ Connects to KNX platform.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/knx/ https://home-assistant.io/components/knx/
""" """
import asyncio
import logging import logging
import voluptuous as vol import voluptuous as vol
@ -66,13 +66,12 @@ SERVICE_KNX_SEND_SCHEMA = vol.Schema({
}) })
@asyncio.coroutine async def async_setup(hass, config):
def async_setup(hass, config):
"""Set up the KNX component.""" """Set up the KNX component."""
from xknx.exceptions import XKNXException from xknx.exceptions import XKNXException
try: try:
hass.data[DATA_KNX] = KNXModule(hass, config) hass.data[DATA_KNX] = KNXModule(hass, config)
yield from hass.data[DATA_KNX].start() await hass.data[DATA_KNX].start()
except XKNXException as ex: except XKNXException as ex:
_LOGGER.warning("Can't connect to KNX interface: %s", ex) _LOGGER.warning("Can't connect to KNX interface: %s", ex)
@ -128,20 +127,18 @@ class KNXModule(object):
from xknx import XKNX from xknx import XKNX
self.xknx = XKNX(config=self.config_file(), loop=self.hass.loop) self.xknx = XKNX(config=self.config_file(), loop=self.hass.loop)
@asyncio.coroutine async def start(self):
def start(self):
"""Start KNX object. Connect to tunneling or Routing device.""" """Start KNX object. Connect to tunneling or Routing device."""
connection_config = self.connection_config() connection_config = self.connection_config()
yield from self.xknx.start( await self.xknx.start(
state_updater=self.config[DOMAIN][CONF_KNX_STATE_UPDATER], state_updater=self.config[DOMAIN][CONF_KNX_STATE_UPDATER],
connection_config=connection_config) connection_config=connection_config)
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.stop) self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.stop)
self.connected = True self.connected = True
@asyncio.coroutine async def stop(self, event):
def stop(self, event):
"""Stop KNX object. Disconnect from tunneling or Routing device.""" """Stop KNX object. Disconnect from tunneling or Routing device."""
yield from self.xknx.stop() await self.xknx.stop()
def config_file(self): def config_file(self):
"""Resolve and return the full path of xknx.yaml if configured.""" """Resolve and return the full path of xknx.yaml if configured."""
@ -202,8 +199,7 @@ class KNXModule(object):
self.xknx.telegram_queue.register_telegram_received_cb( self.xknx.telegram_queue.register_telegram_received_cb(
self.telegram_received_cb, address_filters) self.telegram_received_cb, address_filters)
@asyncio.coroutine async def telegram_received_cb(self, telegram):
def telegram_received_cb(self, telegram):
"""Call invoked after a KNX telegram was received.""" """Call invoked after a KNX telegram was received."""
self.hass.bus.fire('knx_event', { self.hass.bus.fire('knx_event', {
'address': telegram.group_address.str(), 'address': telegram.group_address.str(),
@ -212,8 +208,7 @@ class KNXModule(object):
# False signals XKNX to proceed with processing telegrams. # False signals XKNX to proceed with processing telegrams.
return False return False
@asyncio.coroutine async def service_send_to_knx_bus(self, call):
def service_send_to_knx_bus(self, call):
"""Service for sending an arbitrary KNX message to the KNX bus.""" """Service for sending an arbitrary KNX message to the KNX bus."""
from xknx.knx import Telegram, GroupAddress, DPTBinary, DPTArray from xknx.knx import Telegram, GroupAddress, DPTBinary, DPTArray
attr_payload = call.data.get(SERVICE_KNX_ATTR_PAYLOAD) attr_payload = call.data.get(SERVICE_KNX_ATTR_PAYLOAD)
@ -230,7 +225,7 @@ class KNXModule(object):
telegram = Telegram() telegram = Telegram()
telegram.payload = payload telegram.payload = payload
telegram.group_address = address telegram.group_address = address
yield from self.xknx.telegrams.put(telegram) await self.xknx.telegrams.put(telegram)
class KNXAutomation(): class KNXAutomation():

View file

@ -240,20 +240,18 @@ def preprocess_turn_on_alternatives(params):
params[ATTR_BRIGHTNESS] = int(255 * brightness_pct/100) params[ATTR_BRIGHTNESS] = int(255 * brightness_pct/100)
@asyncio.coroutine async def async_setup(hass, config):
def async_setup(hass, config):
"""Expose light control via state machine and services.""" """Expose light control via state machine and services."""
component = EntityComponent( component = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_LIGHTS) _LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_LIGHTS)
yield from component.async_setup(config) await component.async_setup(config)
# load profiles from files # load profiles from files
profiles_valid = yield from Profiles.load_profiles(hass) profiles_valid = await Profiles.load_profiles(hass)
if not profiles_valid: if not profiles_valid:
return False return False
@asyncio.coroutine async def async_handle_light_service(service):
def async_handle_light_service(service):
"""Handle a turn light on or off service call.""" """Handle a turn light on or off service call."""
# Get the validated data # Get the validated data
params = service.data.copy() params = service.data.copy()
@ -267,18 +265,18 @@ def async_setup(hass, config):
update_tasks = [] 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) await light.async_turn_on(**params)
elif service.service == SERVICE_TURN_OFF: elif service.service == SERVICE_TURN_OFF:
yield from light.async_turn_off(**params) await light.async_turn_off(**params)
else: else:
yield from light.async_toggle(**params) await light.async_toggle(**params)
if not light.should_poll: if not light.should_poll:
continue continue
update_tasks.append(light.async_update_ha_state(True)) update_tasks.append(light.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
# Listen for light on and light off service calls. # Listen for light on and light off service calls.
hass.services.async_register( hass.services.async_register(
@ -302,8 +300,7 @@ class Profiles:
_all = None _all = None
@classmethod @classmethod
@asyncio.coroutine async def load_profiles(cls, hass):
def load_profiles(cls, hass):
"""Load and cache profiles.""" """Load and cache profiles."""
def load_profile_data(hass): def load_profile_data(hass):
"""Load built-in profiles and custom profiles.""" """Load built-in profiles and custom profiles."""
@ -333,7 +330,7 @@ class Profiles:
return None return None
return profiles return profiles
cls._all = yield from hass.async_add_job(load_profile_data, hass) cls._all = await hass.async_add_job(load_profile_data, hass)
return cls._all is not None return cls._all is not None
@classmethod @classmethod

View file

@ -4,7 +4,6 @@ Support for KNX/IP lights.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.knx/ https://home-assistant.io/components/light.knx/
""" """
import asyncio
import voluptuous as vol import voluptuous as vol
@ -37,8 +36,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
}) })
@asyncio.coroutine async def async_setup_platform(hass, config, async_add_devices,
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): discovery_info=None):
"""Set up lights for KNX platform.""" """Set up lights for KNX platform."""
if discovery_info is not None: if discovery_info is not None:
async_add_devices_discovery(hass, discovery_info, async_add_devices) async_add_devices_discovery(hass, discovery_info, async_add_devices)
@ -86,11 +85,10 @@ class KNXLight(Light):
@callback @callback
def async_register_callbacks(self): def async_register_callbacks(self):
"""Register callbacks to update hass after device was changed.""" """Register callbacks to update hass after device was changed."""
@asyncio.coroutine async def after_update_callback(device):
def after_update_callback(device):
"""Call after device was updated.""" """Call after device was updated."""
# pylint: disable=unused-argument # 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) self.device.register_device_updated_cb(after_update_callback)
@property @property
@ -162,17 +160,15 @@ class KNXLight(Light):
flags |= SUPPORT_RGB_COLOR flags |= SUPPORT_RGB_COLOR
return flags return flags
@asyncio.coroutine async def async_turn_on(self, **kwargs):
def async_turn_on(self, **kwargs):
"""Turn the light on.""" """Turn the light on."""
if ATTR_BRIGHTNESS in kwargs and self.device.supports_dimming: if ATTR_BRIGHTNESS in kwargs and self.device.supports_dimming:
yield from self.device.set_brightness(int(kwargs[ATTR_BRIGHTNESS])) await self.device.set_brightness(int(kwargs[ATTR_BRIGHTNESS]))
elif ATTR_RGB_COLOR in kwargs: elif ATTR_RGB_COLOR in kwargs:
yield from self.device.set_color(kwargs[ATTR_RGB_COLOR]) await self.device.set_color(kwargs[ATTR_RGB_COLOR])
else: else:
yield from self.device.set_on() await self.device.set_on()
@asyncio.coroutine async def async_turn_off(self, **kwargs):
def async_turn_off(self, **kwargs):
"""Turn the light off.""" """Turn the light off."""
yield from self.device.set_off() await self.device.set_off()

View file

@ -4,7 +4,7 @@ KNX/IP notification service.
For more details about this platform, please refer to the documentation For more details about this platform, please refer to the documentation
https://home-assistant.io/components/notify.knx/ https://home-assistant.io/components/notify.knx/
""" """
import asyncio
import voluptuous as vol import voluptuous as vol
from homeassistant.components.knx import DATA_KNX, ATTR_DISCOVER_DEVICES from homeassistant.components.knx import DATA_KNX, ATTR_DISCOVER_DEVICES
@ -24,8 +24,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
}) })
@asyncio.coroutine async def async_get_service(hass, config, discovery_info=None):
def async_get_service(hass, config, discovery_info=None):
"""Get the KNX notification service.""" """Get the KNX notification service."""
return async_get_service_discovery(hass, discovery_info) \ return async_get_service_discovery(hass, discovery_info) \
if discovery_info is not None else \ if discovery_info is not None else \
@ -72,23 +71,20 @@ class KNXNotificationService(BaseNotificationService):
ret[device.name] = device.name ret[device.name] = device.name
return ret return ret
@asyncio.coroutine async def async_send_message(self, message="", **kwargs):
def async_send_message(self, message="", **kwargs):
"""Send a notification to knx bus.""" """Send a notification to knx bus."""
if "target" in kwargs: if "target" in kwargs:
yield from self._async_send_to_device(message, kwargs["target"]) await self._async_send_to_device(message, kwargs["target"])
else: else:
yield from self._async_send_to_all_devices(message) await self._async_send_to_all_devices(message)
@asyncio.coroutine async def _async_send_to_all_devices(self, message):
def _async_send_to_all_devices(self, message):
"""Send a notification to knx bus to all connected devices.""" """Send a notification to knx bus to all connected devices."""
for device in self.devices: for device in self.devices:
yield from device.set(message) await device.set(message)
@asyncio.coroutine async def _async_send_to_device(self, message, names):
def _async_send_to_device(self, message, names):
"""Send a notification to knx bus to device with given names.""" """Send a notification to knx bus to device with given names."""
for device in self.devices: for device in self.devices:
if device.name in names: if device.name in names:
yield from device.set(message) await device.set(message)

View file

@ -68,22 +68,20 @@ def activate(hass, entity_id=None):
hass.services.call(DOMAIN, SERVICE_TURN_ON, data) hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
@asyncio.coroutine async def async_setup(hass, config):
def async_setup(hass, config):
"""Set up the scenes.""" """Set up the scenes."""
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
component = EntityComponent(logger, DOMAIN, hass) component = EntityComponent(logger, DOMAIN, hass)
yield from component.async_setup(config) await component.async_setup(config)
@asyncio.coroutine async def async_handle_scene_service(service):
def async_handle_scene_service(service):
"""Handle calls to the switch services.""" """Handle calls to the switch services."""
target_scenes = component.async_extract_from_service(service) target_scenes = component.async_extract_from_service(service)
tasks = [scene.async_activate() for scene in target_scenes] tasks = [scene.async_activate() for scene in target_scenes]
if tasks: if tasks:
yield from asyncio.wait(tasks, loop=hass.loop) await asyncio.wait(tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_TURN_ON, async_handle_scene_service, DOMAIN, SERVICE_TURN_ON, async_handle_scene_service,

View file

@ -4,7 +4,6 @@ Support for VELUX scenes.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/scene.velux/ https://home-assistant.io/components/scene.velux/
""" """
import asyncio
from homeassistant.components.scene import Scene from homeassistant.components.scene import Scene
from homeassistant.components.velux import _LOGGER, DATA_VELUX from homeassistant.components.velux import _LOGGER, DATA_VELUX
@ -13,9 +12,8 @@ from homeassistant.components.velux import _LOGGER, DATA_VELUX
DEPENDENCIES = ['velux'] DEPENDENCIES = ['velux']
@asyncio.coroutine async def async_setup_platform(hass, config, async_add_devices,
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
discovery_info=None):
"""Set up the scenes for velux platform.""" """Set up the scenes for velux platform."""
entities = [] entities = []
for scene in hass.data[DATA_VELUX].pyvlx.scenes: for scene in hass.data[DATA_VELUX].pyvlx.scenes:
@ -36,7 +34,6 @@ class VeluxScene(Scene):
"""Return the name of the scene.""" """Return the name of the scene."""
return self.scene.name return self.scene.name
@asyncio.coroutine async def async_activate(self):
def async_activate(self):
"""Activate the scene.""" """Activate the scene."""
yield from self.scene.run() await self.scene.run()

View file

@ -4,7 +4,7 @@ Component to interface with various sensors that can be monitored.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/sensor/ https://home-assistant.io/components/sensor/
""" """
import asyncio
from datetime import timedelta from datetime import timedelta
import logging import logging
@ -20,11 +20,10 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}'
SCAN_INTERVAL = timedelta(seconds=30) SCAN_INTERVAL = timedelta(seconds=30)
@asyncio.coroutine async def async_setup(hass, config):
def async_setup(hass, config):
"""Track states and offer events for sensors.""" """Track states and offer events for sensors."""
component = EntityComponent( component = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL) _LOGGER, DOMAIN, hass, SCAN_INTERVAL)
yield from component.async_setup(config) await component.async_setup(config)
return True return True

View file

@ -4,7 +4,6 @@ Support for KNX/IP sensors.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.knx/ https://home-assistant.io/components/sensor.knx/
""" """
import asyncio
import voluptuous as vol import voluptuous as vol
@ -28,8 +27,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
}) })
@asyncio.coroutine async def async_setup_platform(hass, config, async_add_devices,
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): discovery_info=None):
"""Set up sensor(s) for KNX platform.""" """Set up sensor(s) for KNX platform."""
if discovery_info is not None: if discovery_info is not None:
async_add_devices_discovery(hass, discovery_info, async_add_devices) async_add_devices_discovery(hass, discovery_info, async_add_devices)
@ -72,11 +71,10 @@ class KNXSensor(Entity):
@callback @callback
def async_register_callbacks(self): def async_register_callbacks(self):
"""Register callbacks to update hass after device was changed.""" """Register callbacks to update hass after device was changed."""
@asyncio.coroutine async def after_update_callback(device):
def after_update_callback(device):
"""Call after device was updated.""" """Call after device was updated."""
# pylint: disable=unused-argument # 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) self.device.register_device_updated_cb(after_update_callback)
@property @property

View file

@ -93,33 +93,31 @@ def toggle(hass, entity_id=None):
hass.services.call(DOMAIN, SERVICE_TOGGLE, data) hass.services.call(DOMAIN, SERVICE_TOGGLE, data)
@asyncio.coroutine async def async_setup(hass, config):
def async_setup(hass, config):
"""Track states and offer events for switches.""" """Track states and offer events for switches."""
component = EntityComponent( component = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_SWITCHES) _LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_SWITCHES)
yield from component.async_setup(config) await component.async_setup(config)
@asyncio.coroutine async def async_handle_switch_service(service):
def async_handle_switch_service(service):
"""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 = [] 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() await switch.async_turn_on()
elif service.service == SERVICE_TOGGLE: elif service.service == SERVICE_TOGGLE:
yield from switch.async_toggle() await switch.async_toggle()
else: else:
yield from switch.async_turn_off() await switch.async_turn_off()
if not switch.should_poll: if not switch.should_poll:
continue continue
update_tasks.append(switch.async_update_ha_state(True)) update_tasks.append(switch.async_update_ha_state(True))
if update_tasks: if update_tasks:
yield from asyncio.wait(update_tasks, loop=hass.loop) await asyncio.wait(update_tasks, loop=hass.loop)
hass.services.async_register( hass.services.async_register(
DOMAIN, SERVICE_TURN_OFF, async_handle_switch_service, DOMAIN, SERVICE_TURN_OFF, async_handle_switch_service,

View file

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

View file

@ -5,7 +5,6 @@ For more details about this component, please refer to the documentation at
https://home-assistant.io/components/velux/ https://home-assistant.io/components/velux/
""" """
import logging import logging
import asyncio
import voluptuous as vol import voluptuous as vol
@ -28,13 +27,12 @@ CONFIG_SCHEMA = vol.Schema({
}, extra=vol.ALLOW_EXTRA) }, extra=vol.ALLOW_EXTRA)
@asyncio.coroutine async def async_setup(hass, config):
def async_setup(hass, config):
"""Set up the velux component.""" """Set up the velux component."""
from pyvlx import PyVLXException from pyvlx import PyVLXException
try: try:
hass.data[DATA_VELUX] = VeluxModule(hass, config) hass.data[DATA_VELUX] = VeluxModule(hass, config)
yield from hass.data[DATA_VELUX].async_start() await hass.data[DATA_VELUX].async_start()
except PyVLXException as ex: except PyVLXException as ex:
_LOGGER.exception("Can't connect to velux interface: %s", ex) _LOGGER.exception("Can't connect to velux interface: %s", ex)
@ -58,7 +56,6 @@ class VeluxModule:
host=host, host=host,
password=password) password=password)
@asyncio.coroutine async def async_start(self):
def async_start(self):
"""Start velux component.""" """Start velux component."""
yield from self.pyvlx.load_scenes() await self.pyvlx.load_scenes()