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 2018-10-15 03:29:36 +02:00 committed by Martin Hjelmare
parent c5905ee5ca
commit a71cc67efb
6 changed files with 42 additions and 31 deletions

View file

@ -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."""