Trim the text of todo and shopping list items in intents (#128456)

pull/128470/head
Michael Hansen 2024-10-15 10:44:32 -05:00 committed by GitHub
parent bb9f534259
commit 36a1eaedcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 7 additions and 5 deletions

View File

@ -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()

View File

@ -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

View File

@ -34,6 +34,8 @@ async def test_add_item(hass: HomeAssistant, sl_setup) -> None:
response = await intent.async_handle(
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

View File

@ -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()