From 5abff70a87656667b47bf843fd9017706d903759 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Tue, 15 Mar 2016 10:13:57 -0400 Subject: [PATCH 1/6] read in `allow_unreachable` config value --- homeassistant/components/light/hue.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 0c2bf8b0411..c77c74b2e63 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -53,6 +53,8 @@ def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE): def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Setup the Hue lights.""" filename = config.get(CONF_FILENAME, PHUE_CONFIG_FILE) + allow_unreachable = config.get('allow_unreachable', False) + if discovery_info is not None: host = urlparse(discovery_info[1]).hostname else: From dd33831cb19d03655d84fa8304b525a9db114924 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Tue, 15 Mar 2016 10:15:10 -0400 Subject: [PATCH 2/6] pass allow_unreachable all the way down the line --- homeassistant/components/light/hue.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index c77c74b2e63..03fe6ad1977 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -71,10 +71,10 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): if host in _CONFIGURING: return - setup_bridge(host, hass, add_devices_callback, filename) + setup_bridge(host, hass, add_devices_callback, filename, allow_unreachable) -def setup_bridge(host, hass, add_devices_callback, filename): +def setup_bridge(host, hass, add_devices_callback, filename, allow_unreachable): """Setup a phue bridge based on host parameter.""" import phue @@ -132,7 +132,7 @@ def setup_bridge(host, hass, add_devices_callback, filename): if light_id not in lights: lights[light_id] = HueLight(int(light_id), info, bridge, update_lights, - bridge_type=bridge_type) + bridge_type, allow_unreachable) new_lights.append(lights[light_id]) else: lights[light_id].info = info @@ -173,7 +173,7 @@ class HueLight(Light): # pylint: disable=too-many-arguments def __init__(self, light_id, info, bridge, update_lights, - bridge_type='hue'): + bridge_type='hue', allow_unreachable=False): """Initialize the light.""" self.light_id = light_id self.info = info @@ -181,6 +181,8 @@ class HueLight(Light): self.update_lights = update_lights self.bridge_type = bridge_type + self.allow_unreachable = allow_unreachable + @property def unique_id(self): """Return the ID of this Hue light.""" From 95d5c456d7566f234c66c1facb6ed0f725ed0b44 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Tue, 15 Mar 2016 10:15:29 -0400 Subject: [PATCH 3/6] ignore unreachable state if opted in --- homeassistant/components/light/hue.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 03fe6ad1977..4c0211f6d15 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -213,7 +213,11 @@ class HueLight(Light): def is_on(self): """Return true if device is on.""" self.update_lights() - return self.info['state']['reachable'] and self.info['state']['on'] + + if self.allow_unreachable: + return self.info['state']['on'] + else: + return self.info['state']['reachable'] and self.info['state']['on'] def turn_on(self, **kwargs): """Turn the specified or all lights on.""" From 971fe8bc7b878cbaa59039b16e35ed95c3032297 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Tue, 15 Mar 2016 10:27:46 -0400 Subject: [PATCH 4/6] style --- homeassistant/components/light/hue.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 4c0211f6d15..f286c167aa9 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -74,7 +74,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): setup_bridge(host, hass, add_devices_callback, filename, allow_unreachable) -def setup_bridge(host, hass, add_devices_callback, filename, allow_unreachable): +def setup_bridge(host, hass, add_devices_callback, filename, + allow_unreachable): """Setup a phue bridge based on host parameter.""" import phue From b7b34b280f6f5720aee2bd21b86f6b52f31684d5 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Tue, 15 Mar 2016 10:27:56 -0400 Subject: [PATCH 5/6] just pass them in --- homeassistant/components/light/hue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index f286c167aa9..6d3bd7682a9 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -174,7 +174,7 @@ class HueLight(Light): # pylint: disable=too-many-arguments def __init__(self, light_id, info, bridge, update_lights, - bridge_type='hue', allow_unreachable=False): + bridge_type, allow_unreachable): """Initialize the light.""" self.light_id = light_id self.info = info From 9fe17423ea0dcbc5485a553d2455c9ecb79c388a Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Tue, 15 Mar 2016 10:37:47 -0400 Subject: [PATCH 6/6] pass allow_unreachable for callback --- homeassistant/components/light/hue.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 6d3bd7682a9..6defbf5efc5 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -91,7 +91,8 @@ def setup_bridge(host, hass, add_devices_callback, filename, except phue.PhueRegistrationException: _LOGGER.warning("Connected to Hue at %s but not registered.", host) - request_configuration(host, hass, add_devices_callback, filename) + request_configuration(host, hass, add_devices_callback, filename, + allow_unreachable) return @@ -144,7 +145,8 @@ def setup_bridge(host, hass, add_devices_callback, filename, update_lights() -def request_configuration(host, hass, add_devices_callback, filename): +def request_configuration(host, hass, add_devices_callback, filename, + allow_unreachable): """Request configuration steps from the user.""" configurator = get_component('configurator') @@ -158,7 +160,8 @@ def request_configuration(host, hass, add_devices_callback, filename): # pylint: disable=unused-argument def hue_configuration_callback(data): """The actions to do when our configuration callback is called.""" - setup_bridge(host, hass, add_devices_callback, filename) + setup_bridge(host, hass, add_devices_callback, filename, + allow_unreachable) _CONFIGURING[host] = configurator.request_config( hass, "Philips Hue", hue_configuration_callback,