Catch if bridge goes unavailable (#13109)

pull/13164/head
Paulus Schoutsen 2018-03-12 13:55:22 -07:00 committed by GitHub
parent 8d8b07abd5
commit 51b0cbefe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -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 = {}

View File

@ -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):