From 75ab4d2398d1995e0730461513f9a6bb32406deb Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Tue, 28 May 2024 13:53:49 -0500 Subject: [PATCH] Add temperature slot to light turn on intent (#118321) --- homeassistant/components/light/intent.py | 5 +++-- tests/components/light/test_intent.py | 27 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/light/intent.py b/homeassistant/components/light/intent.py index a2824f7cc22..1839d176f91 100644 --- a/homeassistant/components/light/intent.py +++ b/homeassistant/components/light/intent.py @@ -8,10 +8,10 @@ import voluptuous as vol from homeassistant.const import SERVICE_TURN_ON from homeassistant.core import HomeAssistant -from homeassistant.helpers import intent +from homeassistant.helpers import config_validation as cv, intent import homeassistant.util.color as color_util -from . import ATTR_BRIGHTNESS_PCT, ATTR_RGB_COLOR, DOMAIN +from . import ATTR_BRIGHTNESS_PCT, ATTR_COLOR_TEMP_KELVIN, ATTR_RGB_COLOR, DOMAIN _LOGGER = logging.getLogger(__name__) @@ -28,6 +28,7 @@ async def async_setup_intents(hass: HomeAssistant) -> None: SERVICE_TURN_ON, optional_slots={ ("color", ATTR_RGB_COLOR): color_util.color_name_to_rgb, + ("temperature", ATTR_COLOR_TEMP_KELVIN): cv.positive_int, ("brightness", ATTR_BRIGHTNESS_PCT): vol.All( vol.Coerce(int), vol.Range(0, 100) ), diff --git a/tests/components/light/test_intent.py b/tests/components/light/test_intent.py index 94457928b5b..1f5a9e7ce27 100644 --- a/tests/components/light/test_intent.py +++ b/tests/components/light/test_intent.py @@ -62,3 +62,30 @@ async def test_intent_set_color_and_brightness(hass: HomeAssistant) -> None: assert call.data.get(ATTR_ENTITY_ID) == "light.hello_2" assert call.data.get(light.ATTR_RGB_COLOR) == (0, 0, 255) assert call.data.get(light.ATTR_BRIGHTNESS_PCT) == 20 + + +async def test_intent_set_temperature(hass: HomeAssistant) -> None: + """Test setting the color temperature in kevin via intent.""" + hass.states.async_set( + "light.test", "off", {ATTR_SUPPORTED_COLOR_MODES: [ColorMode.COLOR_TEMP]} + ) + calls = async_mock_service(hass, light.DOMAIN, light.SERVICE_TURN_ON) + await intent.async_setup_intents(hass) + + await async_handle( + hass, + "test", + intent.INTENT_SET, + { + "name": {"value": "Test"}, + "temperature": {"value": 2000}, + }, + ) + await hass.async_block_till_done() + + assert len(calls) == 1 + call = calls[0] + assert call.domain == light.DOMAIN + assert call.service == SERVICE_TURN_ON + assert call.data.get(ATTR_ENTITY_ID) == "light.test" + assert call.data.get(light.ATTR_COLOR_TEMP_KELVIN) == 2000