Trim the text of todo and shopping list items in intents (#128456)
parent
bb9f534259
commit
36a1eaedcf
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue