diff --git a/homeassistant/components/intent_script/__init__.py b/homeassistant/components/intent_script/__init__.py index 63b37c08950..d6fbb1edd80 100644 --- a/homeassistant/components/intent_script/__init__.py +++ b/homeassistant/components/intent_script/__init__.py @@ -8,7 +8,7 @@ from typing import Any, TypedDict import voluptuous as vol from homeassistant.components.script import CONF_MODE -from homeassistant.const import CONF_TYPE, SERVICE_RELOAD +from homeassistant.const import CONF_DESCRIPTION, CONF_TYPE, SERVICE_RELOAD from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import ( config_validation as cv, @@ -24,6 +24,7 @@ _LOGGER = logging.getLogger(__name__) DOMAIN = "intent_script" +CONF_PLATFORMS = "platforms" CONF_INTENTS = "intents" CONF_SPEECH = "speech" CONF_REPROMPT = "reprompt" @@ -41,6 +42,8 @@ CONFIG_SCHEMA = vol.Schema( { DOMAIN: { cv.string: { + vol.Optional(CONF_DESCRIPTION): cv.string, + vol.Optional(CONF_PLATFORMS): vol.All([cv.string], vol.Coerce(set)), vol.Optional(CONF_ACTION): cv.SCRIPT_SCHEMA, vol.Optional( CONF_ASYNC_ACTION, default=DEFAULT_CONF_ASYNC_ACTION @@ -146,6 +149,8 @@ class ScriptIntentHandler(intent.IntentHandler): """Initialize the script intent handler.""" self.intent_type = intent_type self.config = config + self.description = config.get(CONF_DESCRIPTION) + self.platforms = config.get(CONF_PLATFORMS) async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse: """Handle the intent.""" diff --git a/tests/components/intent_script/test_init.py b/tests/components/intent_script/test_init.py index 14e5dd62d51..5f4c7b97b63 100644 --- a/tests/components/intent_script/test_init.py +++ b/tests/components/intent_script/test_init.py @@ -22,6 +22,8 @@ async def test_intent_script(hass: HomeAssistant) -> None: { "intent_script": { "HelloWorld": { + "description": "Intent to control a test service.", + "platforms": ["switch"], "action": { "service": "test.service", "data_template": {"hello": "{{ name }}"}, @@ -36,6 +38,17 @@ async def test_intent_script(hass: HomeAssistant) -> None: }, ) + handlers = [ + intent_handler + for intent_handler in intent.async_get(hass) + if intent_handler.intent_type == "HelloWorld" + ] + + assert len(handlers) == 1 + handler = handlers[0] + assert handler.description == "Intent to control a test service." + assert handler.platforms == {"switch"} + response = await intent.async_handle( hass, "test", "HelloWorld", {"name": {"value": "Paulus"}} ) @@ -78,6 +91,16 @@ async def test_intent_script_wait_response(hass: HomeAssistant) -> None: }, ) + handlers = [ + intent_handler + for intent_handler in intent.async_get(hass) + if intent_handler.intent_type == "HelloWorldWaitResponse" + ] + + assert len(handlers) == 1 + handler = handlers[0] + assert handler.platforms is None + response = await intent.async_handle( hass, "test", "HelloWorldWaitResponse", {"name": {"value": "Paulus"}} )