Add script_mode parameter to custom intent scripts (#102203)

* Add script_mode parameter to custom intent scripts

* Reuse CONF_MODE from the script component
This commit is contained in:
Tudor Sandu 2023-11-09 14:41:25 -08:00 committed by GitHub
parent 04e0e2bd75
commit 527a3dba9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,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.core import HomeAssistant, ServiceCall
from homeassistant.helpers import (
@ -43,6 +44,9 @@ CONFIG_SCHEMA = vol.Schema(
vol.Optional(
CONF_ASYNC_ACTION, default=DEFAULT_CONF_ASYNC_ACTION
): cv.boolean,
vol.Optional(CONF_MODE, default=script.DEFAULT_SCRIPT_MODE): vol.In(
script.SCRIPT_MODE_CHOICES
),
vol.Optional(CONF_CARD): {
vol.Optional(CONF_TYPE, default="simple"): cv.string,
vol.Required(CONF_TITLE): cv.template,
@ -87,8 +91,13 @@ def async_load_intents(hass: HomeAssistant, intents: dict[str, ConfigType]) -> N
for intent_type, conf in intents.items():
if CONF_ACTION in conf:
script_mode: str = conf.get(CONF_MODE, script.DEFAULT_SCRIPT_MODE)
conf[CONF_ACTION] = script.Script(
hass, conf[CONF_ACTION], f"Intent Script {intent_type}", DOMAIN
hass,
conf[CONF_ACTION],
f"Intent Script {intent_type}",
DOMAIN,
script_mode=script_mode,
)
intent.async_register(hass, ScriptIntentHandler(intent_type, conf))