mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Explicitly pass in the config_entry in nyt_games coordinator (#138062)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
d66ac97c34
commit
7097faa950
@ -4,21 +4,17 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from nyt_games import NYTGamesClient
|
from nyt_games import NYTGamesClient
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_TOKEN, Platform
|
from homeassistant.const import CONF_TOKEN, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
||||||
|
|
||||||
from .coordinator import NYTGamesCoordinator
|
from .coordinator import NYTGamesConfigEntry, NYTGamesCoordinator
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [
|
PLATFORMS: list[Platform] = [
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
type NYTGamesConfigEntry = ConfigEntry[NYTGamesCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: NYTGamesConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: NYTGamesConfigEntry) -> bool:
|
||||||
"""Set up NYTGames from a config entry."""
|
"""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)
|
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()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
|
@ -4,18 +4,15 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from nyt_games import Connections, NYTGamesClient, NYTGamesError, SpellingBee, Wordle
|
from nyt_games import Connections, NYTGamesClient, NYTGamesError, SpellingBee, Wordle
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import LOGGER
|
from .const import LOGGER
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from . import NYTGamesConfigEntry
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class NYTGamesData:
|
class NYTGamesData:
|
||||||
@ -26,16 +23,25 @@ class NYTGamesData:
|
|||||||
connections: Connections | None
|
connections: Connections | None
|
||||||
|
|
||||||
|
|
||||||
|
type NYTGamesConfigEntry = ConfigEntry[NYTGamesCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class NYTGamesCoordinator(DataUpdateCoordinator[NYTGamesData]):
|
class NYTGamesCoordinator(DataUpdateCoordinator[NYTGamesData]):
|
||||||
"""Class to manage fetching NYT Games data."""
|
"""Class to manage fetching NYT Games data."""
|
||||||
|
|
||||||
config_entry: NYTGamesConfigEntry
|
config_entry: NYTGamesConfigEntry
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, client: NYTGamesClient) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: NYTGamesConfigEntry,
|
||||||
|
client: NYTGamesClient,
|
||||||
|
) -> None:
|
||||||
"""Initialize coordinator."""
|
"""Initialize coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
logger=LOGGER,
|
logger=LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name="NYT Games",
|
name="NYT Games",
|
||||||
update_interval=timedelta(minutes=15),
|
update_interval=timedelta(minutes=15),
|
||||||
)
|
)
|
||||||
|
@ -17,8 +17,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import NYTGamesConfigEntry
|
from .coordinator import NYTGamesConfigEntry, NYTGamesCoordinator
|
||||||
from .coordinator import NYTGamesCoordinator
|
|
||||||
from .entity import ConnectionsEntity, SpellingBeeEntity, WordleEntity
|
from .entity import ConnectionsEntity, SpellingBeeEntity, WordleEntity
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user