Catch if bridge goes unavailable (#13109)
parent
8d8b07abd5
commit
51b0cbefe3
|
@ -181,6 +181,7 @@ class HueBridge(object):
|
||||||
self.allow_in_emulated_hue = allow_in_emulated_hue
|
self.allow_in_emulated_hue = allow_in_emulated_hue
|
||||||
self.allow_hue_groups = allow_hue_groups
|
self.allow_hue_groups = allow_hue_groups
|
||||||
|
|
||||||
|
self.available = True
|
||||||
self.bridge = None
|
self.bridge = None
|
||||||
self.lights = {}
|
self.lights = {}
|
||||||
self.lightgroups = {}
|
self.lightgroups = {}
|
||||||
|
|
|
@ -123,15 +123,20 @@ def unthrottled_update_lights(hass, bridge, add_devices):
|
||||||
api = bridge.get_api()
|
api = bridge.get_api()
|
||||||
except phue.PhueRequestTimeout:
|
except phue.PhueRequestTimeout:
|
||||||
_LOGGER.warning("Timeout trying to reach the bridge")
|
_LOGGER.warning("Timeout trying to reach the bridge")
|
||||||
|
bridge.available = False
|
||||||
return
|
return
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
_LOGGER.error("The bridge refused the connection")
|
_LOGGER.error("The bridge refused the connection")
|
||||||
|
bridge.available = False
|
||||||
return
|
return
|
||||||
except socket.error:
|
except socket.error:
|
||||||
# socket.error when we cannot reach Hue
|
# socket.error when we cannot reach Hue
|
||||||
_LOGGER.exception("Cannot reach the bridge")
|
_LOGGER.exception("Cannot reach the bridge")
|
||||||
|
bridge.available = False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
bridge.available = True
|
||||||
|
|
||||||
new_lights = process_lights(
|
new_lights = process_lights(
|
||||||
hass, api, bridge,
|
hass, api, bridge,
|
||||||
lambda **kw: update_lights(hass, bridge, add_devices, **kw))
|
lambda **kw: update_lights(hass, bridge, add_devices, **kw))
|
||||||
|
@ -266,8 +271,9 @@ class HueLight(Light):
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Return if light is available."""
|
"""Return if light is available."""
|
||||||
return (self.is_group or self.allow_unreachable or
|
return self.bridge.available and (self.is_group or
|
||||||
self.info['state']['reachable'])
|
self.allow_unreachable or
|
||||||
|
self.info['state']['reachable'])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
|
|
Loading…
Reference in New Issue