Home Assistant Unofficial Reference 2024.12.1
intent.py
Go to the documentation of this file.
1 """Intents for the light integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 import voluptuous as vol
8 
9 from homeassistant.const import SERVICE_TURN_ON
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers import config_validation as cv, intent
12 import homeassistant.util.color as color_util
13 
14 from . import ATTR_BRIGHTNESS_PCT, ATTR_COLOR_TEMP_KELVIN, ATTR_RGB_COLOR, DOMAIN
15 
16 _LOGGER = logging.getLogger(__name__)
17 
18 INTENT_SET = "HassLightSet"
19 
20 
21 async def async_setup_intents(hass: HomeAssistant) -> None:
22  """Set up the light intents."""
23  intent.async_register(
24  hass,
25  intent.ServiceIntentHandler(
26  INTENT_SET,
27  DOMAIN,
28  SERVICE_TURN_ON,
29  optional_slots={
30  ("color", ATTR_RGB_COLOR): color_util.color_name_to_rgb,
31  ("temperature", ATTR_COLOR_TEMP_KELVIN): cv.positive_int,
32  ("brightness", ATTR_BRIGHTNESS_PCT): vol.All(
33  vol.Coerce(int), vol.Range(0, 100)
34  ),
35  },
36  description="Sets the brightness or color of a light",
37  platforms={DOMAIN},
38  ),
39  )
None async_setup_intents(HomeAssistant hass)
Definition: intent.py:21