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
@@ -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
|
||||
|
||||
@@ -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()
|
||||
Reference in new issue
Block a user