Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions homeassistant/components/alexa/smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ 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)
return 0


class _AlexaColorController(_AlexaInterface):
Expand Down
19 changes: 18 additions & 1 deletion tests/components/alexa/test_smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was a mistake, the assert would always exit with a success if the first property was not the one being asserted. This fixes that so all properties are checked and at least one must match the assertion.


assert False, 'property %s:%s not in %r' % (
namespace,
Expand Down