From 311c321d06269da0b9c1f52abb7312ee8d4dae4f Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Tue, 25 Jul 2023 21:19:03 -0500 Subject: [PATCH] Add HassShoppingListAddItem to default agent (#97232) * Bump hassil and intents package for HassShoppingListAddItem * Remove hard-coded response text * Test adding item to the shopping list * Hook removed import in test for some reason --- .../components/conversation/manifest.json | 2 +- .../components/shopping_list/intent.py | 1 - homeassistant/package_constraints.txt | 4 ++-- requirements_all.txt | 4 ++-- requirements_test_all.txt | 4 ++-- tests/components/conversation/conftest.py | 23 +++++++++++++++++++ .../conversation/test_default_agent.py | 13 +++++++++++ tests/components/shopping_list/test_init.py | 3 ++- 8 files changed, 45 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/conversation/manifest.json b/homeassistant/components/conversation/manifest.json index 65b12b64e58a21..a8f24a335f07c7 100644 --- a/homeassistant/components/conversation/manifest.json +++ b/homeassistant/components/conversation/manifest.json @@ -7,5 +7,5 @@ "integration_type": "system", "iot_class": "local_push", "quality_scale": "internal", - "requirements": ["hassil==1.2.0", "home-assistant-intents==2023.7.24"] + "requirements": ["hassil==1.2.2", "home-assistant-intents==2023.7.25"] } diff --git a/homeassistant/components/shopping_list/intent.py b/homeassistant/components/shopping_list/intent.py index c709322e0b7db0..d6a29eb73f364c 100644 --- a/homeassistant/components/shopping_list/intent.py +++ b/homeassistant/components/shopping_list/intent.py @@ -29,7 +29,6 @@ async def async_handle(self, intent_obj: intent.Intent): await intent_obj.hass.data[DOMAIN].async_add(item) response = intent_obj.create_response() - response.async_set_speech(f"I've added {item} to your shopping list") intent_obj.hass.bus.async_fire(EVENT_SHOPPING_LIST_UPDATED) return response diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index cf576fc1c837a9..a9239bcfda8890 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -20,10 +20,10 @@ dbus-fast==1.87.2 fnv-hash-fast==0.4.0 ha-av==10.1.0 hass-nabucasa==0.69.0 -hassil==1.2.0 +hassil==1.2.2 home-assistant-bluetooth==1.10.2 home-assistant-frontend==20230725.0 -home-assistant-intents==2023.7.24 +home-assistant-intents==2023.7.25 httpx==0.24.1 ifaddr==0.2.0 janus==1.0.0 diff --git a/requirements_all.txt b/requirements_all.txt index 92d3ae94fb1494..a51c0e57a6d7f7 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -955,7 +955,7 @@ hass-nabucasa==0.69.0 hass-splunk==0.1.1 # homeassistant.components.conversation -hassil==1.2.0 +hassil==1.2.2 # homeassistant.components.jewish_calendar hdate==0.10.4 @@ -988,7 +988,7 @@ holidays==0.28 home-assistant-frontend==20230725.0 # homeassistant.components.conversation -home-assistant-intents==2023.7.24 +home-assistant-intents==2023.7.25 # homeassistant.components.home_connect homeconnect==0.7.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index d10f29c5374233..b2d39c0d7877e8 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -750,7 +750,7 @@ habitipy==0.2.0 hass-nabucasa==0.69.0 # homeassistant.components.conversation -hassil==1.2.0 +hassil==1.2.2 # homeassistant.components.jewish_calendar hdate==0.10.4 @@ -774,7 +774,7 @@ holidays==0.28 home-assistant-frontend==20230725.0 # homeassistant.components.conversation -home-assistant-intents==2023.7.24 +home-assistant-intents==2023.7.25 # homeassistant.components.home_connect homeconnect==0.7.2 diff --git a/tests/components/conversation/conftest.py b/tests/components/conversation/conftest.py index 85d5b5daa910e3..a08823255e9d1d 100644 --- a/tests/components/conversation/conftest.py +++ b/tests/components/conversation/conftest.py @@ -1,8 +1,10 @@ """Conversation test helpers.""" +from unittest.mock import patch import pytest from homeassistant.components import conversation +from homeassistant.components.shopping_list import intent as sl_intent from homeassistant.const import MATCH_ALL from . import MockAgent @@ -28,3 +30,24 @@ def mock_agent_support_all(hass): agent = MockAgent(entry.entry_id, MATCH_ALL) conversation.async_set_agent(hass, entry, agent) return agent + + +@pytest.fixture(autouse=True) +def mock_shopping_list_io(): + """Stub out the persistence.""" + with patch("homeassistant.components.shopping_list.ShoppingData.save"), patch( + "homeassistant.components.shopping_list.ShoppingData.async_load" + ): + yield + + +@pytest.fixture +async def sl_setup(hass): + """Set up the shopping list.""" + + entry = MockConfigEntry(domain="shopping_list") + entry.add_to_hass(hass) + + assert await hass.config_entries.async_setup(entry.entry_id) + + await sl_intent.async_setup_intents(hass) diff --git a/tests/components/conversation/test_default_agent.py b/tests/components/conversation/test_default_agent.py index 899fd761d5ebf8..af9af468453ee4 100644 --- a/tests/components/conversation/test_default_agent.py +++ b/tests/components/conversation/test_default_agent.py @@ -265,3 +265,16 @@ async def test_trigger_sentences(hass: HomeAssistant, init_components) -> None: ), sentence assert len(callback.mock_calls) == 0 + + +async def test_shopping_list_add_item( + hass: HomeAssistant, init_components, sl_setup +) -> None: + """Test adding an item to the shopping list through the default agent.""" + result = await conversation.async_converse( + hass, "add apples to my shopping list", None, Context() + ) + assert result.response.response_type == intent.IntentResponseType.ACTION_DONE + assert result.response.speech == { + "plain": {"speech": "Added apples", "extra_data": None} + } diff --git a/tests/components/shopping_list/test_init.py b/tests/components/shopping_list/test_init.py index e5f1e30efdb3e3..a28b1ee0cfbbd0 100644 --- a/tests/components/shopping_list/test_init.py +++ b/tests/components/shopping_list/test_init.py @@ -34,7 +34,8 @@ async def test_add_item(hass: HomeAssistant, sl_setup) -> None: hass, "test", "HassShoppingListAddItem", {"item": {"value": "beer"}} ) - assert response.speech["plain"]["speech"] == "I've added beer to your shopping list" + # Response text is now handled by default conversation agent + assert response.response_type == intent.IntentResponseType.ACTION_DONE async def test_remove_item(hass: HomeAssistant, sl_setup) -> None: