mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Explicitly pass in the config_entry in gios coordinator (#137832)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
b22830260c
commit
d97ef67620
@ -2,32 +2,21 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
|
||||
from homeassistant.components.air_quality import DOMAIN as AIR_QUALITY_PLATFORM
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import CONF_STATION_ID, DOMAIN
|
||||
from .coordinator import GiosDataUpdateCoordinator
|
||||
from .coordinator import GiosConfigEntry, GiosData, GiosDataUpdateCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = [Platform.SENSOR]
|
||||
|
||||
type GiosConfigEntry = ConfigEntry[GiosData]
|
||||
|
||||
|
||||
@dataclass
|
||||
class GiosData:
|
||||
"""Data for GIOS integration."""
|
||||
|
||||
coordinator: GiosDataUpdateCoordinator
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: GiosConfigEntry) -> bool:
|
||||
"""Set up GIOS as config entry."""
|
||||
@ -48,7 +37,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: GiosConfigEntry) -> bool
|
||||
|
||||
websession = async_get_clientsession(hass)
|
||||
|
||||
coordinator = GiosDataUpdateCoordinator(hass, websession, station_id)
|
||||
coordinator = GiosDataUpdateCoordinator(hass, entry, websession, station_id)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
entry.runtime_data = GiosData(coordinator)
|
||||
|
@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
|
||||
from aiohttp import ClientSession
|
||||
@ -11,6 +12,7 @@ from gios import Gios
|
||||
from gios.exceptions import GiosError
|
||||
from gios.model import GiosSensors
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
@ -18,17 +20,38 @@ from .const import API_TIMEOUT, DOMAIN, SCAN_INTERVAL
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type GiosConfigEntry = ConfigEntry[GiosData]
|
||||
|
||||
|
||||
@dataclass
|
||||
class GiosData:
|
||||
"""Data for GIOS integration."""
|
||||
|
||||
coordinator: GiosDataUpdateCoordinator
|
||||
|
||||
|
||||
class GiosDataUpdateCoordinator(DataUpdateCoordinator[GiosSensors]):
|
||||
"""Define an object to hold GIOS data."""
|
||||
|
||||
config_entry: GiosConfigEntry
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, session: ClientSession, station_id: int
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: GiosConfigEntry,
|
||||
session: ClientSession,
|
||||
station_id: int,
|
||||
) -> None:
|
||||
"""Class to manage fetching GIOS data API."""
|
||||
self.gios = Gios(station_id, session)
|
||||
|
||||
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL)
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
config_entry=config_entry,
|
||||
name=DOMAIN,
|
||||
update_interval=SCAN_INTERVAL,
|
||||
)
|
||||
|
||||
async def _async_update_data(self) -> GiosSensors:
|
||||
"""Update data via library."""
|
||||
|
@ -7,7 +7,7 @@ from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import GiosConfigEntry
|
||||
from .coordinator import GiosConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
|
@ -23,7 +23,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import GiosConfigEntry
|
||||
from .const import (
|
||||
ATTR_AQI,
|
||||
ATTR_C6H6,
|
||||
@ -38,7 +37,7 @@ from .const import (
|
||||
MANUFACTURER,
|
||||
URL,
|
||||
)
|
||||
from .coordinator import GiosDataUpdateCoordinator
|
||||
from .coordinator import GiosConfigEntry, GiosDataUpdateCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user