Check color temp range for google assistant (#12994)

This commit is contained in:
Paulus Schoutsen 2018-03-08 17:43:41 -08:00 committed by GitHub
parent c4a4802a8c
commit 7f065e38a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 4 deletions

View file

@ -330,9 +330,20 @@ class ColorTemperatureTrait(_Trait):
async def execute(self, hass, command, params):
"""Execute a color temperature command."""
temp = color_util.color_temperature_kelvin_to_mired(
params['color']['temperature'])
min_temp = self.state.attributes[light.ATTR_MIN_MIREDS]
max_temp = self.state.attributes[light.ATTR_MAX_MIREDS]
if temp < min_temp or temp > max_temp:
raise SmartHomeError(
ERR_VALUE_OUT_OF_RANGE,
"Temperature should be between {} and {}".format(min_temp,
max_temp))
await hass.services.async_call(light.DOMAIN, SERVICE_TURN_ON, {
ATTR_ENTITY_ID: self.state.entity_id,
light.ATTR_KELVIN: params['color']['temperature'],
light.ATTR_COLOR_TEMP: temp,
}, blocking=True)