mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Use runtime_data in epic_games_store (#136709)
This commit is contained in:
parent
8300fd2de8
commit
1f35451863
@ -2,34 +2,29 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import EGSCalendarUpdateCoordinator
|
||||
from .coordinator import EGSCalendarUpdateCoordinator, EGSConfigEntry
|
||||
|
||||
PLATFORMS: list[Platform] = [
|
||||
Platform.CALENDAR,
|
||||
]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: EGSConfigEntry) -> bool:
|
||||
"""Set up Epic Games Store from a config entry."""
|
||||
|
||||
coordinator = EGSCalendarUpdateCoordinator(hass, entry)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
||||
entry.runtime_data = coordinator
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: EGSConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -7,25 +7,24 @@ from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN, CalendarType
|
||||
from .coordinator import EGSCalendarUpdateCoordinator
|
||||
from .coordinator import EGSCalendarUpdateCoordinator, EGSConfigEntry
|
||||
|
||||
DateRange = namedtuple("DateRange", ["start", "end"]) # noqa: PYI024
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: EGSConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the local calendar platform."""
|
||||
coordinator: EGSCalendarUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
entities = [
|
||||
EGSCalendar(coordinator, entry.entry_id, CalendarType.FREE),
|
||||
|
@ -20,13 +20,15 @@ SCAN_INTERVAL = timedelta(days=1)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type EGSConfigEntry = ConfigEntry[EGSCalendarUpdateCoordinator]
|
||||
|
||||
|
||||
class EGSCalendarUpdateCoordinator(
|
||||
DataUpdateCoordinator[dict[str, list[dict[str, Any]]]]
|
||||
):
|
||||
"""Class to manage fetching data from the Epic Game Store."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
def __init__(self, hass: HomeAssistant, entry: EGSConfigEntry) -> None:
|
||||
"""Initialize."""
|
||||
self._api = EpicGamesStoreAPI(
|
||||
entry.data[CONF_LANGUAGE],
|
||||
@ -37,6 +39,7 @@ class EGSCalendarUpdateCoordinator(
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
config_entry=entry,
|
||||
name=DOMAIN,
|
||||
update_interval=SCAN_INTERVAL,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user