Fix Report State for Alexa Brightness Controller (#12318)

* Fix Report State for Alexa Brightness Controller

* Lint
This commit is contained in:
Richard Lucas 2018-02-11 22:36:22 -08:00 committed by Paulus Schoutsen
parent ead158b68c
commit 2a0bd8d330
2 changed files with 21 additions and 3 deletions

View File

@ -328,8 +328,9 @@ class _AlexaBrightnessController(_AlexaInterface):
def get_property(self, name): def get_property(self, name):
if name != 'brightness': if name != 'brightness':
raise _UnsupportedProperty(name) raise _UnsupportedProperty(name)
if 'brightness' in self.entity.attributes:
return round(self.entity.attributes['brightness'] / 255.0 * 100) return round(self.entity.attributes['brightness'] / 255.0 * 100)
return 0
class _AlexaColorController(_AlexaInterface): class _AlexaColorController(_AlexaInterface):

View File

@ -1095,6 +1095,23 @@ def test_report_lock_state(hass):
properties.assert_equal('Alexa.LockController', 'lockState', 'JAMMED') 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 @asyncio.coroutine
def reported_properties(hass, endpoint): def reported_properties(hass, endpoint):
"""Use ReportState to get properties and return them. """Use ReportState to get properties and return them.
@ -1118,7 +1135,7 @@ class _ReportedProperties(object):
for prop in self.properties: for prop in self.properties:
if prop['namespace'] == namespace and prop['name'] == name: if prop['namespace'] == namespace and prop['name'] == name:
assert prop['value'] == value assert prop['value'] == value
return prop return prop
assert False, 'property %s:%s not in %r' % ( assert False, 'property %s:%s not in %r' % (
namespace, namespace,