Fix update of uncategorized OurGroceries items (#105255)

* Fix update of uncategorized OurGroceries items

* Address code review comments
This commit is contained in:
On Freund 2023-12-07 23:11:08 +02:00 committed by GitHub
parent 8a4b761c78
commit c4d77877d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -89,7 +89,7 @@ class OurGroceriesTodoListEntity(
if item.summary:
api_items = self.coordinator.data[self._list_id]["list"]["items"]
category = next(
api_item["categoryId"]
api_item.get("categoryId")
for api_item in api_items
if api_item["id"] == item.uid
)

View file

@ -142,12 +142,20 @@ async def test_update_todo_item_status(
@pytest.mark.parametrize(
("items"), [[{"id": "12345", "name": "Soda", "categoryId": "test_category"}]]
("items", "category"),
[
(
[{"id": "12345", "name": "Soda", "categoryId": "test_category"}],
"test_category",
),
([{"id": "12345", "name": "Uncategorized"}], None),
],
)
async def test_update_todo_item_summary(
hass: HomeAssistant,
setup_integration: None,
ourgroceries: AsyncMock,
category: str | None,
) -> None:
"""Test for updating an item summary."""
@ -171,7 +179,7 @@ async def test_update_todo_item_summary(
)
assert ourgroceries.change_item_on_list
args = ourgroceries.change_item_on_list.call_args
assert args.args == ("test_list", "12345", "test_category", "Milk")
assert args.args == ("test_list", "12345", category, "Milk")
@pytest.mark.parametrize(