From cfaefca2f6da7a7fffd50f7c14ef5425af8522c4 Mon Sep 17 00:00:00 2001 From: Richard Lucas Date: Sun, 11 Feb 2018 11:53:13 -0800 Subject: [PATCH 1/2] Fix Report State for Alexa Brightness Controller --- homeassistant/components/alexa/smart_home.py | 6 ++++-- tests/components/alexa/test_smart_home.py | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/alexa/smart_home.py b/homeassistant/components/alexa/smart_home.py index 354a612c4b80d..a04674786d711 100644 --- a/homeassistant/components/alexa/smart_home.py +++ b/homeassistant/components/alexa/smart_home.py @@ -328,8 +328,10 @@ def properties_retrievable(self): def get_property(self, name): if name != 'brightness': raise _UnsupportedProperty(name) - - return round(self.entity.attributes['brightness'] / 255.0 * 100) + if 'brightness' in self.entity.attributes: + return round(self.entity.attributes['brightness'] / 255.0 * 100) + else: + return 0 class _AlexaColorController(_AlexaInterface): diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index 71485231150ab..d762a0bb3e798 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -1095,6 +1095,23 @@ def test_report_lock_state(hass): properties.assert_equal('Alexa.LockController', 'lockState', 'JAMMED') +@asyncio.coroutine +def test_report_dimmable_light_state(hass): + """Test BrightnessController reports brightness correctly.""" + hass.states.async_set( + 'light.test_on', 'on', {'friendly_name': "Test light On", + 'brightness': 128, 'supported_features': 1}) + hass.states.async_set( + 'light.test_off', 'off', {'friendly_name': "Test light Off", + 'supported_features': 1}) + + properties = yield from reported_properties(hass, 'light.test_on') + properties.assert_equal('Alexa.BrightnessController', 'brightness', 50) + + properties = yield from reported_properties(hass, 'light.test_off') + properties.assert_equal('Alexa.BrightnessController', 'brightness', 0) + + @asyncio.coroutine def reported_properties(hass, endpoint): """Use ReportState to get properties and return them. @@ -1118,7 +1135,7 @@ def assert_equal(self, namespace, name, value): for prop in self.properties: if prop['namespace'] == namespace and prop['name'] == name: assert prop['value'] == value - return prop + return prop assert False, 'property %s:%s not in %r' % ( namespace, From 87ccfff1ef6ce79088908fce2beb95910d2b999d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 11 Feb 2018 20:38:09 -0800 Subject: [PATCH 2/2] Lint --- homeassistant/components/alexa/smart_home.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/alexa/smart_home.py b/homeassistant/components/alexa/smart_home.py index a04674786d711..c96ea4b56e604 100644 --- a/homeassistant/components/alexa/smart_home.py +++ b/homeassistant/components/alexa/smart_home.py @@ -330,8 +330,7 @@ def get_property(self, name): raise _UnsupportedProperty(name) if 'brightness' in self.entity.attributes: return round(self.entity.attributes['brightness'] / 255.0 * 100) - else: - return 0 + return 0 class _AlexaColorController(_AlexaInterface):