Skip to content

Commit

Permalink
Trim the text of todo and shopping list items in intents (home-assist…
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam authored Oct 15, 2024
1 parent bb9f534 commit 36a1eae
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/shopping_list/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AddItemIntent(intent.IntentHandler):
async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse:
"""Handle the intent."""
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)

response = intent_obj.create_response()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/todo/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def async_handle(self, intent_obj: intent.Intent) -> intent.IntentResponse
hass = intent_obj.hass

slots = self.async_validate_slots(intent_obj.slots)
item = slots["item"]["value"]
item = slots["item"]["value"].strip()
list_name = slots["name"]["value"]

target_list: TodoListEntity | None = None
Expand Down
4 changes: 3 additions & 1 deletion tests/components/shopping_list/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ async def test_add_item(hass: HomeAssistant, sl_setup) -> None:
"""Test adding an item intent."""

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
assert response.response_type == intent.IntentResponseType.ACTION_DONE
Expand Down
4 changes: 2 additions & 2 deletions tests/components/todo/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ async def test_add_item_intent(
hass,
"test",
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,
)
assert response.response_type == intent.IntentResponseType.ACTION_DONE
Expand All @@ -1017,7 +1017,7 @@ async def test_add_item_intent(

assert len(entity1.items) == 1
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
entity1.items.clear()

Expand Down

0 comments on commit 36a1eae

Please sign in to comment.