mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
Trim the text of todo and shopping list items in intents (#128456)
This commit is contained in:
parent
bb9f534259
commit
36a1eaedcf
@ -29,7 +29,7 @@ class AddItemIntent(intent.IntentHandler):
|
|||||||
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
|
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
|
||||||
"""Handle the intent."""
|
"""Handle the intent."""
|
||||||
slots = self.async_validate_slots(intent_obj.slots)
|
slots = self.async_validate_slots(intent_obj.slots)
|
||||||
item = slots["item"]["value"]
|
item = slots["item"]["value"].strip()
|
||||||
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()
|
||||||
|
@ -34,7 +34,7 @@ class ListAddItemIntent(intent.IntentHandler):
|
|||||||
hass = intent_obj.hass
|
hass = intent_obj.hass
|
||||||
|
|
||||||
slots = self.async_validate_slots(intent_obj.slots)
|
slots = self.async_validate_slots(intent_obj.slots)
|
||||||
item = slots["item"]["value"]
|
item = slots["item"]["value"].strip()
|
||||||
list_name = slots["name"]["value"]
|
list_name = slots["name"]["value"]
|
||||||
|
|
||||||
target_list: TodoListEntity | None = None
|
target_list: TodoListEntity | None = None
|
||||||
|
@ -32,8 +32,10 @@ async def test_add_item(hass: HomeAssistant, sl_setup) -> None:
|
|||||||
"""Test adding an item intent."""
|
"""Test adding an item intent."""
|
||||||
|
|
||||||
response = await intent.async_handle(
|
response = await intent.async_handle(
|
||||||
hass, "test", "HassShoppingListAddItem", {"item": {"value": "beer"}}
|
hass, "test", "HassShoppingListAddItem", {"item": {"value": " beer "}}
|
||||||
)
|
)
|
||||||
|
assert len(hass.data[DOMAIN].items) == 1
|
||||||
|
assert hass.data[DOMAIN].items[0]["name"] == "beer" # name was trimmed
|
||||||
|
|
||||||
# Response text is now handled by default conversation agent
|
# Response text is now handled by default conversation agent
|
||||||
assert response.response_type == intent.IntentResponseType.ACTION_DONE
|
assert response.response_type == intent.IntentResponseType.ACTION_DONE
|
||||||
|
@ -1007,7 +1007,7 @@ async def test_add_item_intent(
|
|||||||
hass,
|
hass,
|
||||||
"test",
|
"test",
|
||||||
todo_intent.INTENT_LIST_ADD_ITEM,
|
todo_intent.INTENT_LIST_ADD_ITEM,
|
||||||
{ATTR_ITEM: {"value": "beer"}, "name": {"value": "list 1"}},
|
{ATTR_ITEM: {"value": " beer "}, "name": {"value": "list 1"}},
|
||||||
assistant=conversation.DOMAIN,
|
assistant=conversation.DOMAIN,
|
||||||
)
|
)
|
||||||
assert response.response_type == intent.IntentResponseType.ACTION_DONE
|
assert response.response_type == intent.IntentResponseType.ACTION_DONE
|
||||||
@ -1017,7 +1017,7 @@ async def test_add_item_intent(
|
|||||||
|
|
||||||
assert len(entity1.items) == 1
|
assert len(entity1.items) == 1
|
||||||
assert len(entity2.items) == 0
|
assert len(entity2.items) == 0
|
||||||
assert entity1.items[0].summary == "beer"
|
assert entity1.items[0].summary == "beer" # summary is trimmed
|
||||||
assert entity1.items[0].status == TodoItemStatus.NEEDS_ACTION
|
assert entity1.items[0].status == TodoItemStatus.NEEDS_ACTION
|
||||||
entity1.items.clear()
|
entity1.items.clear()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user