diff --git a/homeassistant/components/ourgroceries/coordinator.py b/homeassistant/components/ourgroceries/coordinator.py index a4b594c7e86..636ebcc300a 100644 --- a/homeassistant/components/ourgroceries/coordinator.py +++ b/homeassistant/components/ourgroceries/coordinator.py @@ -1,6 +1,7 @@ """The OurGroceries coordinator.""" from __future__ import annotations +import asyncio from datetime import timedelta import logging @@ -25,6 +26,7 @@ class OurGroceriesDataUpdateCoordinator(DataUpdateCoordinator[dict[str, dict]]): """Initialize global OurGroceries data updater.""" self.og = og self.lists = lists + self._ids = [sl["id"] for sl in lists] interval = timedelta(seconds=SCAN_INTERVAL) super().__init__( hass, @@ -35,7 +37,11 @@ class OurGroceriesDataUpdateCoordinator(DataUpdateCoordinator[dict[str, dict]]): async def _async_update_data(self) -> dict[str, dict]: """Fetch data from OurGroceries.""" - return { - sl["id"]: (await self.og.get_list_items(list_id=sl["id"])) - for sl in self.lists - } + return dict( + zip( + self._ids, + await asyncio.gather( + *[self.og.get_list_items(list_id=id) for id in self._ids] + ), + ) + ) diff --git a/homeassistant/components/ourgroceries/strings.json b/homeassistant/components/ourgroceries/strings.json index 96dc8b371d1..78a46954183 100644 --- a/homeassistant/components/ourgroceries/strings.json +++ b/homeassistant/components/ourgroceries/strings.json @@ -12,9 +12,6 @@ "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", "unknown": "[%key:common::config_flow::error::unknown%]" - }, - "abort": { - "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" } } } diff --git a/homeassistant/components/ourgroceries/todo.py b/homeassistant/components/ourgroceries/todo.py index 98029b09ba8..8115066d0fb 100644 --- a/homeassistant/components/ourgroceries/todo.py +++ b/homeassistant/components/ourgroceries/todo.py @@ -1,6 +1,7 @@ """A todo platform for OurGroceries.""" import asyncio +from typing import Any from homeassistant.components.todo import ( TodoItem, @@ -28,6 +29,12 @@ async def async_setup_entry( ) +def _completion_status(item: dict[str, Any]) -> TodoItemStatus: + if item.get("crossedOffAt", False): + return TodoItemStatus.COMPLETED + return TodoItemStatus.NEEDS_ACTION + + class OurGroceriesTodoListEntity( CoordinatorEntity[OurGroceriesDataUpdateCoordinator], TodoListEntity ): @@ -58,12 +65,6 @@ class OurGroceriesTodoListEntity( if self.coordinator.data is None: self._attr_todo_items = None else: - - def _completion_status(item): - if item.get("crossedOffAt", False): - return TodoItemStatus.COMPLETED - return TodoItemStatus.NEEDS_ACTION - self._attr_todo_items = [ TodoItem( summary=item["name"],