From 51b0cbefe3d8145b503e4b87311ce91ed9e09558 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 12 Mar 2018 13:55:22 -0700 Subject: [PATCH] Catch if bridge goes unavailable (#13109) --- homeassistant/components/hue/__init__.py | 1 + homeassistant/components/light/hue.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/hue/__init__.py b/homeassistant/components/hue/__init__.py index 92b23a74065..f15052fbd67 100644 --- a/homeassistant/components/hue/__init__.py +++ b/homeassistant/components/hue/__init__.py @@ -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 = {} diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 75825683928..661b7c2b3a1 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -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):