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:
parent
e3a73c12bc
commit
9bff039d17
8 changed files with 248 additions and 13 deletions
|
@ -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"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue