Ensure sentence triggers are only checked once (#131210)
Co-authored-by: Artur Pragacz <49985303+arturpragacz@users.noreply.github.com>pull/127580/merge
parent
754cf1fdb4
commit
7621012ee6
|
@ -1032,39 +1032,37 @@ class PipelineRun:
|
||||||
agent_id=self.intent_agent,
|
agent_id=self.intent_agent,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Sentence triggers override conversation agent
|
conversation_result: conversation.ConversationResult | None = None
|
||||||
if (
|
if user_input.agent_id != conversation.HOME_ASSISTANT_AGENT:
|
||||||
trigger_response_text
|
# Sentence triggers override conversation agent
|
||||||
:= await conversation.async_handle_sentence_triggers(
|
if (
|
||||||
self.hass, user_input
|
trigger_response_text
|
||||||
)
|
:= await conversation.async_handle_sentence_triggers(
|
||||||
):
|
self.hass, user_input
|
||||||
# Sentence trigger matched
|
)
|
||||||
trigger_response = intent.IntentResponse(
|
):
|
||||||
self.pipeline.conversation_language
|
# Sentence trigger matched
|
||||||
)
|
trigger_response = intent.IntentResponse(
|
||||||
trigger_response.async_set_speech(trigger_response_text)
|
self.pipeline.conversation_language
|
||||||
conversation_result = conversation.ConversationResult(
|
)
|
||||||
response=trigger_response,
|
trigger_response.async_set_speech(trigger_response_text)
|
||||||
conversation_id=user_input.conversation_id,
|
conversation_result = conversation.ConversationResult(
|
||||||
)
|
response=trigger_response,
|
||||||
# Try local intents first, if preferred.
|
conversation_id=user_input.conversation_id,
|
||||||
# Skip this step if the default agent is already used.
|
)
|
||||||
elif (
|
# Try local intents first, if preferred.
|
||||||
self.pipeline.prefer_local_intents
|
elif self.pipeline.prefer_local_intents and (
|
||||||
and (user_input.agent_id != conversation.HOME_ASSISTANT_AGENT)
|
|
||||||
and (
|
|
||||||
intent_response := await conversation.async_handle_intents(
|
intent_response := await conversation.async_handle_intents(
|
||||||
self.hass, user_input
|
self.hass, user_input
|
||||||
)
|
)
|
||||||
)
|
):
|
||||||
):
|
# Local intent matched
|
||||||
# Local intent matched
|
conversation_result = conversation.ConversationResult(
|
||||||
conversation_result = conversation.ConversationResult(
|
response=intent_response,
|
||||||
response=intent_response,
|
conversation_id=user_input.conversation_id,
|
||||||
conversation_id=user_input.conversation_id,
|
)
|
||||||
)
|
|
||||||
else:
|
if conversation_result is None:
|
||||||
# Fall back to pipeline conversation agent
|
# Fall back to pipeline conversation agent
|
||||||
conversation_result = await conversation.async_converse(
|
conversation_result = await conversation.async_converse(
|
||||||
hass=self.hass,
|
hass=self.hass,
|
||||||
|
|
|
@ -941,7 +941,7 @@ async def test_sentence_trigger_overrides_conversation_agent(
|
||||||
init_components,
|
init_components,
|
||||||
pipeline_data: assist_pipeline.pipeline.PipelineData,
|
pipeline_data: assist_pipeline.pipeline.PipelineData,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that sentence triggers are checked before the conversation agent."""
|
"""Test that sentence triggers are checked before a non-default conversation agent."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"automation",
|
"automation",
|
||||||
|
@ -975,9 +975,16 @@ async def test_sentence_trigger_overrides_conversation_agent(
|
||||||
start_stage=assist_pipeline.PipelineStage.INTENT,
|
start_stage=assist_pipeline.PipelineStage.INTENT,
|
||||||
end_stage=assist_pipeline.PipelineStage.INTENT,
|
end_stage=assist_pipeline.PipelineStage.INTENT,
|
||||||
event_callback=events.append,
|
event_callback=events.append,
|
||||||
|
intent_agent="test-agent", # not the default agent
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
await pipeline_input.validate()
|
|
||||||
|
# Ensure prepare succeeds
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.assist_pipeline.pipeline.conversation.async_get_agent_info",
|
||||||
|
return_value=conversation.AgentInfo(id="test-agent", name="Test Agent"),
|
||||||
|
):
|
||||||
|
await pipeline_input.validate()
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.assist_pipeline.pipeline.conversation.async_converse"
|
"homeassistant.components.assist_pipeline.pipeline.conversation.async_converse"
|
||||||
|
|
Loading…
Reference in New Issue