diff --git a/homeassistant/components/lcn/__init__.py b/homeassistant/components/lcn/__init__.py index 418b6ffa89d..7e7fb1430cc 100644 --- a/homeassistant/components/lcn/__init__.py +++ b/homeassistant/components/lcn/__init__.py @@ -1,6 +1,8 @@ """Support for LCN devices.""" import logging +import pypck +from pypck.connection import PchkConnectionManager import voluptuous as vol from homeassistant.const import ( @@ -149,9 +151,6 @@ def get_connection(connections, connection_id=None): async def async_setup(hass, config): """Set up the LCN component.""" - import pypck - from pypck.connection import PchkConnectionManager - hass.data[DATA_LCN] = {} conf_connections = config[DOMAIN][CONF_CONNECTIONS] @@ -201,7 +200,6 @@ class LcnDevice(Entity): def __init__(self, config, address_connection): """Initialize the LCN device.""" - import pypck self.pypck = pypck self.config = config self.address_connection = address_connection diff --git a/homeassistant/components/lcn/binary_sensor.py b/homeassistant/components/lcn/binary_sensor.py index ec37d3e5128..a59494023bb 100755 --- a/homeassistant/components/lcn/binary_sensor.py +++ b/homeassistant/components/lcn/binary_sensor.py @@ -1,4 +1,6 @@ """Support for LCN binary sensors.""" +import pypck + from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.const import CONF_ADDRESS @@ -13,8 +15,6 @@ async def async_setup_platform(hass, hass_config, async_add_entities, if discovery_info is None: return - import pypck - devices = [] for config in discovery_info: address, connection_id = config[CONF_ADDRESS] @@ -50,9 +50,8 @@ class LcnRegulatorLockSensor(LcnDevice, BinarySensorDevice): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" await super().async_added_to_hass() - self.hass.async_create_task( - self.address_connection.activate_status_request_handler( - self.setpoint_variable)) + await self.address_connection.activate_status_request_handler( + self.setpoint_variable) @property def is_on(self): @@ -84,9 +83,8 @@ class LcnBinarySensor(LcnDevice, BinarySensorDevice): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" await super().async_added_to_hass() - self.hass.async_create_task( - self.address_connection.activate_status_request_handler( - self.bin_sensor_port)) + await self.address_connection.activate_status_request_handler( + self.bin_sensor_port) @property def is_on(self): @@ -115,9 +113,8 @@ class LcnLockKeysSensor(LcnDevice, BinarySensorDevice): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" await super().async_added_to_hass() - self.hass.async_create_task( - self.address_connection.activate_status_request_handler( - self.source)) + await self.address_connection.activate_status_request_handler( + self.source) @property def is_on(self): diff --git a/homeassistant/components/lcn/cover.py b/homeassistant/components/lcn/cover.py index 7123f2d5d0a..d07fa09c189 100755 --- a/homeassistant/components/lcn/cover.py +++ b/homeassistant/components/lcn/cover.py @@ -1,4 +1,6 @@ """Support for LCN covers.""" +import pypck + from homeassistant.components.cover import CoverDevice from homeassistant.const import CONF_ADDRESS @@ -12,8 +14,6 @@ async def async_setup_platform(hass, hass_config, async_add_entities, if discovery_info is None: return - import pypck - devices = [] for config in discovery_info: address, connection_id = config[CONF_ADDRESS] @@ -43,9 +43,8 @@ class LcnCover(LcnDevice, CoverDevice): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" await super().async_added_to_hass() - self.hass.async_create_task( - self.address_connection.activate_status_request_handler( - self.motor)) + await self.address_connection.activate_status_request_handler( + self.motor) @property def is_closed(self): diff --git a/homeassistant/components/lcn/light.py b/homeassistant/components/lcn/light.py index 653873ba78a..49cdff5de49 100644 --- a/homeassistant/components/lcn/light.py +++ b/homeassistant/components/lcn/light.py @@ -1,4 +1,6 @@ """Support for LCN lights.""" +import pypck + from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_TRANSITION, SUPPORT_BRIGHTNESS, SUPPORT_TRANSITION, Light) @@ -16,8 +18,6 @@ async def async_setup_platform( if discovery_info is None: return - import pypck - devices = [] for config in discovery_info: address, connection_id = config[CONF_ADDRESS] @@ -56,9 +56,8 @@ class LcnOutputLight(LcnDevice, Light): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" await super().async_added_to_hass() - self.hass.async_create_task( - self.address_connection.activate_status_request_handler( - self.output)) + await self.address_connection.activate_status_request_handler( + self.output) @property def supported_features(self): @@ -138,9 +137,8 @@ class LcnRelayLight(LcnDevice, Light): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" await super().async_added_to_hass() - self.hass.async_create_task( - self.address_connection.activate_status_request_handler( - self.output)) + await self.address_connection.activate_status_request_handler( + self.output) @property def is_on(self): diff --git a/homeassistant/components/lcn/sensor.py b/homeassistant/components/lcn/sensor.py index 48ac8c7266c..38b17c80793 100755 --- a/homeassistant/components/lcn/sensor.py +++ b/homeassistant/components/lcn/sensor.py @@ -1,4 +1,6 @@ """Support for LCN sensors.""" +import pypck + from homeassistant.const import CONF_ADDRESS, CONF_UNIT_OF_MEASUREMENT from . import LcnDevice, get_connection @@ -13,8 +15,6 @@ async def async_setup_platform(hass, hass_config, async_add_entities, if discovery_info is None: return - import pypck - devices = [] for config in discovery_info: address, connection_id = config[CONF_ADDRESS] @@ -50,9 +50,8 @@ class LcnVariableSensor(LcnDevice): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" await super().async_added_to_hass() - self.hass.async_create_task( - self.address_connection.activate_status_request_handler( - self.variable)) + await self.address_connection.activate_status_request_handler( + self.variable) @property def state(self): @@ -91,9 +90,8 @@ class LcnLedLogicSensor(LcnDevice): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" await super().async_added_to_hass() - self.hass.async_create_task( - self.address_connection.activate_status_request_handler( - self.source)) + await self.address_connection.activate_status_request_handler( + self.source) @property def state(self): diff --git a/homeassistant/components/lcn/switch.py b/homeassistant/components/lcn/switch.py index 48ae579fbcd..e5a8484e271 100755 --- a/homeassistant/components/lcn/switch.py +++ b/homeassistant/components/lcn/switch.py @@ -1,4 +1,6 @@ """Support for LCN switches.""" +import pypck + from homeassistant.components.switch import SwitchDevice from homeassistant.const import CONF_ADDRESS @@ -12,8 +14,6 @@ async def async_setup_platform(hass, hass_config, async_add_entities, if discovery_info is None: return - import pypck - devices = [] for config in discovery_info: address, connection_id = config[CONF_ADDRESS] @@ -46,9 +46,8 @@ class LcnOutputSwitch(LcnDevice, SwitchDevice): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" await super().async_added_to_hass() - self.hass.async_create_task( - self.address_connection.activate_status_request_handler( - self.output)) + await self.address_connection.activate_status_request_handler( + self.output) @property def is_on(self): @@ -91,9 +90,8 @@ class LcnRelaySwitch(LcnDevice, SwitchDevice): async def async_added_to_hass(self): """Run when entity about to be added to hass.""" await super().async_added_to_hass() - self.hass.async_create_task( - self.address_connection.activate_status_request_handler( - self.output)) + await self.address_connection.activate_status_request_handler( + self.output) @property def is_on(self):