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