diff --git a/homeassistant/components/binary_sensor/knx.py b/homeassistant/components/binary_sensor/knx.py index d0707b0f067..a89d5d1c945 100644 --- a/homeassistant/components/binary_sensor/knx.py +++ b/homeassistant/components/binary_sensor/knx.py @@ -69,7 +69,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities): entities = [] for device_name in discovery_info[ATTR_DISCOVER_DEVICES]: device = hass.data[DATA_KNX].xknx.devices[device_name] - entities.append(KNXBinarySensor(hass, device)) + entities.append(KNXBinarySensor(device)) async_add_entities(entities) @@ -87,7 +87,7 @@ def async_add_entities_config(hass, config, async_add_entities): reset_after=config.get(CONF_RESET_AFTER)) hass.data[DATA_KNX].xknx.devices.add(binary_sensor) - entity = KNXBinarySensor(hass, binary_sensor) + entity = KNXBinarySensor(binary_sensor) automations = config.get(CONF_AUTOMATION) if automations is not None: for automation in automations: @@ -103,11 +103,9 @@ def async_add_entities_config(hass, config, async_add_entities): class KNXBinarySensor(BinarySensorDevice): """Representation of a KNX binary sensor.""" - def __init__(self, hass, device): + def __init__(self, device): """Initialize of KNX binary sensor.""" self.device = device - self.hass = hass - self.async_register_callbacks() self.automations = [] @callback @@ -118,6 +116,10 @@ class KNXBinarySensor(BinarySensorDevice): await self.async_update_ha_state() self.device.register_device_updated_cb(after_update_callback) + async def async_added_to_hass(self): + """Store register state change callback.""" + self.async_register_callbacks() + @property def name(self): """Return the name of the KNX device.""" diff --git a/homeassistant/components/climate/knx.py b/homeassistant/components/climate/knx.py index 4eada356653..b52bd4b418d 100644 --- a/homeassistant/components/climate/knx.py +++ b/homeassistant/components/climate/knx.py @@ -75,7 +75,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities): entities = [] for device_name in discovery_info[ATTR_DISCOVER_DEVICES]: device = hass.data[DATA_KNX].xknx.devices[device_name] - entities.append(KNXClimate(hass, device)) + entities.append(KNXClimate(device)) async_add_entities(entities) @@ -110,17 +110,15 @@ def async_add_entities_config(hass, config, async_add_entities): group_address_operation_mode_comfort=config.get( CONF_OPERATION_MODE_COMFORT_ADDRESS)) hass.data[DATA_KNX].xknx.devices.add(climate) - async_add_entities([KNXClimate(hass, climate)]) + async_add_entities([KNXClimate(climate)]) class KNXClimate(ClimateDevice): """Representation of a KNX climate device.""" - def __init__(self, hass, device): + def __init__(self, device): """Initialize of a KNX climate device.""" self.device = device - self.hass = hass - self.async_register_callbacks() @property def supported_features(self): @@ -137,6 +135,10 @@ class KNXClimate(ClimateDevice): await self.async_update_ha_state() self.device.register_device_updated_cb(after_update_callback) + async def async_added_to_hass(self): + """Store register state change callback.""" + self.async_register_callbacks() + @property def name(self): """Return the name of the KNX device.""" diff --git a/homeassistant/components/cover/knx.py b/homeassistant/components/cover/knx.py index 43a87fab367..4173db5f450 100644 --- a/homeassistant/components/cover/knx.py +++ b/homeassistant/components/cover/knx.py @@ -64,7 +64,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities): entities = [] for device_name in discovery_info[ATTR_DISCOVER_DEVICES]: device = hass.data[DATA_KNX].xknx.devices[device_name] - entities.append(KNXCover(hass, device)) + entities.append(KNXCover(device)) async_add_entities(entities) @@ -88,18 +88,15 @@ def async_add_entities_config(hass, config, async_add_entities): invert_angle=config.get(CONF_INVERT_ANGLE)) hass.data[DATA_KNX].xknx.devices.add(cover) - async_add_entities([KNXCover(hass, cover)]) + async_add_entities([KNXCover(cover)]) class KNXCover(CoverDevice): """Representation of a KNX cover.""" - def __init__(self, hass, device): + def __init__(self, device): """Initialize the cover.""" self.device = device - self.hass = hass - self.async_register_callbacks() - self._unsubscribe_auto_updater = None @callback @@ -110,6 +107,10 @@ class KNXCover(CoverDevice): await self.async_update_ha_state() self.device.register_device_updated_cb(after_update_callback) + async def async_added_to_hass(self): + """Store register state change callback.""" + self.async_register_callbacks() + @property def name(self): """Return the name of the KNX device.""" diff --git a/homeassistant/components/light/knx.py b/homeassistant/components/light/knx.py index 778d2fac59c..a1423cc6682 100644 --- a/homeassistant/components/light/knx.py +++ b/homeassistant/components/light/knx.py @@ -52,7 +52,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities): entities = [] for device_name in discovery_info[ATTR_DISCOVER_DEVICES]: device = hass.data[DATA_KNX].xknx.devices[device_name] - entities.append(KNXLight(hass, device)) + entities.append(KNXLight(device)) async_add_entities(entities) @@ -71,17 +71,15 @@ def async_add_entities_config(hass, config, async_add_entities): group_address_color=config.get(CONF_COLOR_ADDRESS), group_address_color_state=config.get(CONF_COLOR_STATE_ADDRESS)) hass.data[DATA_KNX].xknx.devices.add(light) - async_add_entities([KNXLight(hass, light)]) + async_add_entities([KNXLight(light)]) class KNXLight(Light): """Representation of a KNX light.""" - def __init__(self, hass, device): + def __init__(self, device): """Initialize of KNX light.""" self.device = device - self.hass = hass - self.async_register_callbacks() @callback def async_register_callbacks(self): @@ -91,6 +89,10 @@ class KNXLight(Light): await self.async_update_ha_state() self.device.register_device_updated_cb(after_update_callback) + async def async_added_to_hass(self): + """Store register state change callback.""" + self.async_register_callbacks() + @property def name(self): """Return the name of the KNX device.""" diff --git a/homeassistant/components/sensor/knx.py b/homeassistant/components/sensor/knx.py index ec506189c12..c096e15192d 100644 --- a/homeassistant/components/sensor/knx.py +++ b/homeassistant/components/sensor/knx.py @@ -42,7 +42,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities): entities = [] for device_name in discovery_info[ATTR_DISCOVER_DEVICES]: device = hass.data[DATA_KNX].xknx.devices[device_name] - entities.append(KNXSensor(hass, device)) + entities.append(KNXSensor(device)) async_add_entities(entities) @@ -56,17 +56,15 @@ def async_add_entities_config(hass, config, async_add_entities): group_address=config.get(CONF_ADDRESS), value_type=config.get(CONF_TYPE)) hass.data[DATA_KNX].xknx.devices.add(sensor) - async_add_entities([KNXSensor(hass, sensor)]) + async_add_entities([KNXSensor(sensor)]) class KNXSensor(Entity): """Representation of a KNX sensor.""" - def __init__(self, hass, device): + def __init__(self, device): """Initialize of a KNX sensor.""" self.device = device - self.hass = hass - self.async_register_callbacks() @callback def async_register_callbacks(self): @@ -76,6 +74,10 @@ class KNXSensor(Entity): await self.async_update_ha_state() self.device.register_device_updated_cb(after_update_callback) + async def async_added_to_hass(self): + """Store register state change callback.""" + self.async_register_callbacks() + @property def name(self): """Return the name of the KNX device.""" diff --git a/homeassistant/components/switch/knx.py b/homeassistant/components/switch/knx.py index 678a8d4775f..26b9f77028d 100644 --- a/homeassistant/components/switch/knx.py +++ b/homeassistant/components/switch/knx.py @@ -41,7 +41,7 @@ def async_add_entities_discovery(hass, discovery_info, async_add_entities): entities = [] for device_name in discovery_info[ATTR_DISCOVER_DEVICES]: device = hass.data[DATA_KNX].xknx.devices[device_name] - entities.append(KNXSwitch(hass, device)) + entities.append(KNXSwitch(device)) async_add_entities(entities) @@ -55,17 +55,15 @@ def async_add_entities_config(hass, config, async_add_entities): group_address=config.get(CONF_ADDRESS), group_address_state=config.get(CONF_STATE_ADDRESS)) hass.data[DATA_KNX].xknx.devices.add(switch) - async_add_entities([KNXSwitch(hass, switch)]) + async_add_entities([KNXSwitch(switch)]) class KNXSwitch(SwitchDevice): """Representation of a KNX switch.""" - def __init__(self, hass, device): + def __init__(self, device): """Initialize of KNX switch.""" self.device = device - self.hass = hass - self.async_register_callbacks() @callback def async_register_callbacks(self): @@ -75,6 +73,10 @@ class KNXSwitch(SwitchDevice): await self.async_update_ha_state() self.device.register_device_updated_cb(after_update_callback) + async def async_added_to_hass(self): + """Store register state change callback.""" + self.async_register_callbacks() + @property def name(self): """Return the name of the KNX device."""