From efb83dde19f061ac217745737446dc3a396fc9ec Mon Sep 17 00:00:00 2001 From: Julius Mittenzwei Date: Sun, 7 Jan 2018 22:39:14 +0100 Subject: [PATCH] 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 --- homeassistant/components/binary_sensor/knx.py | 5 +++++ homeassistant/components/climate/knx.py | 5 +++++ homeassistant/components/cover/knx.py | 5 +++++ homeassistant/components/knx.py | 12 ++++++++---- homeassistant/components/light/knx.py | 5 +++++ homeassistant/components/sensor/knx.py | 5 +++++ homeassistant/components/switch/knx.py | 5 +++++ 7 files changed, 38 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/binary_sensor/knx.py b/homeassistant/components/binary_sensor/knx.py index 406f60f99bb..9e5ddf5cac4 100644 --- a/homeassistant/components/binary_sensor/knx.py +++ b/homeassistant/components/binary_sensor/knx.py @@ -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.""" diff --git a/homeassistant/components/climate/knx.py b/homeassistant/components/climate/knx.py index fb0de1e2de0..97bd3e9503c 100644 --- a/homeassistant/components/climate/knx.py +++ b/homeassistant/components/climate/knx.py @@ -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.""" diff --git a/homeassistant/components/cover/knx.py b/homeassistant/components/cover/knx.py index b840c780645..d8313caeb5f 100644 --- a/homeassistant/components/cover/knx.py +++ b/homeassistant/components/cover/knx.py @@ -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.""" diff --git a/homeassistant/components/knx.py b/homeassistant/components/knx.py index 3966b490f52..f9747351bdd 100644 --- a/homeassistant/components/knx.py +++ b/homeassistant/components/knx.py @@ -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:
" + "{0}".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): diff --git a/homeassistant/components/light/knx.py b/homeassistant/components/light/knx.py index 3688cafdd25..c1caf91db45 100644 --- a/homeassistant/components/light/knx.py +++ b/homeassistant/components/light/knx.py @@ -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.""" diff --git a/homeassistant/components/sensor/knx.py b/homeassistant/components/sensor/knx.py index 7abc986bdd7..f803f406e1e 100644 --- a/homeassistant/components/sensor/knx.py +++ b/homeassistant/components/sensor/knx.py @@ -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.""" diff --git a/homeassistant/components/switch/knx.py b/homeassistant/components/switch/knx.py index b340bf5f43a..d1c6d717945 100644 --- a/homeassistant/components/switch/knx.py +++ b/homeassistant/components/switch/knx.py @@ -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."""