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