Fix missing colorTemperatureInKelvin from Alexa responses (#19069)

* Fix missing colorTemperatureInKelvin from Alexa responses

* Update smart_home.py

* Add test
This commit is contained in:
Mike Miller 2018-12-06 18:05:15 +02:00 committed by Paulus Schoutsen
parent c931619269
commit dd92318762
2 changed files with 33 additions and 0 deletions

View File

@ -504,6 +504,20 @@ class _AlexaColorTemperatureController(_AlexaInterface):
def name(self):
return 'Alexa.ColorTemperatureController'
def properties_supported(self):
return [{'name': 'colorTemperatureInKelvin'}]
def properties_retrievable(self):
return True
def get_property(self, name):
if name != 'colorTemperatureInKelvin':
raise _UnsupportedProperty(name)
if 'color_temp' in self.entity.attributes:
return color_util.color_temperature_mired_to_kelvin(
self.entity.attributes['color_temp'])
return 0
class _AlexaPercentageController(_AlexaInterface):
"""Implements Alexa.PercentageController.

View File

@ -1354,6 +1354,25 @@ async def test_report_colored_light_state(hass):
})
async def test_report_colored_temp_light_state(hass):
"""Test ColorTemperatureController reports color temp correctly."""
hass.states.async_set(
'light.test_on', 'on', {'friendly_name': "Test light On",
'color_temp': 240,
'supported_features': 2})
hass.states.async_set(
'light.test_off', 'off', {'friendly_name': "Test light Off",
'supported_features': 2})
properties = await reported_properties(hass, 'light.test_on')
properties.assert_equal('Alexa.ColorTemperatureController',
'colorTemperatureInKelvin', 4166)
properties = await reported_properties(hass, 'light.test_off')
properties.assert_equal('Alexa.ColorTemperatureController',
'colorTemperatureInKelvin', 0)
async def reported_properties(hass, endpoint):
"""Use ReportState to get properties and return them.