deConz rewrite to use async await syntax (#13151)
* Rewrite to use async await syntax * Fix hound commentpull/13132/head^2
parent
53351423dd
commit
8a1687accb
|
@ -4,8 +4,6 @@ Support for deCONZ binary sensor.
|
|||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/binary_sensor.deconz/
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.components.deconz import (
|
||||
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID)
|
||||
|
@ -15,8 +13,8 @@ from homeassistant.core import callback
|
|||
DEPENDENCIES = ['deconz']
|
||||
|
||||
|
||||
@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 deCONZ binary sensor."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
@ -39,8 +37,7 @@ class DeconzBinarySensor(BinarySensorDevice):
|
|||
"""Set up sensor and add update callback to get data from websocket."""
|
||||
self._sensor = sensor
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe sensors events."""
|
||||
self._sensor.register_async_callback(self.async_update_callback)
|
||||
self.hass.data[DATA_DECONZ_ID][self.entity_id] = self._sensor.deconz_id
|
||||
|
|
|
@ -4,8 +4,6 @@ Support for deCONZ devices.
|
|||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/deconz/
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -19,7 +17,7 @@ from homeassistant.helpers import discovery
|
|||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.util.json import load_json, save_json
|
||||
|
||||
REQUIREMENTS = ['pydeconz==30']
|
||||
REQUIREMENTS = ['pydeconz==31']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -57,30 +55,28 @@ Unlock your deCONZ gateway to register with Home Assistant.
|
|||
"""
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
async def async_setup(hass, config):
|
||||
"""Set up services and configuration for deCONZ component."""
|
||||
result = False
|
||||
config_file = yield from hass.async_add_job(
|
||||
config_file = await hass.async_add_job(
|
||||
load_json, hass.config.path(CONFIG_FILE))
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_deconz_discovered(service, discovery_info):
|
||||
async def async_deconz_discovered(service, discovery_info):
|
||||
"""Call when deCONZ gateway has been found."""
|
||||
deconz_config = {}
|
||||
deconz_config[CONF_HOST] = discovery_info.get(CONF_HOST)
|
||||
deconz_config[CONF_PORT] = discovery_info.get(CONF_PORT)
|
||||
yield from async_request_configuration(hass, config, deconz_config)
|
||||
await async_request_configuration(hass, config, deconz_config)
|
||||
|
||||
if config_file:
|
||||
result = yield from async_setup_deconz(hass, config, config_file)
|
||||
result = await async_setup_deconz(hass, config, config_file)
|
||||
|
||||
if not result and DOMAIN in config and CONF_HOST in config[DOMAIN]:
|
||||
deconz_config = config[DOMAIN]
|
||||
if CONF_API_KEY in deconz_config:
|
||||
result = yield from async_setup_deconz(hass, config, deconz_config)
|
||||
result = await async_setup_deconz(hass, config, deconz_config)
|
||||
else:
|
||||
yield from async_request_configuration(hass, config, deconz_config)
|
||||
await async_request_configuration(hass, config, deconz_config)
|
||||
return True
|
||||
|
||||
if not result:
|
||||
|
@ -89,8 +85,7 @@ def async_setup(hass, config):
|
|||
return True
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_deconz(hass, config, deconz_config):
|
||||
async def async_setup_deconz(hass, config, deconz_config):
|
||||
"""Set up a deCONZ session.
|
||||
|
||||
Load config, group, light and sensor data for server information.
|
||||
|
@ -100,7 +95,7 @@ def async_setup_deconz(hass, config, deconz_config):
|
|||
from pydeconz import DeconzSession
|
||||
websession = async_get_clientsession(hass)
|
||||
deconz = DeconzSession(hass.loop, websession, **deconz_config)
|
||||
result = yield from deconz.async_load_parameters()
|
||||
result = await deconz.async_load_parameters()
|
||||
if result is False:
|
||||
_LOGGER.error("Failed to communicate with deCONZ")
|
||||
return False
|
||||
|
@ -113,8 +108,7 @@ def async_setup_deconz(hass, config, deconz_config):
|
|||
hass, component, DOMAIN, {}, config))
|
||||
deconz.start()
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_configure(call):
|
||||
async def async_configure(call):
|
||||
"""Set attribute of device in deCONZ.
|
||||
|
||||
Field is a string representing a specific device in deCONZ
|
||||
|
@ -140,7 +134,7 @@ def async_setup_deconz(hass, config, deconz_config):
|
|||
if field is None:
|
||||
_LOGGER.error('Could not find the entity %s', entity_id)
|
||||
return
|
||||
yield from deconz.async_put_state(field, data)
|
||||
await deconz.async_put_state(field, data)
|
||||
hass.services.async_register(
|
||||
DOMAIN, 'configure', async_configure, schema=SERVICE_SCHEMA)
|
||||
|
||||
|
@ -159,21 +153,19 @@ def async_setup_deconz(hass, config, deconz_config):
|
|||
return True
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_request_configuration(hass, config, deconz_config):
|
||||
async def async_request_configuration(hass, config, deconz_config):
|
||||
"""Request configuration steps from the user."""
|
||||
configurator = hass.components.configurator
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_configuration_callback(data):
|
||||
async def async_configuration_callback(data):
|
||||
"""Set up actions to do when our configuration callback is called."""
|
||||
from pydeconz.utils import async_get_api_key
|
||||
api_key = yield from async_get_api_key(hass.loop, **deconz_config)
|
||||
api_key = await async_get_api_key(hass.loop, **deconz_config)
|
||||
if api_key:
|
||||
deconz_config[CONF_API_KEY] = api_key
|
||||
result = yield from async_setup_deconz(hass, config, deconz_config)
|
||||
result = await async_setup_deconz(hass, config, deconz_config)
|
||||
if result:
|
||||
yield from hass.async_add_job(
|
||||
await hass.async_add_job(
|
||||
save_json, hass.config.path(CONFIG_FILE), deconz_config)
|
||||
configurator.async_request_done(request_id)
|
||||
return
|
||||
|
|
|
@ -4,8 +4,6 @@ Support for deCONZ light.
|
|||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/light.deconz/
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
from homeassistant.components.deconz import (
|
||||
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID)
|
||||
from homeassistant.components.light import (
|
||||
|
@ -19,8 +17,8 @@ from homeassistant.util.color import color_RGB_to_xy
|
|||
DEPENDENCIES = ['deconz']
|
||||
|
||||
|
||||
@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 deCONZ light."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
@ -59,8 +57,7 @@ class DeconzLight(Light):
|
|||
if self._light.effect is not None:
|
||||
self._features |= SUPPORT_EFFECT
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to lights events."""
|
||||
self._light.register_async_callback(self.async_update_callback)
|
||||
self.hass.data[DATA_DECONZ_ID][self.entity_id] = self._light.deconz_id
|
||||
|
@ -120,8 +117,7 @@ class DeconzLight(Light):
|
|||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn on light."""
|
||||
data = {'on': True}
|
||||
|
||||
|
@ -157,10 +153,9 @@ class DeconzLight(Light):
|
|||
else:
|
||||
data['effect'] = 'none'
|
||||
|
||||
yield from self._light.async_set_state(data)
|
||||
await self._light.async_set_state(data)
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn off light."""
|
||||
data = {'on': False}
|
||||
|
||||
|
@ -176,4 +171,4 @@ class DeconzLight(Light):
|
|||
data['alert'] = 'lselect'
|
||||
del data['on']
|
||||
|
||||
yield from self._light.async_set_state(data)
|
||||
await self._light.async_set_state(data)
|
||||
|
|
|
@ -4,8 +4,6 @@ Support for deCONZ scenes.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/scene.deconz/
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
from homeassistant.components.deconz import (
|
||||
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID)
|
||||
from homeassistant.components.scene import Scene
|
||||
|
@ -13,8 +11,8 @@ from homeassistant.components.scene import Scene
|
|||
DEPENDENCIES = ['deconz']
|
||||
|
||||
|
||||
@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 scenes for deCONZ component."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
@ -34,15 +32,13 @@ class DeconzScene(Scene):
|
|||
"""Set up a scene."""
|
||||
self._scene = scene
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to sensors events."""
|
||||
self.hass.data[DATA_DECONZ_ID][self.entity_id] = self._scene.deconz_id
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_activate(self):
|
||||
async def async_activate(self):
|
||||
"""Activate the scene."""
|
||||
yield from self._scene.async_set_state({})
|
||||
await self._scene.async_set_state({})
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -4,8 +4,6 @@ Support for deCONZ sensor.
|
|||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.deconz/
|
||||
"""
|
||||
import asyncio
|
||||
|
||||
from homeassistant.components.deconz import (
|
||||
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID)
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL, CONF_EVENT, CONF_ID
|
||||
|
@ -19,8 +17,8 @@ DEPENDENCIES = ['deconz']
|
|||
ATTR_EVENT_ID = 'event_id'
|
||||
|
||||
|
||||
@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 deCONZ sensors."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
@ -48,8 +46,7 @@ class DeconzSensor(Entity):
|
|||
"""Set up sensor and add update callback to get data from websocket."""
|
||||
self._sensor = sensor
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to sensors events."""
|
||||
self._sensor.register_async_callback(self.async_update_callback)
|
||||
self.hass.data[DATA_DECONZ_ID][self.entity_id] = self._sensor.deconz_id
|
||||
|
@ -125,8 +122,7 @@ class DeconzBattery(Entity):
|
|||
self._device_class = 'battery'
|
||||
self._unit_of_measurement = "%"
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to sensors events."""
|
||||
self._device.register_async_callback(self.async_update_callback)
|
||||
self.hass.data[DATA_DECONZ_ID][self.entity_id] = self._device.deconz_id
|
||||
|
|
|
@ -701,7 +701,7 @@ pycsspeechtts==1.0.2
|
|||
pydaikin==0.4
|
||||
|
||||
# homeassistant.components.deconz
|
||||
pydeconz==30
|
||||
pydeconz==31
|
||||
|
||||
# homeassistant.components.zwave
|
||||
pydispatcher==2.0.5
|
||||
|
|
Loading…
Reference in New Issue