From 3713dfe1393cc4b65d83c5b629f91ca04baeeba1 Mon Sep 17 00:00:00 2001 From: Julius Mittenzwei Date: Sat, 24 Feb 2018 19:24:33 +0100 Subject: [PATCH] Removing asyncio.coroutine syntax from some components (#12507) * Removing asyncio.coroutine syntax (first steps) * merge conflict * fixed small bug * pylint --- .../components/binary_sensor/__init__.py | 7 +- homeassistant/components/binary_sensor/knx.py | 10 +-- homeassistant/components/climate/__init__.py | 74 ++++++++----------- homeassistant/components/climate/knx.py | 22 +++--- homeassistant/components/cover/__init__.py | 12 ++- homeassistant/components/cover/knx.py | 35 ++++----- homeassistant/components/knx.py | 25 +++---- homeassistant/components/light/__init__.py | 23 +++--- homeassistant/components/light/knx.py | 24 +++--- homeassistant/components/notify/knx.py | 22 +++--- homeassistant/components/scene/__init__.py | 10 +-- homeassistant/components/scene/velux.py | 11 +-- homeassistant/components/sensor/__init__.py | 7 +- homeassistant/components/sensor/knx.py | 10 +-- homeassistant/components/switch/__init__.py | 16 ++-- homeassistant/components/switch/knx.py | 20 ++--- homeassistant/components/velux.py | 11 +-- 17 files changed, 140 insertions(+), 199 deletions(-) diff --git a/homeassistant/components/binary_sensor/__init__.py b/homeassistant/components/binary_sensor/__init__.py index df271a7ebac..919abc678e4 100644 --- a/homeassistant/components/binary_sensor/__init__.py +++ b/homeassistant/components/binary_sensor/__init__.py @@ -4,7 +4,7 @@ Component to interface with binary sensors. For more details about this component, please refer to the documentation at https://home-assistant.io/components/binary_sensor/ """ -import asyncio + from datetime import timedelta import logging @@ -47,13 +47,12 @@ DEVICE_CLASSES = [ DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.In(DEVICE_CLASSES)) -@asyncio.coroutine -def async_setup(hass, config): +async def async_setup(hass, config): """Track states and offer events for binary sensors.""" component = EntityComponent( logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL) - yield from component.async_setup(config) + await component.async_setup(config) return True diff --git a/homeassistant/components/binary_sensor/knx.py b/homeassistant/components/binary_sensor/knx.py index 2b33d6850d6..1802ae34454 100644 --- a/homeassistant/components/binary_sensor/knx.py +++ b/homeassistant/components/binary_sensor/knx.py @@ -4,7 +4,6 @@ Support for KNX/IP binary sensors. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/binary_sensor.knx/ """ -import asyncio import voluptuous as vol @@ -53,8 +52,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 binary sensor(s) for KNX platform.""" if discovery_info is not None: async_add_devices_discovery(hass, discovery_info, async_add_devices) @@ -111,11 +110,10 @@ class KNXBinarySensor(BinarySensorDevice): @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 diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index e1a5f71af83..7ea23f4fd65 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -237,14 +237,12 @@ def set_swing_mode(hass, swing_mode, entity_id=None): hass.services.call(DOMAIN, SERVICE_SET_SWING_MODE, data) -@asyncio.coroutine -def async_setup(hass, config): +async def async_setup(hass, config): """Set up climate devices.""" component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL) - yield from component.async_setup(config) + await component.async_setup(config) - @asyncio.coroutine - def async_away_mode_set_service(service): + async def async_away_mode_set_service(service): """Set away mode on target climate devices.""" target_climate = component.async_extract_from_service(service) @@ -253,23 +251,22 @@ def async_setup(hass, config): update_tasks = [] for climate in target_climate: if away_mode: - yield from climate.async_turn_away_mode_on() + await climate.async_turn_away_mode_on() else: - yield from climate.async_turn_away_mode_off() + await climate.async_turn_away_mode_off() if not climate.should_poll: continue update_tasks.append(climate.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_SET_AWAY_MODE, async_away_mode_set_service, schema=SET_AWAY_MODE_SCHEMA) - @asyncio.coroutine - def async_hold_mode_set_service(service): + async def async_hold_mode_set_service(service): """Set hold mode on target climate devices.""" target_climate = component.async_extract_from_service(service) @@ -277,21 +274,20 @@ def async_setup(hass, config): update_tasks = [] 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: continue update_tasks.append(climate.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_SET_HOLD_MODE, async_hold_mode_set_service, schema=SET_HOLD_MODE_SCHEMA) - @asyncio.coroutine - def async_aux_heat_set_service(service): + async def async_aux_heat_set_service(service): """Set auxiliary heater on target climate devices.""" target_climate = component.async_extract_from_service(service) @@ -300,23 +296,22 @@ def async_setup(hass, config): update_tasks = [] for climate in target_climate: if aux_heat: - yield from climate.async_turn_aux_heat_on() + await climate.async_turn_aux_heat_on() else: - yield from climate.async_turn_aux_heat_off() + await climate.async_turn_aux_heat_off() if not climate.should_poll: continue update_tasks.append(climate.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_SET_AUX_HEAT, async_aux_heat_set_service, schema=SET_AUX_HEAT_SCHEMA) - @asyncio.coroutine - def async_temperature_set_service(service): + async def async_temperature_set_service(service): """Set temperature on the target climate devices.""" target_climate = component.async_extract_from_service(service) @@ -333,21 +328,20 @@ def async_setup(hass, config): else: kwargs[value] = temp - yield from climate.async_set_temperature(**kwargs) + await climate.async_set_temperature(**kwargs) if not climate.should_poll: continue update_tasks.append(climate.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_SET_TEMPERATURE, async_temperature_set_service, schema=SET_TEMPERATURE_SCHEMA) - @asyncio.coroutine - def async_humidity_set_service(service): + async def async_humidity_set_service(service): """Set humidity on the target climate devices.""" target_climate = component.async_extract_from_service(service) @@ -355,20 +349,19 @@ def async_setup(hass, config): update_tasks = [] for climate in target_climate: - yield from climate.async_set_humidity(humidity) + await climate.async_set_humidity(humidity) if not climate.should_poll: continue update_tasks.append(climate.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_SET_HUMIDITY, async_humidity_set_service, schema=SET_HUMIDITY_SCHEMA) - @asyncio.coroutine - def async_fan_mode_set_service(service): + async def async_fan_mode_set_service(service): """Set fan mode on target climate devices.""" target_climate = component.async_extract_from_service(service) @@ -376,20 +369,19 @@ def async_setup(hass, config): update_tasks = [] 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: continue update_tasks.append(climate.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_SET_FAN_MODE, async_fan_mode_set_service, schema=SET_FAN_MODE_SCHEMA) - @asyncio.coroutine - def async_operation_set_service(service): + async def async_operation_set_service(service): """Set operating mode on the target climate devices.""" target_climate = component.async_extract_from_service(service) @@ -397,20 +389,19 @@ def async_setup(hass, config): update_tasks = [] 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: continue update_tasks.append(climate.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_SET_OPERATION_MODE, async_operation_set_service, schema=SET_OPERATION_MODE_SCHEMA) - @asyncio.coroutine - def async_swing_set_service(service): + async def async_swing_set_service(service): """Set swing mode on the target climate devices.""" target_climate = component.async_extract_from_service(service) @@ -418,36 +409,35 @@ def async_setup(hass, config): update_tasks = [] 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: continue update_tasks.append(climate.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_SET_SWING_MODE, async_swing_set_service, schema=SET_SWING_MODE_SCHEMA) - @asyncio.coroutine - def async_on_off_service(service): + async def async_on_off_service(service): """Handle on/off calls.""" target_climate = component.async_extract_from_service(service) update_tasks = [] for climate in target_climate: if service.service == SERVICE_TURN_ON: - yield from climate.async_turn_on() + await climate.async_turn_on() elif service.service == SERVICE_TURN_OFF: - yield from climate.async_turn_off() + await climate.async_turn_off() if not climate.should_poll: continue update_tasks.append(climate.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_on_off_service, diff --git a/homeassistant/components/climate/knx.py b/homeassistant/components/climate/knx.py index 1bbc5b789fb..5ce6cc2fa7a 100644 --- a/homeassistant/components/climate/knx.py +++ b/homeassistant/components/climate/knx.py @@ -4,7 +4,6 @@ Support for KNX/IP climate devices. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/climate.knx/ """ -import asyncio import voluptuous as vol @@ -61,8 +60,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 climate(s) for KNX platform.""" if discovery_info is not None: async_add_devices_discovery(hass, discovery_info, async_add_devices) @@ -135,11 +134,10 @@ class KNXClimate(ClimateDevice): 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 @@ -187,14 +185,13 @@ class KNXClimate(ClimateDevice): """Return the maximum temperature.""" return self.device.target_temperature_max - @asyncio.coroutine - def async_set_temperature(self, **kwargs): + async def async_set_temperature(self, **kwargs): """Set new target temperature.""" temperature = kwargs.get(ATTR_TEMPERATURE) if temperature is None: return - yield from self.device.set_target_temperature(temperature) - yield from self.async_update_ha_state() + await self.device.set_target_temperature(temperature) + await self.async_update_ha_state() @property def current_operation(self): @@ -210,10 +207,9 @@ class KNXClimate(ClimateDevice): operation_mode in self.device.get_supported_operation_modes()] - @asyncio.coroutine - def async_set_operation_mode(self, operation_mode): + async def async_set_operation_mode(self, operation_mode): """Set operation mode.""" if self.device.supports_operation_mode: from xknx.knx import HVACOperationMode 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) diff --git a/homeassistant/components/cover/__init__.py b/homeassistant/components/cover/__init__.py index 1dfa0028ab8..b24361d8293 100644 --- a/homeassistant/components/cover/__init__.py +++ b/homeassistant/components/cover/__init__.py @@ -150,16 +150,14 @@ def stop_cover_tilt(hass, entity_id=None): hass.services.call(DOMAIN, SERVICE_STOP_COVER_TILT, data) -@asyncio.coroutine -def async_setup(hass, config): +async def async_setup(hass, config): """Track states and offer events for covers.""" component = EntityComponent( _LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_COVERS) - yield from component.async_setup(config) + await component.async_setup(config) - @asyncio.coroutine - def async_handle_cover_service(service): + async def async_handle_cover_service(service): """Handle calls to the cover services.""" covers = component.async_extract_from_service(service) method = SERVICE_TO_METHOD.get(service.service) @@ -169,13 +167,13 @@ def async_setup(hass, config): # call method update_tasks = [] for cover in covers: - yield from getattr(cover, method['method'])(**params) + await getattr(cover, method['method'])(**params) if not cover.should_poll: continue update_tasks.append(cover.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) for service_name in SERVICE_TO_METHOD: schema = SERVICE_TO_METHOD[service_name].get( diff --git a/homeassistant/components/cover/knx.py b/homeassistant/components/cover/knx.py index 730a2b29a2e..83668924268 100644 --- a/homeassistant/components/cover/knx.py +++ b/homeassistant/components/cover/knx.py @@ -4,7 +4,6 @@ Support for KNX/IP covers. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/cover.knx/ """ -import asyncio import voluptuous as vol @@ -50,8 +49,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 cover(s) for KNX platform.""" if discovery_info is not None: async_add_devices_discovery(hass, discovery_info, async_add_devices) @@ -106,11 +105,10 @@ class KNXCover(CoverDevice): @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 @@ -147,32 +145,28 @@ class KNXCover(CoverDevice): """Return if the cover is closed.""" return self.device.is_closed() - @asyncio.coroutine - def async_close_cover(self, **kwargs): + async def async_close_cover(self, **kwargs): """Close the cover.""" if not self.device.is_closed(): - yield from self.device.set_down() + await self.device.set_down() self.start_auto_updater() - @asyncio.coroutine - def async_open_cover(self, **kwargs): + async def async_open_cover(self, **kwargs): """Open the cover.""" if not self.device.is_open(): - yield from self.device.set_up() + await self.device.set_up() self.start_auto_updater() - @asyncio.coroutine - def async_set_cover_position(self, **kwargs): + async def async_set_cover_position(self, **kwargs): """Move the cover to a specific position.""" if ATTR_POSITION in kwargs: position = kwargs[ATTR_POSITION] - yield from self.device.set_position(position) + await self.device.set_position(position) self.start_auto_updater() - @asyncio.coroutine - def async_stop_cover(self, **kwargs): + async def async_stop_cover(self, **kwargs): """Stop the cover.""" - yield from self.device.stop() + await self.device.stop() self.stop_auto_updater() @property @@ -182,12 +176,11 @@ class KNXCover(CoverDevice): return None return self.device.current_angle() - @asyncio.coroutine - def async_set_cover_tilt_position(self, **kwargs): + async def async_set_cover_tilt_position(self, **kwargs): """Move the cover tilt to a specific position.""" if ATTR_TILT_POSITION in kwargs: 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): """Start the autoupdater to update HASS while cover is moving.""" diff --git a/homeassistant/components/knx.py b/homeassistant/components/knx.py index a90a5246759..63407fd6246 100644 --- a/homeassistant/components/knx.py +++ b/homeassistant/components/knx.py @@ -4,7 +4,7 @@ Connects to KNX platform. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/knx/ """ -import asyncio + import logging import voluptuous as vol @@ -66,13 +66,12 @@ SERVICE_KNX_SEND_SCHEMA = vol.Schema({ }) -@asyncio.coroutine -def async_setup(hass, config): +async def async_setup(hass, config): """Set up the KNX component.""" from xknx.exceptions import XKNXException try: hass.data[DATA_KNX] = KNXModule(hass, config) - yield from hass.data[DATA_KNX].start() + await hass.data[DATA_KNX].start() except XKNXException as ex: _LOGGER.warning("Can't connect to KNX interface: %s", ex) @@ -128,20 +127,18 @@ class KNXModule(object): from xknx import XKNX self.xknx = XKNX(config=self.config_file(), loop=self.hass.loop) - @asyncio.coroutine - def start(self): + async def start(self): """Start KNX object. Connect to tunneling or Routing device.""" connection_config = self.connection_config() - yield from self.xknx.start( + await self.xknx.start( state_updater=self.config[DOMAIN][CONF_KNX_STATE_UPDATER], connection_config=connection_config) self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.stop) self.connected = True - @asyncio.coroutine - def stop(self, event): + async def stop(self, event): """Stop KNX object. Disconnect from tunneling or Routing device.""" - yield from self.xknx.stop() + await self.xknx.stop() def config_file(self): """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.telegram_received_cb, address_filters) - @asyncio.coroutine - def telegram_received_cb(self, telegram): + async def telegram_received_cb(self, telegram): """Call invoked after a KNX telegram was received.""" self.hass.bus.fire('knx_event', { 'address': telegram.group_address.str(), @@ -212,8 +208,7 @@ class KNXModule(object): # False signals XKNX to proceed with processing telegrams. return False - @asyncio.coroutine - def service_send_to_knx_bus(self, call): + async def service_send_to_knx_bus(self, call): """Service for sending an arbitrary KNX message to the KNX bus.""" from xknx.knx import Telegram, GroupAddress, DPTBinary, DPTArray attr_payload = call.data.get(SERVICE_KNX_ATTR_PAYLOAD) @@ -230,7 +225,7 @@ class KNXModule(object): telegram = Telegram() telegram.payload = payload telegram.group_address = address - yield from self.xknx.telegrams.put(telegram) + await self.xknx.telegrams.put(telegram) class KNXAutomation(): diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index cfeceb0c991..b7e8966394e 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -240,20 +240,18 @@ def preprocess_turn_on_alternatives(params): params[ATTR_BRIGHTNESS] = int(255 * brightness_pct/100) -@asyncio.coroutine -def async_setup(hass, config): +async def async_setup(hass, config): """Expose light control via state machine and services.""" component = EntityComponent( _LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_LIGHTS) - yield from component.async_setup(config) + await component.async_setup(config) # load profiles from files - profiles_valid = yield from Profiles.load_profiles(hass) + profiles_valid = await Profiles.load_profiles(hass) if not profiles_valid: return False - @asyncio.coroutine - def async_handle_light_service(service): + async def async_handle_light_service(service): """Handle a turn light on or off service call.""" # Get the validated data params = service.data.copy() @@ -267,18 +265,18 @@ def async_setup(hass, config): update_tasks = [] for light in target_lights: 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: - yield from light.async_turn_off(**params) + await light.async_turn_off(**params) else: - yield from light.async_toggle(**params) + await light.async_toggle(**params) if not light.should_poll: continue update_tasks.append(light.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) # Listen for light on and light off service calls. hass.services.async_register( @@ -302,8 +300,7 @@ class Profiles: _all = None @classmethod - @asyncio.coroutine - def load_profiles(cls, hass): + async def load_profiles(cls, hass): """Load and cache profiles.""" def load_profile_data(hass): """Load built-in profiles and custom profiles.""" @@ -333,7 +330,7 @@ class Profiles: return None 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 @classmethod diff --git a/homeassistant/components/light/knx.py b/homeassistant/components/light/knx.py index 020184b8501..1b14ff75ecc 100644 --- a/homeassistant/components/light/knx.py +++ b/homeassistant/components/light/knx.py @@ -4,7 +4,6 @@ Support for KNX/IP lights. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/light.knx/ """ -import asyncio import voluptuous as vol @@ -37,8 +36,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 lights for KNX platform.""" if discovery_info is not None: async_add_devices_discovery(hass, discovery_info, async_add_devices) @@ -86,11 +85,10 @@ class KNXLight(Light): @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 @@ -162,17 +160,15 @@ class KNXLight(Light): flags |= SUPPORT_RGB_COLOR return flags - @asyncio.coroutine - def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs): """Turn the light on.""" 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: - yield from self.device.set_color(kwargs[ATTR_RGB_COLOR]) + await self.device.set_color(kwargs[ATTR_RGB_COLOR]) else: - 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 light off.""" - yield from self.device.set_off() + await self.device.set_off() diff --git a/homeassistant/components/notify/knx.py b/homeassistant/components/notify/knx.py index e6bb400d421..750e3945569 100644 --- a/homeassistant/components/notify/knx.py +++ b/homeassistant/components/notify/knx.py @@ -4,7 +4,7 @@ KNX/IP notification service. For more details about this platform, please refer to the documentation https://home-assistant.io/components/notify.knx/ """ -import asyncio + import voluptuous as vol from homeassistant.components.knx import DATA_KNX, ATTR_DISCOVER_DEVICES @@ -24,8 +24,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ }) -@asyncio.coroutine -def async_get_service(hass, config, discovery_info=None): +async def async_get_service(hass, config, discovery_info=None): """Get the KNX notification service.""" return async_get_service_discovery(hass, discovery_info) \ if discovery_info is not None else \ @@ -72,23 +71,20 @@ class KNXNotificationService(BaseNotificationService): ret[device.name] = device.name return ret - @asyncio.coroutine - def async_send_message(self, message="", **kwargs): + async def async_send_message(self, message="", **kwargs): """Send a notification to knx bus.""" if "target" in kwargs: - yield from self._async_send_to_device(message, kwargs["target"]) + await self._async_send_to_device(message, kwargs["target"]) else: - yield from self._async_send_to_all_devices(message) + await self._async_send_to_all_devices(message) - @asyncio.coroutine - def _async_send_to_all_devices(self, message): + async def _async_send_to_all_devices(self, message): """Send a notification to knx bus to all connected devices.""" for device in self.devices: - yield from device.set(message) + await device.set(message) - @asyncio.coroutine - def _async_send_to_device(self, message, names): + async def _async_send_to_device(self, message, names): """Send a notification to knx bus to device with given names.""" for device in self.devices: if device.name in names: - yield from device.set(message) + await device.set(message) diff --git a/homeassistant/components/scene/__init__.py b/homeassistant/components/scene/__init__.py index fbfe2b6959a..8f0b9d5c7ab 100644 --- a/homeassistant/components/scene/__init__.py +++ b/homeassistant/components/scene/__init__.py @@ -68,22 +68,20 @@ def activate(hass, entity_id=None): hass.services.call(DOMAIN, SERVICE_TURN_ON, data) -@asyncio.coroutine -def async_setup(hass, config): +async def async_setup(hass, config): """Set up the scenes.""" logger = logging.getLogger(__name__) component = EntityComponent(logger, DOMAIN, hass) - yield from component.async_setup(config) + await component.async_setup(config) - @asyncio.coroutine - def async_handle_scene_service(service): + async def async_handle_scene_service(service): """Handle calls to the switch services.""" target_scenes = component.async_extract_from_service(service) tasks = [scene.async_activate() for scene in target_scenes] if tasks: - yield from asyncio.wait(tasks, loop=hass.loop) + await asyncio.wait(tasks, loop=hass.loop) hass.services.async_register( DOMAIN, SERVICE_TURN_ON, async_handle_scene_service, diff --git a/homeassistant/components/scene/velux.py b/homeassistant/components/scene/velux.py index 86d71153a2b..63bb23b1086 100644 --- a/homeassistant/components/scene/velux.py +++ b/homeassistant/components/scene/velux.py @@ -4,7 +4,6 @@ Support for VELUX scenes. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/scene.velux/ """ -import asyncio from homeassistant.components.scene import Scene from homeassistant.components.velux import _LOGGER, DATA_VELUX @@ -13,9 +12,8 @@ from homeassistant.components.velux import _LOGGER, DATA_VELUX DEPENDENCIES = ['velux'] -@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 the scenes for velux platform.""" entities = [] for scene in hass.data[DATA_VELUX].pyvlx.scenes: @@ -36,7 +34,6 @@ class VeluxScene(Scene): """Return the name of the scene.""" return self.scene.name - @asyncio.coroutine - def async_activate(self): + async def async_activate(self): """Activate the scene.""" - yield from self.scene.run() + await self.scene.run() diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 92b874cf2c8..e0bf3c86b05 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -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 https://home-assistant.io/components/sensor/ """ -import asyncio + from datetime import timedelta import logging @@ -20,11 +20,10 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}' SCAN_INTERVAL = timedelta(seconds=30) -@asyncio.coroutine -def async_setup(hass, config): +async def async_setup(hass, config): """Track states and offer events for sensors.""" component = EntityComponent( _LOGGER, DOMAIN, hass, SCAN_INTERVAL) - yield from component.async_setup(config) + await component.async_setup(config) return True diff --git a/homeassistant/components/sensor/knx.py b/homeassistant/components/sensor/knx.py index bdceb729e89..8eeb75fb0f1 100644 --- a/homeassistant/components/sensor/knx.py +++ b/homeassistant/components/sensor/knx.py @@ -4,7 +4,6 @@ Support for KNX/IP sensors. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/sensor.knx/ """ -import asyncio import voluptuous as vol @@ -28,8 +27,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 sensor(s) for KNX platform.""" if discovery_info is not None: async_add_devices_discovery(hass, discovery_info, async_add_devices) @@ -72,11 +71,10 @@ class KNXSensor(Entity): @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 diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index 66a416c5bea..9a35198628a 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -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, diff --git a/homeassistant/components/switch/knx.py b/homeassistant/components/switch/knx.py index 86a9adf0495..a96f96a9c5c 100644 --- a/homeassistant/components/switch/knx.py +++ b/homeassistant/components/switch/knx.py @@ -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() diff --git a/homeassistant/components/velux.py b/homeassistant/components/velux.py index ad541ee9cfe..47daf17f2a9 100644 --- a/homeassistant/components/velux.py +++ b/homeassistant/components/velux.py @@ -5,7 +5,6 @@ For more details about this component, please refer to the documentation at https://home-assistant.io/components/velux/ """ import logging -import asyncio import voluptuous as vol @@ -28,13 +27,12 @@ CONFIG_SCHEMA = vol.Schema({ }, extra=vol.ALLOW_EXTRA) -@asyncio.coroutine -def async_setup(hass, config): +async def async_setup(hass, config): """Set up the velux component.""" from pyvlx import PyVLXException try: 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: _LOGGER.exception("Can't connect to velux interface: %s", ex) @@ -58,7 +56,6 @@ class VeluxModule: host=host, password=password) - @asyncio.coroutine - def async_start(self): + async def async_start(self): """Start velux component.""" - yield from self.pyvlx.load_scenes() + await self.pyvlx.load_scenes()