Check color temp range for google assistant (#12994)
This commit is contained in:
parent
c4a4802a8c
commit
7f065e38a7
2 changed files with 26 additions and 4 deletions
|
@ -330,9 +330,20 @@ class ColorTemperatureTrait(_Trait):
|
||||||
|
|
||||||
async def execute(self, hass, command, params):
|
async def execute(self, hass, command, params):
|
||||||
"""Execute a color temperature command."""
|
"""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, {
|
await hass.services.async_call(light.DOMAIN, SERVICE_TURN_ON, {
|
||||||
ATTR_ENTITY_ID: self.state.entity_id,
|
ATTR_ENTITY_ID: self.state.entity_id,
|
||||||
light.ATTR_KELVIN: params['color']['temperature'],
|
light.ATTR_COLOR_TEMP: temp,
|
||||||
}, blocking=True)
|
}, blocking=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,8 @@ from homeassistant.components import (
|
||||||
script,
|
script,
|
||||||
switch,
|
switch,
|
||||||
)
|
)
|
||||||
from homeassistant.components.google_assistant import trait, helpers
|
from homeassistant.components.google_assistant import trait, helpers, const
|
||||||
|
from homeassistant.util import color
|
||||||
|
|
||||||
from tests.common import async_mock_service
|
from tests.common import async_mock_service
|
||||||
|
|
||||||
|
@ -399,6 +400,15 @@ async def test_color_temperature_light(hass):
|
||||||
})
|
})
|
||||||
|
|
||||||
calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
||||||
|
|
||||||
|
with pytest.raises(helpers.SmartHomeError) as err:
|
||||||
|
await trt.execute(hass, trait.COMMAND_COLOR_ABSOLUTE, {
|
||||||
|
'color': {
|
||||||
|
'temperature': 5555
|
||||||
|
}
|
||||||
|
})
|
||||||
|
assert err.value.code == const.ERR_VALUE_OUT_OF_RANGE
|
||||||
|
|
||||||
await trt.execute(hass, trait.COMMAND_COLOR_ABSOLUTE, {
|
await trt.execute(hass, trait.COMMAND_COLOR_ABSOLUTE, {
|
||||||
'color': {
|
'color': {
|
||||||
'temperature': 2857
|
'temperature': 2857
|
||||||
|
@ -407,7 +417,7 @@ async def test_color_temperature_light(hass):
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data == {
|
assert calls[0].data == {
|
||||||
ATTR_ENTITY_ID: 'light.bla',
|
ATTR_ENTITY_ID: 'light.bla',
|
||||||
light.ATTR_KELVIN: 2857
|
light.ATTR_COLOR_TEMP: color.color_temperature_kelvin_to_mired(2857)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -511,11 +521,12 @@ async def test_temperature_setting_climate_range(hass):
|
||||||
climate.ATTR_OPERATION_MODE: climate.STATE_AUTO,
|
climate.ATTR_OPERATION_MODE: climate.STATE_AUTO,
|
||||||
}
|
}
|
||||||
|
|
||||||
with pytest.raises(helpers.SmartHomeError):
|
with pytest.raises(helpers.SmartHomeError) as err:
|
||||||
await trt.execute(
|
await trt.execute(
|
||||||
hass, trait.COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT, {
|
hass, trait.COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT, {
|
||||||
'thermostatTemperatureSetpoint': -100,
|
'thermostatTemperatureSetpoint': -100,
|
||||||
})
|
})
|
||||||
|
assert err.value.code == const.ERR_VALUE_OUT_OF_RANGE
|
||||||
|
|
||||||
|
|
||||||
async def test_temperature_setting_climate_setpoint(hass):
|
async def test_temperature_setting_climate_setpoint(hass):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue