Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Coordinator for fetching data from Google Tasks API."""
2 
3 import asyncio
4 import datetime
5 import logging
6 from typing import Any, Final
7 
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
10 
11 from .api import AsyncConfigEntryAuth
12 
13 _LOGGER = logging.getLogger(__name__)
14 
15 UPDATE_INTERVAL: Final = datetime.timedelta(minutes=30)
16 TIMEOUT = 10
17 
18 
19 class TaskUpdateCoordinator(DataUpdateCoordinator[list[dict[str, Any]]]):
20  """Coordinator for fetching Google Tasks for a Task List form the API."""
21 
22  def __init__(
23  self, hass: HomeAssistant, api: AsyncConfigEntryAuth, task_list_id: str
24  ) -> None:
25  """Initialize TaskUpdateCoordinator."""
26  super().__init__(
27  hass,
28  _LOGGER,
29  name=f"Google Tasks {task_list_id}",
30  update_interval=UPDATE_INTERVAL,
31  )
32  self.apiapi = api
33  self._task_list_id_task_list_id = task_list_id
34 
35  async def _async_update_data(self) -> list[dict[str, Any]]:
36  """Fetch tasks from API endpoint."""
37  async with asyncio.timeout(TIMEOUT):
38  return await self.apiapi.list_tasks(self._task_list_id_task_list_id)
None __init__(self, HomeAssistant hass, AsyncConfigEntryAuth api, str task_list_id)
Definition: coordinator.py:24