Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch if Hue bridge goes unavailable #13109

Merged
merged 1 commit into from Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/hue/__init__.py
Expand Up @@ -181,6 +181,7 @@ def __init__(self, host, hass, filename, username, allow_unreachable=False,
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 = {}
Expand Down
10 changes: 8 additions & 2 deletions homeassistant/components/light/hue.py
Expand Up @@ -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))
Expand Down Expand Up @@ -266,8 +271,9 @@ def is_on(self):
@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):
Expand Down