Skip to content

Commit

Permalink
Add HassShoppingListAddItem to default agent (home-assistant#97232)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
synesthesiam authored Jul 26, 2023
1 parent c3977b5 commit 311c321
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/conversation/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
1 change: 0 additions & 1 deletion homeassistant/components/shopping_list/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/package_constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions tests/components/conversation/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
13 changes: 13 additions & 0 deletions tests/components/conversation/test_default_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
3 changes: 2 additions & 1 deletion tests/components/shopping_list/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 311c321

Please sign in to comment.