mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Explicitly pass in the config_entry in PEGELONLINE coordinator init (#136773)
This commit is contained in:
parent
177bb29f69
commit
032e17720c
@ -7,21 +7,18 @@ import logging
|
||||
from aiopegelonline import PegelOnline
|
||||
from aiopegelonline.const import CONNECT_ERRORS
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import CONF_STATION
|
||||
from .coordinator import PegelOnlineDataUpdateCoordinator
|
||||
from .coordinator import PegelOnlineConfigEntry, PegelOnlineDataUpdateCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = [Platform.SENSOR]
|
||||
|
||||
type PegelOnlineConfigEntry = ConfigEntry[PegelOnlineDataUpdateCoordinator]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: PegelOnlineConfigEntry) -> bool:
|
||||
"""Set up PEGELONLINE entry."""
|
||||
@ -35,7 +32,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: PegelOnlineConfigEntry)
|
||||
except CONNECT_ERRORS as err:
|
||||
raise ConfigEntryNotReady("Failed to connect") from err
|
||||
|
||||
coordinator = PegelOnlineDataUpdateCoordinator(hass, entry.title, api, station)
|
||||
coordinator = PegelOnlineDataUpdateCoordinator(hass, entry, api, station)
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
@ -46,6 +43,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: PegelOnlineConfigEntry)
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant, entry: PegelOnlineConfigEntry
|
||||
) -> bool:
|
||||
"""Unload PEGELONLINE entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -4,6 +4,7 @@ import logging
|
||||
|
||||
from aiopegelonline import CONNECT_ERRORS, PegelOnline, Station, StationMeasurements
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
@ -11,12 +12,20 @@ from .const import DOMAIN, MIN_TIME_BETWEEN_UPDATES
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type PegelOnlineConfigEntry = ConfigEntry[PegelOnlineDataUpdateCoordinator]
|
||||
|
||||
|
||||
class PegelOnlineDataUpdateCoordinator(DataUpdateCoordinator[StationMeasurements]):
|
||||
"""DataUpdateCoordinator for the pegel_online integration."""
|
||||
|
||||
config_entry: PegelOnlineConfigEntry
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, name: str, api: PegelOnline, station: Station
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: PegelOnlineConfigEntry,
|
||||
api: PegelOnline,
|
||||
station: Station,
|
||||
) -> None:
|
||||
"""Initialize the PegelOnlineDataUpdateCoordinator."""
|
||||
self.api = api
|
||||
@ -24,7 +33,8 @@ class PegelOnlineDataUpdateCoordinator(DataUpdateCoordinator[StationMeasurements
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=name,
|
||||
config_entry=config_entry,
|
||||
name=config_entry.title,
|
||||
update_interval=MIN_TIME_BETWEEN_UPDATES,
|
||||
)
|
||||
|
||||
|
@ -6,7 +6,7 @@ from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import PegelOnlineConfigEntry
|
||||
from .coordinator import PegelOnlineConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
|
@ -16,8 +16,7 @@ from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import PegelOnlineConfigEntry
|
||||
from .coordinator import PegelOnlineDataUpdateCoordinator
|
||||
from .coordinator import PegelOnlineConfigEntry, PegelOnlineDataUpdateCoordinator
|
||||
from .entity import PegelOnlineEntity
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user