From 5acf372d15e86cef3181776022e9cae50dc7ad35 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 12 Jan 2014 11:29:08 -0800 Subject: [PATCH] Use hue_light reachable attribute to see if we can trust the on state. --- homeassistant/components/light.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/light.py b/homeassistant/components/light.py index 061dc9d6919..2f625a7604f 100644 --- a/homeassistant/components/light.py +++ b/homeassistant/components/light.py @@ -148,10 +148,16 @@ class HueLightControl(object): """ Returns if specified or all light are on. """ if not light_id: return any( - [True for light in self._light_map.values() if light.on]) + True for light in self._light_map.values() + if self.is_light_on(light)) else: - return self._bridge.get_light(self._convert_id(light_id), 'on') + state = self._bridge.get_light(self._convert_id(light_id)) + + try: + return state and state['reachable'] and state['state']['on'] + except KeyError: # If reachable, state or on not exists in state. + return False def turn_light_on(self, light_id=None, transition_seconds=None): """ Turn the specified or all lights on. """