mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
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
This commit is contained in:
parent
c3977b5eb3
commit
311c321d06
@ -7,5 +7,5 @@
|
|||||||
"integration_type": "system",
|
"integration_type": "system",
|
||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"quality_scale": "internal",
|
"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"]
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ class AddItemIntent(intent.IntentHandler):
|
|||||||
await intent_obj.hass.data[DOMAIN].async_add(item)
|
await intent_obj.hass.data[DOMAIN].async_add(item)
|
||||||
|
|
||||||
response = intent_obj.create_response()
|
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)
|
intent_obj.hass.bus.async_fire(EVENT_SHOPPING_LIST_UPDATED)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -20,10 +20,10 @@ dbus-fast==1.87.2
|
|||||||
fnv-hash-fast==0.4.0
|
fnv-hash-fast==0.4.0
|
||||||
ha-av==10.1.0
|
ha-av==10.1.0
|
||||||
hass-nabucasa==0.69.0
|
hass-nabucasa==0.69.0
|
||||||
hassil==1.2.0
|
hassil==1.2.2
|
||||||
home-assistant-bluetooth==1.10.2
|
home-assistant-bluetooth==1.10.2
|
||||||
home-assistant-frontend==20230725.0
|
home-assistant-frontend==20230725.0
|
||||||
home-assistant-intents==2023.7.24
|
home-assistant-intents==2023.7.25
|
||||||
httpx==0.24.1
|
httpx==0.24.1
|
||||||
ifaddr==0.2.0
|
ifaddr==0.2.0
|
||||||
janus==1.0.0
|
janus==1.0.0
|
||||||
|
@ -955,7 +955,7 @@ hass-nabucasa==0.69.0
|
|||||||
hass-splunk==0.1.1
|
hass-splunk==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.conversation
|
# homeassistant.components.conversation
|
||||||
hassil==1.2.0
|
hassil==1.2.2
|
||||||
|
|
||||||
# homeassistant.components.jewish_calendar
|
# homeassistant.components.jewish_calendar
|
||||||
hdate==0.10.4
|
hdate==0.10.4
|
||||||
@ -988,7 +988,7 @@ holidays==0.28
|
|||||||
home-assistant-frontend==20230725.0
|
home-assistant-frontend==20230725.0
|
||||||
|
|
||||||
# homeassistant.components.conversation
|
# homeassistant.components.conversation
|
||||||
home-assistant-intents==2023.7.24
|
home-assistant-intents==2023.7.25
|
||||||
|
|
||||||
# homeassistant.components.home_connect
|
# homeassistant.components.home_connect
|
||||||
homeconnect==0.7.2
|
homeconnect==0.7.2
|
||||||
|
@ -750,7 +750,7 @@ habitipy==0.2.0
|
|||||||
hass-nabucasa==0.69.0
|
hass-nabucasa==0.69.0
|
||||||
|
|
||||||
# homeassistant.components.conversation
|
# homeassistant.components.conversation
|
||||||
hassil==1.2.0
|
hassil==1.2.2
|
||||||
|
|
||||||
# homeassistant.components.jewish_calendar
|
# homeassistant.components.jewish_calendar
|
||||||
hdate==0.10.4
|
hdate==0.10.4
|
||||||
@ -774,7 +774,7 @@ holidays==0.28
|
|||||||
home-assistant-frontend==20230725.0
|
home-assistant-frontend==20230725.0
|
||||||
|
|
||||||
# homeassistant.components.conversation
|
# homeassistant.components.conversation
|
||||||
home-assistant-intents==2023.7.24
|
home-assistant-intents==2023.7.25
|
||||||
|
|
||||||
# homeassistant.components.home_connect
|
# homeassistant.components.home_connect
|
||||||
homeconnect==0.7.2
|
homeconnect==0.7.2
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
"""Conversation test helpers."""
|
"""Conversation test helpers."""
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import conversation
|
from homeassistant.components import conversation
|
||||||
|
from homeassistant.components.shopping_list import intent as sl_intent
|
||||||
from homeassistant.const import MATCH_ALL
|
from homeassistant.const import MATCH_ALL
|
||||||
|
|
||||||
from . import MockAgent
|
from . import MockAgent
|
||||||
@ -28,3 +30,24 @@ def mock_agent_support_all(hass):
|
|||||||
agent = MockAgent(entry.entry_id, MATCH_ALL)
|
agent = MockAgent(entry.entry_id, MATCH_ALL)
|
||||||
conversation.async_set_agent(hass, entry, agent)
|
conversation.async_set_agent(hass, entry, agent)
|
||||||
return 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)
|
||||||
|
@ -265,3 +265,16 @@ async def test_trigger_sentences(hass: HomeAssistant, init_components) -> None:
|
|||||||
), sentence
|
), sentence
|
||||||
|
|
||||||
assert len(callback.mock_calls) == 0
|
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}
|
||||||
|
}
|
||||||
|
@ -34,7 +34,8 @@ async def test_add_item(hass: HomeAssistant, sl_setup) -> None:
|
|||||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "beer"}}
|
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:
|
async def test_remove_item(hass: HomeAssistant, sl_setup) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user