|
12 | 12 | import yaml |
13 | 13 |
|
14 | 14 | from homeassistant.components import conversation, cover, media_player, weather |
15 | | -from homeassistant.components.conversation import default_agent |
16 | | -from homeassistant.components.conversation.const import DATA_DEFAULT_ENTITY |
| 15 | +from homeassistant.components.conversation import async_get_agent, default_agent |
17 | 16 | from homeassistant.components.conversation.default_agent import METADATA_CUSTOM_SENTENCE |
18 | 17 | from homeassistant.components.conversation.models import ConversationInput |
19 | 18 | from homeassistant.components.cover import SERVICE_OPEN_COVER |
@@ -87,7 +86,8 @@ async def init_components(hass: HomeAssistant) -> None: |
87 | 86 | assert await async_setup_component(hass, "intent", {}) |
88 | 87 |
|
89 | 88 | # Disable fuzzy matching by default for tests |
90 | | - agent = hass.data[DATA_DEFAULT_ENTITY] |
| 89 | + agent = async_get_agent(hass) |
| 90 | + assert isinstance(agent, default_agent.DefaultAgent) |
91 | 91 | agent.fuzzy_matching = False |
92 | 92 |
|
93 | 93 |
|
@@ -215,7 +215,7 @@ async def test_exposed_areas( |
215 | 215 | @pytest.mark.usefixtures("init_components") |
216 | 216 | async def test_conversation_agent(hass: HomeAssistant) -> None: |
217 | 217 | """Test DefaultAgent.""" |
218 | | - agent = hass.data[DATA_DEFAULT_ENTITY] |
| 218 | + agent = async_get_agent(hass) |
219 | 219 | with patch( |
220 | 220 | "homeassistant.components.conversation.default_agent.get_languages", |
221 | 221 | return_value=["dwarvish", "elvish", "entish"], |
@@ -415,8 +415,7 @@ async def test_trigger_sentences(hass: HomeAssistant) -> None: |
415 | 415 | trigger_sentences = ["It's party time", "It is time to party"] |
416 | 416 | trigger_response = "Cowabunga!" |
417 | 417 |
|
418 | | - agent = hass.data[DATA_DEFAULT_ENTITY] |
419 | | - assert isinstance(agent, default_agent.DefaultAgent) |
| 418 | + agent = async_get_agent(hass) |
420 | 419 |
|
421 | 420 | callback = AsyncMock(return_value=trigger_response) |
422 | 421 | unregister = agent.register_trigger(trigger_sentences, callback) |
@@ -462,8 +461,7 @@ async def test_trigger_sentence_response_translation( |
462 | 461 | """Test translation of default response 'done'.""" |
463 | 462 | hass.config.language = language |
464 | 463 |
|
465 | | - agent = hass.data[DATA_DEFAULT_ENTITY] |
466 | | - assert isinstance(agent, default_agent.DefaultAgent) |
| 464 | + agent = async_get_agent(hass) |
467 | 465 |
|
468 | 466 | translations = { |
469 | 467 | "en": {"component.conversation.conversation.agent.done": "English done"}, |
@@ -2525,8 +2523,7 @@ async def test_non_default_response(hass: HomeAssistant, init_components) -> Non |
2525 | 2523 | hass.states.async_set("cover.front_door", "closed") |
2526 | 2524 | calls = async_mock_service(hass, "cover", SERVICE_OPEN_COVER) |
2527 | 2525 |
|
2528 | | - agent = hass.data[DATA_DEFAULT_ENTITY] |
2529 | | - assert isinstance(agent, default_agent.DefaultAgent) |
| 2526 | + agent = async_get_agent(hass) |
2530 | 2527 |
|
2531 | 2528 | result = await agent.async_process( |
2532 | 2529 | ConversationInput( |
@@ -2872,8 +2869,7 @@ async def test_query_same_name_different_areas( |
2872 | 2869 | @pytest.mark.usefixtures("init_components") |
2873 | 2870 | async def test_intent_cache_exposed(hass: HomeAssistant) -> None: |
2874 | 2871 | """Test that intent recognition results are cached for exposed entities.""" |
2875 | | - agent = hass.data[DATA_DEFAULT_ENTITY] |
2876 | | - assert isinstance(agent, default_agent.DefaultAgent) |
| 2872 | + agent = async_get_agent(hass) |
2877 | 2873 |
|
2878 | 2874 | entity_id = "light.test_light" |
2879 | 2875 | hass.states.async_set(entity_id, "off") |
@@ -2912,8 +2908,7 @@ async def test_intent_cache_exposed(hass: HomeAssistant) -> None: |
2912 | 2908 | @pytest.mark.usefixtures("init_components") |
2913 | 2909 | async def test_intent_cache_all_entities(hass: HomeAssistant) -> None: |
2914 | 2910 | """Test that intent recognition results are cached for all entities.""" |
2915 | | - agent = hass.data[DATA_DEFAULT_ENTITY] |
2916 | | - assert isinstance(agent, default_agent.DefaultAgent) |
| 2911 | + agent = async_get_agent(hass) |
2917 | 2912 |
|
2918 | 2913 | entity_id = "light.test_light" |
2919 | 2914 | hass.states.async_set(entity_id, "off") |
@@ -2952,8 +2947,7 @@ async def test_intent_cache_all_entities(hass: HomeAssistant) -> None: |
2952 | 2947 | @pytest.mark.usefixtures("init_components") |
2953 | 2948 | async def test_intent_cache_fuzzy(hass: HomeAssistant) -> None: |
2954 | 2949 | """Test that intent recognition results are cached for fuzzy matches.""" |
2955 | | - agent = hass.data[DATA_DEFAULT_ENTITY] |
2956 | | - assert isinstance(agent, default_agent.DefaultAgent) |
| 2950 | + agent = async_get_agent(hass) |
2957 | 2951 |
|
2958 | 2952 | # There is no entity named test light |
2959 | 2953 | user_input = ConversationInput( |
@@ -2982,8 +2976,7 @@ async def test_intent_cache_fuzzy(hass: HomeAssistant) -> None: |
2982 | 2976 | @pytest.mark.usefixtures("init_components") |
2983 | 2977 | async def test_entities_filtered_by_input(hass: HomeAssistant) -> None: |
2984 | 2978 | """Test that entities are filtered by the input text before intent matching.""" |
2985 | | - agent = hass.data[DATA_DEFAULT_ENTITY] |
2986 | | - assert isinstance(agent, default_agent.DefaultAgent) |
| 2979 | + agent = async_get_agent(hass) |
2987 | 2980 |
|
2988 | 2981 | # Only the switch is exposed |
2989 | 2982 | hass.states.async_set("light.test_light", "off") |
@@ -3165,7 +3158,7 @@ async def test_handle_intents_with_response_errors( |
3165 | 3158 | assert await async_setup_component(hass, "climate", {}) |
3166 | 3159 | area_registry.async_create("living room") |
3167 | 3160 |
|
3168 | | - agent: default_agent.DefaultAgent = hass.data[DATA_DEFAULT_ENTITY] |
| 3161 | + agent = async_get_agent(hass) |
3169 | 3162 |
|
3170 | 3163 | user_input = ConversationInput( |
3171 | 3164 | text="What is the temperature in the living room?", |
@@ -3203,7 +3196,7 @@ async def test_handle_intents_filters_results( |
3203 | 3196 | assert await async_setup_component(hass, "climate", {}) |
3204 | 3197 | area_registry.async_create("living room") |
3205 | 3198 |
|
3206 | | - agent: default_agent.DefaultAgent = hass.data[DATA_DEFAULT_ENTITY] |
| 3199 | + agent = async_get_agent(hass) |
3207 | 3200 |
|
3208 | 3201 | user_input = ConversationInput( |
3209 | 3202 | text="What is the temperature in the living room?", |
@@ -3363,7 +3356,7 @@ async def test_fuzzy_matching( |
3363 | 3356 | assert await async_setup_component(hass, "intent", {}) |
3364 | 3357 | await light_intent.async_setup_intents(hass) |
3365 | 3358 |
|
3366 | | - agent = hass.data[DATA_DEFAULT_ENTITY] |
| 3359 | + agent = async_get_agent(hass) |
3367 | 3360 | agent.fuzzy_matching = fuzzy_matching |
3368 | 3361 |
|
3369 | 3362 | area_office = area_registry.async_get_or_create("office_id") |
|
0 commit comments