Async syntax 5, light & lock & remote & scene & telegram & helpers (#17019)
This commit is contained in:
1 parent
9e4c8f45d6
commit
3b5e5cbcd6
28 files changed
+112
-195
No files matched your search
@@ -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,9 +34,8 @@ PLATFORM_SCHEMA = vol.Schema({
|
||||
SCENECONFIG = namedtuple('SceneConfig', [CONF_NAME, STATES])
|
||||
|
||||
|
||||
@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 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,9 +35,8 @@ ROOM_ID_IN_SCENE = 'roomId'
|
||||
STATE_ATTRIBUTE_ROOM_NAME = 'roomName'
|
||||
|
||||
|
||||
@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 home assistant scene entries."""
|
||||
# from aiopvapi.hub import Hub
|
||||
from aiopvapi.scenes import Scenes
|
||||
@@ -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,9 +29,8 @@ PLATFORM_SCHEMA = vol.Schema({
|
||||
})
|
||||
|
||||
|
||||
@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 scenes stored in the LIFX Cloud."""
|
||||
token = config.get(CONF_TOKEN)
|
||||
timeout = config.get(CONF_TIMEOUT)
|
||||
@@ -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,9 +14,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]
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user