More tolerant KNX component if gateway cant be connected (#11511)

* Issue #11432: Do not stop initializing KNX when tunelling device cant be reached

*  Issue #11432: Mark devices as unavailable if gateway cant be connected
pull/10192/merge
Julius Mittenzwei 2018-01-07 22:39:14 +01:00 committed by Paulus Schoutsen
parent c20324793e
commit efb83dde19
7 changed files with 38 additions and 4 deletions

View File

@ -129,6 +129,11 @@ class KNXBinarySensor(BinarySensorDevice):
"""Return the name of the KNX device."""
return self.device.name
@property
def available(self):
"""Return True if entity is available."""
return self.hass.data[DATA_KNX].connected
@property
def should_poll(self):
"""No polling needed within KNX."""

View File

@ -159,6 +159,11 @@ class KNXClimate(ClimateDevice):
"""Return the name of the KNX device."""
return self.device.name
@property
def available(self):
"""Return True if entity is available."""
return self.hass.data[DATA_KNX].connected
@property
def should_poll(self):
"""No polling needed within KNX."""

View File

@ -124,6 +124,11 @@ class KNXCover(CoverDevice):
"""Return the name of the KNX device."""
return self.device.name
@property
def available(self):
"""Return True if entity is available."""
return self.hass.data[DATA_KNX].connected
@property
def should_poll(self):
"""No polling needed within KNX."""

View File

@ -80,8 +80,11 @@ def async_setup(hass, config):
yield from hass.data[DATA_KNX].start()
except XKNXException as ex:
_LOGGER.exception("Can't connect to KNX interface: %s", ex)
return False
_LOGGER.warning("Can't connect to KNX interface: %s", ex)
hass.components.persistent_notification.async_create(
"Can't connect to KNX interface: <br>"
"<b>{0}</b>".format(ex),
title="KNX")
for component, discovery_type in (
('switch', 'Switch'),
@ -120,7 +123,8 @@ class KNXModule(object):
"""Initialization of KNXModule."""
self.hass = hass
self.config = config
self.initialized = False
self.connected = False
self.initialized = True
self.init_xknx()
self.register_callbacks()
@ -139,7 +143,7 @@ class KNXModule(object):
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.initialized = True
self.connected = True
@asyncio.coroutine
def stop(self, event):

View File

@ -97,6 +97,11 @@ class KNXLight(Light):
"""Return the name of the KNX device."""
return self.device.name
@property
def available(self):
"""Return True if entity is available."""
return self.hass.data[DATA_KNX].connected
@property
def should_poll(self):
"""No polling needed within KNX."""

View File

@ -90,6 +90,11 @@ class KNXSensor(Entity):
"""Return the name of the KNX device."""
return self.device.name
@property
def available(self):
"""Return True if entity is available."""
return self.hass.data[DATA_KNX].connected
@property
def should_poll(self):
"""No polling needed within KNX."""

View File

@ -89,6 +89,11 @@ class KNXSwitch(SwitchDevice):
"""Return the name of the KNX device."""
return self.device.name
@property
def available(self):
"""Return True if entity is available."""
return self.hass.data[DATA_KNX].connected
@property
def should_poll(self):
"""No polling needed within KNX."""