diff --git a/homeassistant/components/shopping_list/intent.py b/homeassistant/components/shopping_list/intent.py index 84ea3971293..1a6370f4168 100644 --- a/homeassistant/components/shopping_list/intent.py +++ b/homeassistant/components/shopping_list/intent.py @@ -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() diff --git a/homeassistant/components/todo/intent.py b/homeassistant/components/todo/intent.py index cb7fde3e366..c678408a576 100644 --- a/homeassistant/components/todo/intent.py +++ b/homeassistant/components/todo/intent.py @@ -34,7 +34,7 @@ class ListAddItemIntent(intent.IntentHandler): 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 diff --git a/tests/components/shopping_list/test_init.py b/tests/components/shopping_list/test_init.py index 4e758764e3d..276602f794e 100644 --- a/tests/components/shopping_list/test_init.py +++ b/tests/components/shopping_list/test_init.py @@ -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 diff --git a/tests/components/todo/test_init.py b/tests/components/todo/test_init.py index 16e5647ebb3..fd052a7f8a3 100644 --- a/tests/components/todo/test_init.py +++ b/tests/components/todo/test_init.py @@ -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 @@ -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()