Skip to content

Commit

Permalink
Implement Hue available property (#12939)
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Mar 11, 2018
1 parent 3dfc49d commit d42b5a9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
11 changes: 7 additions & 4 deletions homeassistant/components/light/hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,13 @@ def is_on(self):
"""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):
Expand Down
42 changes: 42 additions & 0 deletions tests/components/light/test_hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,45 @@ def test_unique_id_for_group(self):

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

0 comments on commit d42b5a9

Please sign in to comment.