mirror of
https://github.com/home-assistant/core.git
synced 2026-09-10 02:35:27 -05:00
Add conversation reload service (#86175)
* Add preload and reload service calls to conversation * Add conversation preload/reload to websocket API * Merge prepare into reload * reload service and prepare websocket API * Add preload and reload service calls to conversation * Add conversation preload/reload to websocket API * Merge prepare into reload * reload service and prepare websocket API * Add language lock for loading intents * Add more tests for code coverage
This commit is contained in:
@@ -329,6 +329,34 @@ async def test_ws_api(hass, hass_ws_client, payload):
|
||||
}
|
||||
|
||||
|
||||
# pylint: disable=protected-access
|
||||
async def test_ws_prepare(hass, hass_ws_client):
|
||||
"""Test the Websocket prepare conversation API."""
|
||||
assert await async_setup_component(hass, "conversation", {})
|
||||
agent = await conversation._get_agent(hass)
|
||||
assert isinstance(agent, conversation.DefaultAgent)
|
||||
|
||||
# No intents should be loaded yet
|
||||
assert not agent._lang_intents.get(hass.config.language)
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
await client.send_json(
|
||||
{
|
||||
"id": 5,
|
||||
"type": "conversation/prepare",
|
||||
}
|
||||
)
|
||||
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert msg["success"]
|
||||
assert msg["id"] == 5
|
||||
|
||||
# Intents should now be load
|
||||
assert agent._lang_intents.get(hass.config.language)
|
||||
|
||||
|
||||
async def test_custom_sentences(hass, hass_client, hass_admin_user):
|
||||
"""Test custom sentences with a custom intent."""
|
||||
assert await async_setup_component(hass, "homeassistant", {})
|
||||
@@ -367,3 +395,39 @@ async def test_custom_sentences(hass, hass_client, hass_admin_user):
|
||||
},
|
||||
"conversation_id": None,
|
||||
}
|
||||
|
||||
|
||||
# pylint: disable=protected-access
|
||||
async def test_prepare_reload(hass):
|
||||
"""Test calling the reload service."""
|
||||
language = hass.config.language
|
||||
assert await async_setup_component(hass, "conversation", {})
|
||||
|
||||
# Load intents
|
||||
agent = await conversation._get_agent(hass)
|
||||
assert isinstance(agent, conversation.DefaultAgent)
|
||||
await agent.async_prepare(language)
|
||||
|
||||
# Confirm intents are loaded
|
||||
assert agent._lang_intents.get(language)
|
||||
|
||||
# Clear cache
|
||||
await hass.services.async_call("conversation", "reload", {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Confirm intent cache is cleared
|
||||
assert not agent._lang_intents.get(language)
|
||||
|
||||
|
||||
# pylint: disable=protected-access
|
||||
async def test_prepare_fail(hass):
|
||||
"""Test calling prepare with a non-existent language."""
|
||||
assert await async_setup_component(hass, "conversation", {})
|
||||
|
||||
# Load intents
|
||||
agent = await conversation._get_agent(hass)
|
||||
assert isinstance(agent, conversation.DefaultAgent)
|
||||
await agent.async_prepare("not-a-language")
|
||||
|
||||
# Confirm no intents were loaded
|
||||
assert not agent._lang_intents.get("not-a-language")
|
||||
|
||||
Reference in New Issue
Block a user