Async syntax 5, light & lock & remote & scene & telegram & helpers (#17019)
This commit is contained in:
parent
9e4c8f45d6
commit
3b5e5cbcd6
28 changed files with 112 additions and 195 deletions
|
@ -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,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,8 +17,7 @@ DEPENDENCIES = ['insteon']
|
|||
MAX_BRIGHTNESS = 255
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
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,8 +18,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
DEPENDENCIES = ['lutron_caseta']
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Lutron Caseta lights."""
|
||||
devs = []
|
||||
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
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')
|
||||
|
|
|
@ -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,8 +48,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
})
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ Component to interface with various locks that can be controlled remotely.
|
|||
For more details about this component, please refer to the documentation
|
||||
at https://home-assistant.io/components/lock/
|
||||
"""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import functools as ft
|
||||
import logging
|
||||
|
@ -57,13 +56,12 @@ def is_locked(hass, entity_id=None):
|
|||
return hass.states.is_state(entity_id, STATE_LOCKED)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
async def async_setup(hass, config):
|
||||
"""Track states and offer events for locks."""
|
||||
component = EntityComponent(
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_LOCKS)
|
||||
|
||||
yield from component.async_setup(config)
|
||||
await component.async_setup(config)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_UNLOCK, LOCK_SERVICE_SCHEMA,
|
||||
|
|
|
@ -4,7 +4,6 @@ Support for BMW cars with BMW ConnectedDrive.
|
|||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/lock.bmw_connected_drive/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from homeassistant.components.bmw_connected_drive import DOMAIN as BMW_DOMAIN
|
||||
|
@ -111,8 +110,7 @@ class BMWLock(LockDevice):
|
|||
"""Schedule a state update."""
|
||||
self.schedule_update_ha_state(True)
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Add callback after being added to hass.
|
||||
|
||||
Show latest data after startup.
|
||||
|
|
|
@ -4,7 +4,6 @@ Support for MQTT locks.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/lock.mqtt/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -41,8 +40,7 @@ PLATFORM_SCHEMA = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({
|
|||
}).extend(mqtt.MQTT_AVAILABILITY_SCHEMA.schema)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the MQTT lock."""
|
||||
if discovery_info is not None:
|
||||
|
@ -96,11 +94,10 @@ class MqttLock(MqttAvailability, MqttDiscoveryUpdate, LockDevice):
|
|||
self._template = value_template
|
||||
self._discovery_hash = discovery_hash
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to MQTT events."""
|
||||
yield from MqttAvailability.async_added_to_hass(self)
|
||||
yield from MqttDiscoveryUpdate.async_added_to_hass(self)
|
||||
await MqttAvailability.async_added_to_hass(self)
|
||||
await MqttDiscoveryUpdate.async_added_to_hass(self)
|
||||
|
||||
@callback
|
||||
def message_received(topic, payload, qos):
|
||||
|
@ -119,7 +116,7 @@ class MqttLock(MqttAvailability, MqttDiscoveryUpdate, LockDevice):
|
|||
# Force into optimistic mode.
|
||||
self._optimistic = True
|
||||
else:
|
||||
yield from mqtt.async_subscribe(
|
||||
await mqtt.async_subscribe(
|
||||
self.hass, self._state_topic, message_received, self._qos)
|
||||
|
||||
@property
|
||||
|
@ -142,8 +139,7 @@ class MqttLock(MqttAvailability, MqttDiscoveryUpdate, LockDevice):
|
|||
"""Return true if we do optimistic updates."""
|
||||
return self._optimistic
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_lock(self, **kwargs):
|
||||
async def async_lock(self, **kwargs):
|
||||
"""Lock the device.
|
||||
|
||||
This method is a coroutine.
|
||||
|
@ -156,8 +152,7 @@ class MqttLock(MqttAvailability, MqttDiscoveryUpdate, LockDevice):
|
|||
self._state = True
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_unlock(self, **kwargs):
|
||||
async def async_unlock(self, **kwargs):
|
||||
"""Unlock the device.
|
||||
|
||||
This method is a coroutine.
|
||||
|
|
|
@ -4,7 +4,6 @@ Nuki.io lock platform.
|
|||
For more details about this platform, please refer to the documentation
|
||||
https://home-assistant.io/components/lock.nuki/
|
||||
"""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
|
@ -92,8 +91,7 @@ class NukiLock(LockDevice):
|
|||
self._name = nuki_lock.name
|
||||
self._battery_critical = nuki_lock.battery_critical
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Call when entity is added to hass."""
|
||||
if NUKI_DATA not in self.hass.data:
|
||||
self.hass.data[NUKI_DATA] = {}
|
||||
|
|
|
@ -4,7 +4,6 @@ Support for Wink locks.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/lock.wink/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -131,8 +130,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
class WinkLockDevice(WinkDevice, LockDevice):
|
||||
"""Representation of a Wink lock."""
|
||||
|
||||
@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']['lock'].append(self)
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ Z-Wave platform that handles simple door locks.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/lock.zwave/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -119,11 +118,10 @@ CLEAR_USERCODE_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Z-Wave Lock platform."""
|
||||
yield from zwave.async_setup_platform(
|
||||
await zwave.async_setup_platform(
|
||||
hass, config, async_add_entities, discovery_info)
|
||||
|
||||
network = hass.data[zwave.const.DATA_NETWORK]
|
||||
|
|
|
@ -4,7 +4,6 @@ Component to interface with universal remote control devices.
|
|||
For more details about this component, please refer to the documentation
|
||||
at https://home-assistant.io/components/remote/
|
||||
"""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import functools as ft
|
||||
import logging
|
||||
|
@ -70,12 +69,11 @@ def is_on(hass, entity_id=None):
|
|||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
async def async_setup(hass, config):
|
||||
"""Track states and offer events for remotes."""
|
||||
component = EntityComponent(
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_REMOTES)
|
||||
yield from component.async_setup(config)
|
||||
await component.async_setup(config)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_TURN_OFF, REMOTE_SERVICE_ACTIVITY_SCHEMA,
|
||||
|
|
|
@ -4,7 +4,6 @@ Remote control support for Apple TV.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/remote.apple_tv/
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
from homeassistant.components.apple_tv import (
|
||||
ATTR_ATV, ATTR_POWER, DATA_APPLE_TV)
|
||||
|
@ -15,8 +14,7 @@ from homeassistant.const import (CONF_NAME, CONF_HOST)
|
|||
DEPENDENCIES = ['apple_tv']
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Apple TV remote platform."""
|
||||
if not discovery_info:
|
||||
|
@ -59,16 +57,14 @@ class AppleTVRemote(remote.RemoteDevice):
|
|||
"""No polling needed for Apple TV."""
|
||||
return False
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the device on.
|
||||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
self._power.set_power_on(True)
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn the device off.
|
||||
|
||||
This method is a coroutine.
|
||||
|
@ -81,12 +77,11 @@ class AppleTVRemote(remote.RemoteDevice):
|
|||
This method must be run in the event loop and returns a coroutine.
|
||||
"""
|
||||
# Send commands in specified order but schedule only one coroutine
|
||||
@asyncio.coroutine
|
||||
def _send_commands():
|
||||
async def _send_commands():
|
||||
for single_command in command:
|
||||
if not hasattr(self._atv.remote_control, single_command):
|
||||
continue
|
||||
|
||||
yield from getattr(self._atv.remote_control, single_command)()
|
||||
await getattr(self._atv.remote_control, single_command)()
|
||||
|
||||
return _send_commands()
|
||||
|
|
|
@ -4,7 +4,6 @@ Support for Harmony Hub devices.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/remote.harmony/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
import time
|
||||
|
||||
|
@ -152,8 +151,7 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
pyharmony.ha_write_config_file(self._config, self._config_path)
|
||||
self._delay_secs = delay_secs
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Complete the initialization."""
|
||||
self.hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
|
|
|
@ -61,8 +61,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Xiaomi IR Remote (Chuangmi IR) platform."""
|
||||
from miio import ChuangmiIr, DeviceException
|
||||
|
@ -109,8 +108,7 @@ def async_setup_platform(hass, config, async_add_entities,
|
|||
|
||||
async_add_entities([xiaomi_miio_remote])
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_service_handler(service):
|
||||
async def async_service_handler(service):
|
||||
"""Handle a learn command."""
|
||||
if service.service != SERVICE_LEARN:
|
||||
_LOGGER.error("We should not handle service: %s", service.service)
|
||||
|
@ -130,14 +128,14 @@ def async_setup_platform(hass, config, async_add_entities,
|
|||
|
||||
slot = service.data.get(CONF_SLOT, entity.slot)
|
||||
|
||||
yield from hass.async_add_job(device.learn, slot)
|
||||
await hass.async_add_job(device.learn, slot)
|
||||
|
||||
timeout = service.data.get(CONF_TIMEOUT, entity.timeout)
|
||||
|
||||
_LOGGER.info("Press the key you want Home Assistant to learn")
|
||||
start_time = utcnow()
|
||||
while (utcnow() - start_time) < timedelta(seconds=timeout):
|
||||
message = yield from hass.async_add_job(
|
||||
message = await hass.async_add_job(
|
||||
device.read, slot)
|
||||
_LOGGER.debug("Message received from device: '%s'", message)
|
||||
|
||||
|
@ -150,9 +148,9 @@ def async_setup_platform(hass, config, async_add_entities,
|
|||
|
||||
if ('error' in message and
|
||||
message['error']['message'] == "learn timeout"):
|
||||
yield from hass.async_add_job(device.learn, slot)
|
||||
await hass.async_add_job(device.learn, slot)
|
||||
|
||||
yield from asyncio.sleep(1, loop=hass.loop)
|
||||
await asyncio.sleep(1, loop=hass.loop)
|
||||
|
||||
_LOGGER.error("Timeout. No infrared command captured")
|
||||
hass.components.persistent_notification.async_create(
|
||||
|
@ -230,14 +228,12 @@ class XiaomiMiioRemote(RemoteDevice):
|
|||
return {'hidden': 'true'}
|
||||
return
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
_LOGGER.error("Device does not support turn_on, "
|
||||
"please use 'remote.send_command' to send commands.")
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
_LOGGER.error("Device does not support turn_off, "
|
||||
"please use 'remote.send_command' to send commands.")
|
||||
|
|
|
@ -4,7 +4,6 @@ Allow users to set and activate scenes.
|
|||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/scene/
|
||||
"""
|
||||
import asyncio
|
||||
from collections import namedtuple
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -35,8 +34,7 @@ PLATFORM_SCHEMA = vol.Schema({
|
|||
SCENECONFIG = namedtuple('SceneConfig', [CONF_NAME, STATES])
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up home assistant scene entries."""
|
||||
scene_config = config.get(STATES)
|
||||
|
@ -97,8 +95,7 @@ class HomeAssistantScene(Scene):
|
|||
ATTR_ENTITY_ID: list(self.scene_config.states.keys()),
|
||||
}
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_activate(self):
|
||||
async def async_activate(self):
|
||||
"""Activate scene. Try to get entities into requested state."""
|
||||
yield from async_reproduce_state(
|
||||
await async_reproduce_state(
|
||||
self.hass, self.scene_config.states.values(), True)
|
||||
|
|
|
@ -4,7 +4,6 @@ Support for Powerview scenes from a Powerview hub.
|
|||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/scene.hunterdouglas_powerview/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -36,8 +35,7 @@ ROOM_ID_IN_SCENE = 'roomId'
|
|||
STATE_ATTRIBUTE_ROOM_NAME = 'roomName'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up home assistant scene entries."""
|
||||
# from aiopvapi.hub import Hub
|
||||
|
@ -48,9 +46,9 @@ def async_setup_platform(hass, config, async_add_entities,
|
|||
hub_address = config.get(HUB_ADDRESS)
|
||||
websession = async_get_clientsession(hass)
|
||||
|
||||
_scenes = yield from Scenes(
|
||||
_scenes = await Scenes(
|
||||
hub_address, hass.loop, websession).get_resources()
|
||||
_rooms = yield from Rooms(
|
||||
_rooms = await Rooms(
|
||||
hub_address, hass.loop, websession).get_resources()
|
||||
|
||||
if not _scenes or not _rooms:
|
||||
|
|
|
@ -29,8 +29,7 @@ PLATFORM_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the scenes stored in the LIFX Cloud."""
|
||||
token = config.get(CONF_TOKEN)
|
||||
|
@ -45,7 +44,7 @@ def async_setup_platform(hass, config, async_add_entities,
|
|||
try:
|
||||
httpsession = async_get_clientsession(hass)
|
||||
with async_timeout.timeout(timeout, loop=hass.loop):
|
||||
scenes_resp = yield from httpsession.get(url, headers=headers)
|
||||
scenes_resp = await httpsession.get(url, headers=headers)
|
||||
|
||||
except (asyncio.TimeoutError, aiohttp.ClientError):
|
||||
_LOGGER.exception("Error on %s", url)
|
||||
|
@ -53,7 +52,7 @@ def async_setup_platform(hass, config, async_add_entities,
|
|||
|
||||
status = scenes_resp.status
|
||||
if status == 200:
|
||||
data = yield from scenes_resp.json()
|
||||
data = await scenes_resp.json()
|
||||
devices = []
|
||||
for scene in data:
|
||||
devices.append(LifxCloudScene(hass, headers, timeout, scene))
|
||||
|
@ -83,15 +82,14 @@ class LifxCloudScene(Scene):
|
|||
"""Return the name of the scene."""
|
||||
return self._name
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_activate(self):
|
||||
async def async_activate(self):
|
||||
"""Activate the scene."""
|
||||
url = LIFX_API_URL.format('scenes/scene_id:%s/activate' % self._uuid)
|
||||
|
||||
try:
|
||||
httpsession = async_get_clientsession(self.hass)
|
||||
with async_timeout.timeout(self._timeout, loop=self.hass.loop):
|
||||
yield from httpsession.put(url, headers=self._headers)
|
||||
await httpsession.put(url, headers=self._headers)
|
||||
|
||||
except (asyncio.TimeoutError, aiohttp.ClientError):
|
||||
_LOGGER.exception("Error on %s", url)
|
||||
|
|
|
@ -4,7 +4,6 @@ Support for Lutron Caseta scenes.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/scene.lutron_caseta/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from homeassistant.components.lutron_caseta import LUTRON_CASETA_SMARTBRIDGE
|
||||
|
@ -15,8 +14,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
DEPENDENCIES = ['lutron_caseta']
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Lutron Caseta lights."""
|
||||
devs = []
|
||||
|
@ -43,7 +41,6 @@ class LutronCasetaScene(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."""
|
||||
self._bridge.activate_scene(self._scene_id)
|
||||
|
|
|
@ -4,7 +4,6 @@ Support for Wink scenes.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/scene.wink/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from homeassistant.components.scene import Scene
|
||||
|
@ -33,8 +32,7 @@ class WinkScene(WinkDevice, Scene):
|
|||
super().__init__(wink, hass)
|
||||
hass.data[DOMAIN]['entities']['scene'].append(self)
|
||||
|
||||
@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']['scene'].append(self)
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ Component to send and receive Telegram messages.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/telegram_bot/
|
||||
"""
|
||||
import asyncio
|
||||
import io
|
||||
from functools import partial
|
||||
import logging
|
||||
|
@ -210,8 +209,7 @@ def load_data(hass, url=None, filepath=None, username=None, password=None,
|
|||
return None
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the Telegram bot component."""
|
||||
if not config[DOMAIN]:
|
||||
return False
|
||||
|
@ -220,7 +218,7 @@ def async_setup(hass, config):
|
|||
|
||||
p_type = p_config.get(CONF_PLATFORM)
|
||||
|
||||
platform = yield from async_prepare_setup_platform(
|
||||
platform = await async_prepare_setup_platform(
|
||||
hass, config, DOMAIN, p_type)
|
||||
|
||||
if platform is None:
|
||||
|
@ -228,7 +226,7 @@ def async_setup(hass, config):
|
|||
|
||||
_LOGGER.info("Setting up %s.%s", DOMAIN, p_type)
|
||||
try:
|
||||
receiver_service = yield from \
|
||||
receiver_service = await \
|
||||
platform.async_setup_platform(hass, p_config)
|
||||
if receiver_service is False:
|
||||
_LOGGER.error(
|
||||
|
@ -247,8 +245,7 @@ def async_setup(hass, config):
|
|||
p_config.get(ATTR_PARSER)
|
||||
)
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_send_telegram_message(service):
|
||||
async def async_send_telegram_message(service):
|
||||
"""Handle sending Telegram Bot message service calls."""
|
||||
def _render_template_attr(data, attribute):
|
||||
attribute_templ = data.get(attribute)
|
||||
|
@ -274,23 +271,23 @@ def async_setup(hass, config):
|
|||
_LOGGER.debug("New telegram message %s: %s", msgtype, kwargs)
|
||||
|
||||
if msgtype == SERVICE_SEND_MESSAGE:
|
||||
yield from hass.async_add_job(
|
||||
await hass.async_add_job(
|
||||
partial(notify_service.send_message, **kwargs))
|
||||
elif msgtype in [SERVICE_SEND_PHOTO, SERVICE_SEND_STICKER,
|
||||
SERVICE_SEND_VIDEO, SERVICE_SEND_DOCUMENT]:
|
||||
yield from hass.async_add_job(
|
||||
await hass.async_add_job(
|
||||
partial(notify_service.send_file, msgtype, **kwargs))
|
||||
elif msgtype == SERVICE_SEND_LOCATION:
|
||||
yield from hass.async_add_job(
|
||||
await hass.async_add_job(
|
||||
partial(notify_service.send_location, **kwargs))
|
||||
elif msgtype == SERVICE_ANSWER_CALLBACK_QUERY:
|
||||
yield from hass.async_add_job(
|
||||
await hass.async_add_job(
|
||||
partial(notify_service.answer_callback_query, **kwargs))
|
||||
elif msgtype == SERVICE_DELETE_MESSAGE:
|
||||
yield from hass.async_add_job(
|
||||
await hass.async_add_job(
|
||||
partial(notify_service.delete_message, **kwargs))
|
||||
else:
|
||||
yield from hass.async_add_job(
|
||||
await hass.async_add_job(
|
||||
partial(notify_service.edit_message, msgtype, **kwargs))
|
||||
|
||||
# Register notification services
|
||||
|
|
|
@ -4,7 +4,6 @@ Telegram bot implementation to send messages only.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/telegram_bot.broadcast/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from homeassistant.components.telegram_bot import (
|
||||
|
@ -16,14 +15,13 @@ _LOGGER = logging.getLogger(__name__)
|
|||
PLATFORM_SCHEMA = TELEGRAM_PLATFORM_SCHEMA
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config):
|
||||
async def async_setup_platform(hass, config):
|
||||
"""Set up the Telegram broadcast platform."""
|
||||
# Check the API key works
|
||||
|
||||
bot = initialize_bot(config)
|
||||
|
||||
bot_config = yield from hass.async_add_job(bot.getMe)
|
||||
bot_config = await hass.async_add_job(bot.getMe)
|
||||
_LOGGER.debug("Telegram broadcast platform setup with bot %s",
|
||||
bot_config['username'])
|
||||
return True
|
||||
|
|
|
@ -4,7 +4,6 @@ Telegram bot polling implementation.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/telegram_bot.polling/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from homeassistant.components.telegram_bot import (
|
||||
|
@ -20,8 +19,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
PLATFORM_SCHEMA = TELEGRAM_PLATFORM_SCHEMA
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config):
|
||||
async def async_setup_platform(hass, config):
|
||||
"""Set up the Telegram polling platform."""
|
||||
bot = initialize_bot(config)
|
||||
pol = TelegramPoll(bot, hass, config[CONF_ALLOWED_CHAT_IDS])
|
||||
|
|
|
@ -4,7 +4,6 @@ Allows utilizing telegram webhooks.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/telegram_bot.webhooks/
|
||||
"""
|
||||
import asyncio
|
||||
import datetime as dt
|
||||
from ipaddress import ip_network
|
||||
import logging
|
||||
|
@ -47,13 +46,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
})
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config):
|
||||
async def async_setup_platform(hass, config):
|
||||
"""Set up the Telegram webhooks platform."""
|
||||
import telegram
|
||||
bot = initialize_bot(config)
|
||||
|
||||
current_status = yield from hass.async_add_job(bot.getWebhookInfo)
|
||||
current_status = await hass.async_add_job(bot.getWebhookInfo)
|
||||
base_url = config.get(CONF_URL, hass.config.api.base_url)
|
||||
|
||||
# Some logging of Bot current status:
|
||||
|
@ -81,7 +79,7 @@ def async_setup_platform(hass, config):
|
|||
retry_num)
|
||||
|
||||
if current_status and current_status['url'] != handler_url:
|
||||
result = yield from hass.async_add_job(_try_to_set_webhook)
|
||||
result = await hass.async_add_job(_try_to_set_webhook)
|
||||
if result:
|
||||
_LOGGER.info("Set new telegram webhook %s", handler_url)
|
||||
else:
|
||||
|
@ -108,8 +106,7 @@ class BotPushReceiver(HomeAssistantView, BaseTelegramBotEntity):
|
|||
BaseTelegramBotEntity.__init__(self, hass, allowed_chat_ids)
|
||||
self.trusted_networks = trusted_networks
|
||||
|
||||
@asyncio.coroutine
|
||||
def post(self, request):
|
||||
async def post(self, request):
|
||||
"""Accept the POST from telegram."""
|
||||
real_ip = request[KEY_REAL_IP]
|
||||
if not any(real_ip in net for net in self.trusted_networks):
|
||||
|
@ -117,7 +114,7 @@ class BotPushReceiver(HomeAssistantView, BaseTelegramBotEntity):
|
|||
return self.json_message('Access denied', HTTP_UNAUTHORIZED)
|
||||
|
||||
try:
|
||||
data = yield from request.json()
|
||||
data = await request.json()
|
||||
except ValueError:
|
||||
return self.json_message('Invalid JSON', HTTP_BAD_REQUEST)
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""An abstract class for entities."""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import functools as ft
|
||||
|
@ -202,8 +201,7 @@ class Entity:
|
|||
self._context = context
|
||||
self._context_set = dt_util.utcnow()
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_update_ha_state(self, force_refresh=False):
|
||||
async def async_update_ha_state(self, force_refresh=False):
|
||||
"""Update Home Assistant with current state of entity.
|
||||
|
||||
If force_refresh == True will update entity before setting state.
|
||||
|
@ -220,7 +218,7 @@ class Entity:
|
|||
# update entity data
|
||||
if force_refresh:
|
||||
try:
|
||||
yield from self.async_device_update()
|
||||
await self.async_device_update()
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Update for %s fails", self.entity_id)
|
||||
return
|
||||
|
@ -323,8 +321,7 @@ class Entity:
|
|||
"""Schedule an update ha state change task."""
|
||||
self.hass.async_add_job(self.async_update_ha_state(force_refresh))
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_device_update(self, warning=True):
|
||||
async def async_device_update(self, warning=True):
|
||||
"""Process 'update' or 'async_update' from entity.
|
||||
|
||||
This method is a coroutine.
|
||||
|
@ -335,7 +332,7 @@ class Entity:
|
|||
|
||||
# Process update sequential
|
||||
if self.parallel_updates:
|
||||
yield from self.parallel_updates.acquire()
|
||||
await self.parallel_updates.acquire()
|
||||
|
||||
if warning:
|
||||
update_warn = self.hass.loop.call_later(
|
||||
|
@ -347,9 +344,9 @@ class Entity:
|
|||
try:
|
||||
# pylint: disable=no-member
|
||||
if hasattr(self, 'async_update'):
|
||||
yield from self.async_update()
|
||||
await self.async_update()
|
||||
elif hasattr(self, 'update'):
|
||||
yield from self.hass.async_add_job(self.update)
|
||||
await self.hass.async_add_job(self.update)
|
||||
finally:
|
||||
self._update_staged = False
|
||||
if warning:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue