From a7f34bbce9e564e648751e9cc8e9896887741745 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 11 Mar 2018 09:49:28 -0700 Subject: [PATCH] Implement Hue available property (#12939) --- homeassistant/components/light/hue.py | 11 ++++--- tests/components/light/test_hue.py | 42 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index bee6840f346..75825683928 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -261,10 +261,13 @@ class HueLight(Light): """Return true if device is on.""" if self.is_group: return self.info['state']['any_on'] - elif self.allow_unreachable: - return self.info['state']['on'] - return self.info['state']['reachable'] and \ - self.info['state']['on'] + return self.info['state']['on'] + + @property + def available(self): + """Return if light is available.""" + return (self.is_group or self.allow_unreachable or + self.info['state']['reachable']) @property def supported_features(self): diff --git a/tests/components/light/test_hue.py b/tests/components/light/test_hue.py index 5c28ea9988f..559467d5e9a 100644 --- a/tests/components/light/test_hue.py +++ b/tests/components/light/test_hue.py @@ -501,3 +501,45 @@ class TestHueLight(unittest.TestCase): light = self.buildLight(info={}, is_group=True) self.assertIsNone(light.unique_id) + + +def test_available(): + """Test available property.""" + light = hue_light.HueLight( + info={'state': {'reachable': False}}, + allow_unreachable=False, + is_group=False, + + light_id=None, + bridge=mock.Mock(), + update_lights_cb=None, + allow_in_emulated_hue=False, + ) + + assert light.available is False + + light = hue_light.HueLight( + info={'state': {'reachable': False}}, + allow_unreachable=True, + is_group=False, + + light_id=None, + bridge=mock.Mock(), + update_lights_cb=None, + allow_in_emulated_hue=False, + ) + + assert light.available is True + + light = hue_light.HueLight( + info={'state': {'reachable': False}}, + allow_unreachable=False, + is_group=True, + + light_id=None, + bridge=mock.Mock(), + update_lights_cb=None, + allow_in_emulated_hue=False, + ) + + assert light.available is True