Async syntax 5, light & lock & remote & scene & telegram & helpers (#17019)

This commit is contained in:
cdce8p authored and Paulus Schoutsen committed 2018-10-01 08:56:50 +02:00
1 parent 9e4c8f45d6
commit 3b5e5cbcd6
28 files changed
+112 -195

No files matched your search

+1 -3
View File
@@ -5,7 +5,6 @@ For more details about this platform, please refer to the documentation.
https://home-assistant.io/components/light.ads/
"""
import asyncio
import logging
import voluptuous as vol
from homeassistant.components.light import Light, ATTR_BRIGHTNESS, \
@@ -50,8 +49,7 @@ class AdsLight(Light):
self.ads_var_enable = ads_var_enable
self.ads_var_brightness = ads_var_brightness
@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Register device notification."""
def update_on_state(name, value):
"""Handle device notifications for state."""
+4 -8
View File
@@ -4,7 +4,6 @@ Support for Insteon lights via PowerLinc Modem.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/light.insteon/
"""
import asyncio
import logging
from homeassistant.components.insteon import InsteonEntity
@@ -18,9 +17,8 @@ DEPENDENCIES = ['insteon']
MAX_BRIGHTNESS = 255
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Insteon component."""
insteon_modem = hass.data['insteon'].get('modem')
@@ -55,8 +53,7 @@ class InsteonDimmerDevice(InsteonEntity, Light):
"""Flag supported features."""
return SUPPORT_BRIGHTNESS
@asyncio.coroutine
def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs):
"""Turn device on."""
if ATTR_BRIGHTNESS in kwargs:
brightness = int(kwargs[ATTR_BRIGHTNESS])
@@ -64,7 +61,6 @@ class InsteonDimmerDevice(InsteonEntity, Light):
else:
self._insteon_device_state.on()
@asyncio.coroutine
def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs):
"""Turn device off."""
self._insteon_device_state.off()
@@ -4,7 +4,6 @@ Support for LimitlessLED bulbs.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.limitlessled/
"""
import asyncio
import logging
import voluptuous as vol
@@ -188,10 +187,9 @@ class LimitlessLEDGroup(Light):
self._color = None
self._effect = None
@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Handle entity about to be added to hass event."""
last_state = yield from async_get_last_state(self.hass, self.entity_id)
last_state = await async_get_last_state(self.hass, self.entity_id)
if last_state:
self._is_on = (last_state.state == STATE_ON)
self._brightness = last_state.attributes.get('brightness')
@@ -4,7 +4,6 @@ Support for Lutron Caseta lights.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.lutron_caseta/
"""
import asyncio
import logging
from homeassistant.components.light import (
@@ -19,9 +18,8 @@ _LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['lutron_caseta']
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Lutron Caseta lights."""
devs = []
bridge = hass.data[LUTRON_CASETA_SMARTBRIDGE]
@@ -46,15 +44,13 @@ class LutronCasetaLight(LutronCasetaDevice, Light):
"""Return the brightness of the light."""
return to_hass_level(self._state["current_state"])
@asyncio.coroutine
def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs):
"""Turn the light on."""
brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
self._smartbridge.set_value(self._device_id,
to_lutron_level(brightness))
@asyncio.coroutine
def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs):
"""Turn the light off."""
self._smartbridge.set_value(self._device_id, 0)
@@ -63,8 +59,7 @@ class LutronCasetaLight(LutronCasetaDevice, Light):
"""Return true if device is on."""
return self._state["current_state"] > 0
@asyncio.coroutine
def async_update(self):
async def async_update(self):
"""Call when forcing a refresh of the device."""
self._state = self._smartbridge.get_device_by_id(self._device_id)
_LOGGER.debug(self._state)
+12 -19
View File
@@ -4,7 +4,6 @@ Support for Rflink lights.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.rflink/
"""
import asyncio
import logging
from homeassistant.components.light import (
@@ -155,14 +154,12 @@ def devices_from_config(domain_config, hass=None):
return devices
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Rflink light platform."""
async_add_entities(devices_from_config(config, hass))
@asyncio.coroutine
def add_new_device(event):
async def add_new_device(event):
"""Check if device is known, otherwise add to list of known devices."""
device_id = event[EVENT_KEY_ID]
@@ -195,15 +192,14 @@ class DimmableRflinkLight(SwitchableRflinkDevice, Light):
_brightness = 255
@asyncio.coroutine
def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs):
"""Turn the device on."""
if ATTR_BRIGHTNESS in kwargs:
# rflink only support 16 brightness levels
self._brightness = int(kwargs[ATTR_BRIGHTNESS] / 17) * 17
# Turn on light at the requested dim level
yield from self._async_handle_command('dim', self._brightness)
await self._async_handle_command('dim', self._brightness)
@property
def brightness(self):
@@ -233,8 +229,7 @@ class HybridRflinkLight(SwitchableRflinkDevice, Light):
_brightness = 255
@asyncio.coroutine
def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs):
"""Turn the device on and set dim level."""
if ATTR_BRIGHTNESS in kwargs:
# rflink only support 16 brightness levels
@@ -242,12 +237,12 @@ class HybridRflinkLight(SwitchableRflinkDevice, Light):
# if receiver supports dimming this will turn on the light
# at the requested dim level
yield from self._async_handle_command('dim', self._brightness)
await self._async_handle_command('dim', self._brightness)
# if the receiving device does not support dimlevel this
# will ensure it is turned on when full brightness is set
if self._brightness == 255:
yield from self._async_handle_command('turn_on')
await self._async_handle_command('turn_on')
@property
def brightness(self):
@@ -284,12 +279,10 @@ class ToggleRflinkLight(SwitchableRflinkDevice, Light):
# if the state is true, it gets set as false
self._state = self._state in [STATE_UNKNOWN, False]
@asyncio.coroutine
def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs):
"""Turn the device on."""
yield from self._async_handle_command('toggle')
await self._async_handle_command('toggle')
@asyncio.coroutine
def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs):
"""Turn the device off."""
yield from self._async_handle_command('toggle')
await self._async_handle_command('toggle')
+8 -14
View File
@@ -5,7 +5,6 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.template/
"""
import logging
import asyncio
import voluptuous as vol
@@ -49,9 +48,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Template Lights."""
lights = []
@@ -182,8 +180,7 @@ class LightTemplate(Light):
"""Return the entity picture to use in the frontend, if any."""
return self._entity_picture
@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Register callbacks."""
@callback
def template_light_state_listener(entity, old_state, new_state):
@@ -203,8 +200,7 @@ class LightTemplate(Light):
self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_START, template_light_startup)
@asyncio.coroutine
def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs):
"""Turn the light on."""
optimistic_set = False
# set optimistic states
@@ -222,21 +218,19 @@ class LightTemplate(Light):
self.hass.async_add_job(self._level_script.async_run(
{"brightness": kwargs[ATTR_BRIGHTNESS]}))
else:
yield from self._on_script.async_run()
await self._on_script.async_run()
if optimistic_set:
self.async_schedule_update_ha_state()
@asyncio.coroutine
def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs):
"""Turn the light off."""
yield from self._off_script.async_run()
await self._off_script.async_run()
if self._template is None:
self._state = False
self.async_schedule_update_ha_state()
@asyncio.coroutine
def async_update(self):
async def async_update(self):
"""Update the state from the template."""
if self._template is not None:
try:
+3 -5
View File
@@ -4,7 +4,6 @@ Support for Belkin WeMo lights.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/light.wemo/
"""
import asyncio
import logging
from datetime import timedelta
import requests
@@ -160,13 +159,12 @@ class WemoDimmer(Light):
self._brightness = None
self._state = None
@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Register update callback."""
wemo = self.hass.components.wemo
# The register method uses a threading condition, so call via executor.
# and yield from to wait until the task is done.
yield from self.hass.async_add_job(
# and await to wait until the task is done.
await self.hass.async_add_job(
wemo.SUBSCRIPTION_REGISTRY.register, self.wemo)
# The on method just appends to a defaultdict list.
wemo.SUBSCRIPTION_REGISTRY.on(self.wemo, None, self._update_callback)
+1 -3
View File
@@ -4,7 +4,6 @@ Support for Wink lights.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.wink/
"""
import asyncio
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS,
@@ -34,8 +33,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
class WinkLight(WinkDevice, Light):
"""Representation of a Wink light."""
@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Call when entity is added to hass."""
self.hass.data[DOMAIN]['entities']['light'].append(self)