OurGroceries review comments (#104606)
parent
360ef894a7
commit
ba33ad6b18
|
@ -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]
|
||||
),
|
||||
)
|
||||
)
|
||||
|
|
|
@ -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%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"],
|
||||
|
|
Loading…
Reference in New Issue