Add temperature slot to light turn on intent (#118321)

This commit is contained in:
Michael Hansen 2024-05-28 13:53:49 -05:00 committed by GitHub
parent a59621bf9e
commit 75ab4d2398
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View file

@ -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)
),

View file

@ -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