Add set_conversation_response script action (#108233)

* Add set_conversation_response script action

* Update homeassistant/components/conversation/trigger.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Revert accidental change

* Add test

* Ignore mypy

* Remove incorrect callback decorator

* Update homeassistant/helpers/script.py

* Add test with templated set_conversation_response

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Erik Montnemery 2024-01-23 15:13:42 +01:00 committed by GitHub
parent e3a73c12bc
commit 9bff039d17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 248 additions and 13 deletions

View file

@ -7,10 +7,11 @@ from hassil.recognize import PUNCTUATION, RecognizeResult
import voluptuous as vol
from homeassistant.const import CONF_COMMAND, CONF_PLATFORM
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.script import ScriptRunResult
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.typing import UNDEFINED, ConfigType
from . import HOME_ASSISTANT_AGENT, _get_agent_manager
from .const import DOMAIN
@ -60,7 +61,6 @@ async def async_attach_trigger(
job = HassJob(action)
@callback
async def call_action(sentence: str, result: RecognizeResult) -> str | None:
"""Call action with right context."""
@ -91,7 +91,12 @@ async def async_attach_trigger(
job,
{"trigger": trigger_input},
):
await future
automation_result = await future
if isinstance(
automation_result, ScriptRunResult
) and automation_result.conversation_response not in (None, UNDEFINED):
# mypy does not understand the type narrowing, unclear why
return automation_result.conversation_response # type: ignore[return-value]
return "Done"