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
20 changes: 20 additions & 0 deletions homeassistant/components/alexa/smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,26 @@ class _AlexaColorController(_AlexaInterface):
def name(self):
return 'Alexa.ColorController'

def properties_supported(self):
return [{'name': 'color'}]

def properties_retrievable(self):
return True

def get_property(self, name):
if name != 'color':
raise _UnsupportedProperty(name)

hue, saturation = self.entity.attributes.get(
light.ATTR_HS_COLOR, (0, 0))

return {
'hue': hue,
'saturation': saturation / 100.0,
'brightness': self.entity.attributes.get(
light.ATTR_BRIGHTNESS, 0) / 255.0,
}


class _AlexaColorTemperatureController(_AlexaInterface):
"""Implements Alexa.ColorTemperatureController.
Expand Down
26 changes: 26 additions & 0 deletions tests/components/alexa/test_smart_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,32 @@ async def test_report_dimmable_light_state(hass):
properties.assert_equal('Alexa.BrightnessController', 'brightness', 0)


async def test_report_colored_light_state(hass):
"""Test ColorController reports color correctly."""
hass.states.async_set(
'light.test_on', 'on', {'friendly_name': "Test light On",
'hs_color': (180, 75),
'brightness': 128,
'supported_features': 17})
hass.states.async_set(
'light.test_off', 'off', {'friendly_name': "Test light Off",
'supported_features': 17})

properties = await reported_properties(hass, 'light.test_on')
properties.assert_equal('Alexa.ColorController', 'color', {
'hue': 180,
'saturation': 0.75,
'brightness': 128 / 255.0,
})

properties = await reported_properties(hass, 'light.test_off')
properties.assert_equal('Alexa.ColorController', 'color', {
'hue': 0,
'saturation': 0,
'brightness': 0,
})


async def reported_properties(hass, endpoint):
"""Use ReportState to get properties and return them.

Expand Down