Fix NoEntitySpecifiedError during knx startup (#17366)

* Potential fix for #13699

* removed uneccessary initialization of hass

* removed hass from signature
This commit is contained in:
Julius Mittenzwei authored and Martin Hjelmare committed 2018-10-15 03:29:36 +02:00
1 parent c5905ee5ca
commit a71cc67efb
6 files changed
+42 -31

No files matched your search

+7 -5
View File
@@ -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."""