mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Return color information in Alexa Smart Home response (#18368)
Fixes #18367.
This commit is contained in:
parent
9411fca955
commit
5b9a9d8e04
@ -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.
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user