mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Fix default conversation agent tests (#128490)
This commit is contained in:
parent
e273148a89
commit
866f1e70a4
@ -2602,10 +2602,7 @@ async def test_custom_sentences_priority(
|
|||||||
hass_admin_user: MockUser,
|
hass_admin_user: MockUser,
|
||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that user intents from custom_sentences have priority over builtin intents/sentences.
|
"""Test that user intents from custom_sentences have priority over builtin intents/sentences."""
|
||||||
|
|
||||||
Also test that they follow proper selection logic.
|
|
||||||
"""
|
|
||||||
with tempfile.NamedTemporaryFile(
|
with tempfile.NamedTemporaryFile(
|
||||||
mode="w+",
|
mode="w+",
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
@ -2618,11 +2615,7 @@ async def test_custom_sentences_priority(
|
|||||||
{
|
{
|
||||||
"language": "en",
|
"language": "en",
|
||||||
"intents": {
|
"intents": {
|
||||||
"CustomIntent": {"data": [{"sentences": ["turn on <name>"]}]},
|
"CustomIntent": {"data": [{"sentences": ["turn on the lamp"]}]}
|
||||||
"WorseCustomIntent": {
|
|
||||||
"data": [{"sentences": ["turn on the lamp"]}]
|
|
||||||
},
|
|
||||||
"FakeCustomIntent": {"data": [{"sentences": ["turn on <name>"]}]},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
custom_sentences_file,
|
custom_sentences_file,
|
||||||
@ -2639,21 +2632,11 @@ async def test_custom_sentences_priority(
|
|||||||
"intent_script",
|
"intent_script",
|
||||||
{
|
{
|
||||||
"intent_script": {
|
"intent_script": {
|
||||||
"CustomIntent": {"speech": {"text": "custom response"}},
|
"CustomIntent": {"speech": {"text": "custom response"}}
|
||||||
"WorseCustomIntent": {"speech": {"text": "worse custom response"}},
|
|
||||||
"FakeCustomIntent": {"speech": {"text": "fake custom response"}},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fake intent not being custom
|
|
||||||
intents = (
|
|
||||||
await conversation.async_get_agent(hass).async_get_or_load_intents(
|
|
||||||
hass.config.language
|
|
||||||
)
|
|
||||||
).intents.intents
|
|
||||||
intents["FakeCustomIntent"].data[0].metadata[METADATA_CUSTOM_SENTENCE] = False
|
|
||||||
|
|
||||||
# Ensure that a "lamp" exists so that we can verify the custom intent
|
# Ensure that a "lamp" exists so that we can verify the custom intent
|
||||||
# overrides the builtin sentence.
|
# overrides the builtin sentence.
|
||||||
hass.states.async_set("light.lamp", "off")
|
hass.states.async_set("light.lamp", "off")
|
||||||
@ -2676,7 +2659,10 @@ async def test_config_sentences_priority(
|
|||||||
hass_admin_user: MockUser,
|
hass_admin_user: MockUser,
|
||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that user intents from configuration.yaml have priority over builtin intents/sentences."""
|
"""Test that user intents from configuration.yaml have priority over builtin intents/sentences.
|
||||||
|
|
||||||
|
Also test that they follow proper selection logic.
|
||||||
|
"""
|
||||||
# Add a custom sentence that would match a builtin sentence.
|
# Add a custom sentence that would match a builtin sentence.
|
||||||
# Custom sentences have priority.
|
# Custom sentences have priority.
|
||||||
assert await async_setup_component(hass, "homeassistant", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
@ -2684,13 +2670,36 @@ async def test_config_sentences_priority(
|
|||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"conversation",
|
"conversation",
|
||||||
{"conversation": {"intents": {"CustomIntent": ["turn on the lamp"]}}},
|
{
|
||||||
|
"conversation": {
|
||||||
|
"intents": {
|
||||||
|
"CustomIntent": ["turn on <name>"],
|
||||||
|
"WorseCustomIntent": ["turn on the lamp"],
|
||||||
|
"FakeCustomIntent": ["turn on <name>"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Fake intent not being custom
|
||||||
|
intents = (
|
||||||
|
await conversation.async_get_agent(hass).async_get_or_load_intents(
|
||||||
|
hass.config.language
|
||||||
|
)
|
||||||
|
).intents.intents
|
||||||
|
intents["FakeCustomIntent"].data[0].metadata[METADATA_CUSTOM_SENTENCE] = False
|
||||||
|
|
||||||
assert await async_setup_component(hass, "light", {})
|
assert await async_setup_component(hass, "light", {})
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"intent_script",
|
"intent_script",
|
||||||
{"intent_script": {"CustomIntent": {"speech": {"text": "custom response"}}}},
|
{
|
||||||
|
"intent_script": {
|
||||||
|
"CustomIntent": {"speech": {"text": "custom response"}},
|
||||||
|
"WorseCustomIntent": {"speech": {"text": "worse custom response"}},
|
||||||
|
"FakeCustomIntent": {"speech": {"text": "fake custom response"}},
|
||||||
|
}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
# Ensure that a "lamp" exists so that we can verify the custom intent
|
# Ensure that a "lamp" exists so that we can verify the custom intent
|
||||||
|
Loading…
x
Reference in New Issue
Block a user