Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The NYT Games integration."""
2 
3 from __future__ import annotations
4 
5 from nyt_games import NYTGamesClient
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import CONF_TOKEN, Platform
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.aiohttp_client import async_create_clientsession
11 
12 from .coordinator import NYTGamesCoordinator
13 
14 PLATFORMS: list[Platform] = [
15  Platform.SENSOR,
16 ]
17 
18 
19 type NYTGamesConfigEntry = ConfigEntry[NYTGamesCoordinator]
20 
21 
22 async def async_setup_entry(hass: HomeAssistant, entry: NYTGamesConfigEntry) -> bool:
23  """Set up NYTGames from a config entry."""
24 
25  client = NYTGamesClient(
26  entry.data[CONF_TOKEN], session=async_create_clientsession(hass)
27  )
28 
29  coordinator = NYTGamesCoordinator(hass, client)
30 
31  await coordinator.async_config_entry_first_refresh()
32 
33  entry.runtime_data = coordinator
34 
35  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
36 
37  return True
38 
39 
40 async def async_unload_entry(hass: HomeAssistant, entry: NYTGamesConfigEntry) -> bool:
41  """Unload a config entry."""
42  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, NYTGamesConfigEntry entry)
Definition: __init__.py:22
bool async_unload_entry(HomeAssistant hass, NYTGamesConfigEntry entry)
Definition: __init__.py:40
aiohttp.ClientSession async_create_clientsession()
Definition: coordinator.py:51