Explicitly pass in the config_entry in nyt_games coordinator (#138062)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-09 16:33:24 +01:00 committed by GitHub
parent d66ac97c34
commit 7097faa950
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 13 deletions

View File

@ -4,21 +4,17 @@ from __future__ import annotations
from nyt_games import NYTGamesClient
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_TOKEN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from .coordinator import NYTGamesCoordinator
from .coordinator import NYTGamesConfigEntry, NYTGamesCoordinator
PLATFORMS: list[Platform] = [
Platform.SENSOR,
]
type NYTGamesConfigEntry = ConfigEntry[NYTGamesCoordinator]
async def async_setup_entry(hass: HomeAssistant, entry: NYTGamesConfigEntry) -> bool:
"""Set up NYTGames from a config entry."""
@ -26,7 +22,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: NYTGamesConfigEntry) ->
entry.data[CONF_TOKEN], session=async_create_clientsession(hass)
)
coordinator = NYTGamesCoordinator(hass, client)
coordinator = NYTGamesCoordinator(hass, entry, client)
await coordinator.async_config_entry_first_refresh()

View File

@ -4,18 +4,15 @@ from __future__ import annotations
from dataclasses import dataclass
from datetime import timedelta
from typing import TYPE_CHECKING
from nyt_games import Connections, NYTGamesClient, NYTGamesError, SpellingBee, Wordle
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import LOGGER
if TYPE_CHECKING:
from . import NYTGamesConfigEntry
@dataclass
class NYTGamesData:
@ -26,16 +23,25 @@ class NYTGamesData:
connections: Connections | None
type NYTGamesConfigEntry = ConfigEntry[NYTGamesCoordinator]
class NYTGamesCoordinator(DataUpdateCoordinator[NYTGamesData]):
"""Class to manage fetching NYT Games data."""
config_entry: NYTGamesConfigEntry
def __init__(self, hass: HomeAssistant, client: NYTGamesClient) -> None:
def __init__(
self,
hass: HomeAssistant,
config_entry: NYTGamesConfigEntry,
client: NYTGamesClient,
) -> None:
"""Initialize coordinator."""
super().__init__(
hass,
logger=LOGGER,
config_entry=config_entry,
name="NYT Games",
update_interval=timedelta(minutes=15),
)

View File

@ -17,8 +17,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from . import NYTGamesConfigEntry
from .coordinator import NYTGamesCoordinator
from .coordinator import NYTGamesConfigEntry, NYTGamesCoordinator
from .entity import ConnectionsEntity, SpellingBeeEntity, WordleEntity