diff --git a/homeassistant/components/pegel_online/__init__.py b/homeassistant/components/pegel_online/__init__.py index 30e5f4d2a38..1c71603e41e 100644 --- a/homeassistant/components/pegel_online/__init__.py +++ b/homeassistant/components/pegel_online/__init__.py @@ -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) diff --git a/homeassistant/components/pegel_online/coordinator.py b/homeassistant/components/pegel_online/coordinator.py index c8233673fde..1e2471a59f2 100644 --- a/homeassistant/components/pegel_online/coordinator.py +++ b/homeassistant/components/pegel_online/coordinator.py @@ -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, ) diff --git a/homeassistant/components/pegel_online/diagnostics.py b/homeassistant/components/pegel_online/diagnostics.py index b68437c5ee7..e3b4a166cb4 100644 --- a/homeassistant/components/pegel_online/diagnostics.py +++ b/homeassistant/components/pegel_online/diagnostics.py @@ -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( diff --git a/homeassistant/components/pegel_online/sensor.py b/homeassistant/components/pegel_online/sensor.py index 50eb80bafa8..181c0f5dc6d 100644 --- a/homeassistant/components/pegel_online/sensor.py +++ b/homeassistant/components/pegel_online/sensor.py @@ -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