Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Define an object to manage fetching NYT Games data."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 from datetime import timedelta
7 from typing import TYPE_CHECKING
8 
9 from nyt_games import Connections, NYTGamesClient, NYTGamesError, SpellingBee, Wordle
10 
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
13 
14 from .const import LOGGER
15 
16 if TYPE_CHECKING:
17  from . import NYTGamesConfigEntry
18 
19 
20 @dataclass
22  """Class for NYT Games data."""
23 
24  wordle: Wordle
25  spelling_bee: SpellingBee | None
26  connections: Connections | None
27 
28 
30  """Class to manage fetching NYT Games data."""
31 
32  config_entry: NYTGamesConfigEntry
33 
34  def __init__(self, hass: HomeAssistant, client: NYTGamesClient) -> None:
35  """Initialize coordinator."""
36  super().__init__(
37  hass,
38  logger=LOGGER,
39  name="NYT Games",
40  update_interval=timedelta(minutes=15),
41  )
42  self.clientclient = client
43 
44  async def _async_update_data(self) -> NYTGamesData:
45  try:
46  stats_data = await self.clientclient.get_latest_stats()
47  connections_data = await self.clientclient.get_connections()
48  except NYTGamesError as error:
49  raise UpdateFailed(error) from error
50  return NYTGamesData(
51  wordle=stats_data.wordle,
52  spelling_bee=stats_data.spelling_bee,
53  connections=connections_data,
54  )
None __init__(self, HomeAssistant hass, NYTGamesClient client)
Definition: coordinator.py:34