mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Add "conversation" key to translations (#114887)
* Use translated trigger response * Use conversation key instead
This commit is contained in:
parent
cceea6dac2
commit
1c2499b03a
@ -269,20 +269,38 @@ class DefaultAgent(ConversationEntity):
|
|||||||
for trigger_id, trigger_result in result.matched_triggers.items()
|
for trigger_id, trigger_result in result.matched_triggers.items()
|
||||||
]
|
]
|
||||||
|
|
||||||
# Use last non-empty result as response.
|
# Use first non-empty result as response.
|
||||||
#
|
#
|
||||||
# There may be multiple copies of a trigger running when editing in
|
# There may be multiple copies of a trigger running when editing in
|
||||||
# the UI, so it's critical that we filter out empty responses here.
|
# the UI, so it's critical that we filter out empty responses here.
|
||||||
response_text: str | None = None
|
response_text: str | None = None
|
||||||
|
response_set_by_trigger = False
|
||||||
for trigger_future in asyncio.as_completed(trigger_callbacks):
|
for trigger_future in asyncio.as_completed(trigger_callbacks):
|
||||||
if trigger_response := await trigger_future:
|
trigger_response = await trigger_future
|
||||||
|
if trigger_response is None:
|
||||||
|
continue
|
||||||
|
|
||||||
response_text = trigger_response
|
response_text = trigger_response
|
||||||
|
response_set_by_trigger = True
|
||||||
break
|
break
|
||||||
|
|
||||||
# Convert to conversation result
|
# Convert to conversation result
|
||||||
response = intent.IntentResponse(language=language)
|
response = intent.IntentResponse(language=language)
|
||||||
response.response_type = intent.IntentResponseType.ACTION_DONE
|
response.response_type = intent.IntentResponseType.ACTION_DONE
|
||||||
response.async_set_speech(response_text or "Done")
|
|
||||||
|
if response_set_by_trigger:
|
||||||
|
# Response was explicitly set to empty
|
||||||
|
response_text = response_text or ""
|
||||||
|
elif not response_text:
|
||||||
|
# Use translated acknowledgment for pipeline language
|
||||||
|
translations = await translation.async_get_translations(
|
||||||
|
self.hass, language, DOMAIN, [DOMAIN]
|
||||||
|
)
|
||||||
|
response_text = translations.get(
|
||||||
|
f"component.{DOMAIN}.agent.done", "Done"
|
||||||
|
)
|
||||||
|
|
||||||
|
response.async_set_speech(response_text)
|
||||||
|
|
||||||
return ConversationResult(response=response)
|
return ConversationResult(response=response)
|
||||||
|
|
||||||
|
@ -37,5 +37,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"conversation": {
|
||||||
|
"agent": {
|
||||||
|
"done": "Done"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,6 +360,11 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema:
|
|||||||
},
|
},
|
||||||
slug_validator=translation_key_validator,
|
slug_validator=translation_key_validator,
|
||||||
),
|
),
|
||||||
|
vol.Optional("conversation"): {
|
||||||
|
vol.Required("agent"): {
|
||||||
|
vol.Required("done"): translation_value_validator,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -104,6 +104,36 @@ async def test_response(hass: HomeAssistant, setup_comp) -> None:
|
|||||||
assert service_response["response"]["speech"]["plain"]["speech"] == response
|
assert service_response["response"]["speech"]["plain"]["speech"] == response
|
||||||
|
|
||||||
|
|
||||||
|
async def test_empty_response(hass: HomeAssistant, setup_comp) -> None:
|
||||||
|
"""Test the conversation response action with an empty response."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
"automation",
|
||||||
|
{
|
||||||
|
"automation": {
|
||||||
|
"trigger": {
|
||||||
|
"platform": "conversation",
|
||||||
|
"command": ["Open the pod bay door Hal"],
|
||||||
|
},
|
||||||
|
"action": {
|
||||||
|
"set_conversation_response": "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
service_response = await hass.services.async_call(
|
||||||
|
"conversation",
|
||||||
|
"process",
|
||||||
|
{
|
||||||
|
"text": "Open the pod bay door Hal",
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
return_response=True,
|
||||||
|
)
|
||||||
|
assert service_response["response"]["speech"]["plain"]["speech"] == ""
|
||||||
|
|
||||||
|
|
||||||
async def test_response_same_sentence(hass: HomeAssistant, calls, setup_comp) -> None:
|
async def test_response_same_sentence(hass: HomeAssistant, calls, setup_comp) -> None:
|
||||||
"""Test the conversation response action with multiple triggers using the same sentence."""
|
"""Test the conversation response action with multiple triggers using the same sentence."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user