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:
Julius Mittenzwei 2018-02-24 19:24:33 +01:00 committed by Paulus Schoutsen
parent c076b805e7
commit 3713dfe139
17 changed files with 140 additions and 199 deletions

View file

@ -4,7 +4,7 @@ Connects to KNX platform.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/knx/
"""
import asyncio
import logging
import voluptuous as vol
@ -66,13 +66,12 @@ SERVICE_KNX_SEND_SCHEMA = vol.Schema({
})
@asyncio.coroutine
def async_setup(hass, config):
async def async_setup(hass, config):
"""Set up the KNX component."""
from xknx.exceptions import XKNXException
try:
hass.data[DATA_KNX] = KNXModule(hass, config)
yield from hass.data[DATA_KNX].start()
await hass.data[DATA_KNX].start()
except XKNXException as ex:
_LOGGER.warning("Can't connect to KNX interface: %s", ex)
@ -128,20 +127,18 @@ class KNXModule(object):
from xknx import XKNX
self.xknx = XKNX(config=self.config_file(), loop=self.hass.loop)
@asyncio.coroutine
def start(self):
async def start(self):
"""Start KNX object. Connect to tunneling or Routing device."""
connection_config = self.connection_config()
yield from self.xknx.start(
await self.xknx.start(
state_updater=self.config[DOMAIN][CONF_KNX_STATE_UPDATER],
connection_config=connection_config)
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.stop)
self.connected = True
@asyncio.coroutine
def stop(self, event):
async def stop(self, event):
"""Stop KNX object. Disconnect from tunneling or Routing device."""
yield from self.xknx.stop()
await self.xknx.stop()
def config_file(self):
"""Resolve and return the full path of xknx.yaml if configured."""
@ -202,8 +199,7 @@ class KNXModule(object):
self.xknx.telegram_queue.register_telegram_received_cb(
self.telegram_received_cb, address_filters)
@asyncio.coroutine
def telegram_received_cb(self, telegram):
async def telegram_received_cb(self, telegram):
"""Call invoked after a KNX telegram was received."""
self.hass.bus.fire('knx_event', {
'address': telegram.group_address.str(),
@ -212,8 +208,7 @@ class KNXModule(object):
# False signals XKNX to proceed with processing telegrams.
return False
@asyncio.coroutine
def service_send_to_knx_bus(self, call):
async def service_send_to_knx_bus(self, call):
"""Service for sending an arbitrary KNX message to the KNX bus."""
from xknx.knx import Telegram, GroupAddress, DPTBinary, DPTArray
attr_payload = call.data.get(SERVICE_KNX_ATTR_PAYLOAD)
@ -230,7 +225,7 @@ class KNXModule(object):
telegram = Telegram()
telegram.payload = payload
telegram.group_address = address
yield from self.xknx.telegrams.put(telegram)
await self.xknx.telegrams.put(telegram)
class KNXAutomation():