Explicitly pass in the config_entry in met coordinator (#138091)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-09 17:33:52 +01:00 committed by GitHub
parent bd3eec90ba
commit c8f035b5c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 8 deletions

View File

@ -4,7 +4,6 @@ from __future__ import annotations
import logging import logging
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 from homeassistant.helpers import device_registry as dr
@ -15,14 +14,12 @@ from .const import (
DEFAULT_HOME_LONGITUDE, DEFAULT_HOME_LONGITUDE,
DOMAIN, DOMAIN,
) )
from .coordinator import MetDataUpdateCoordinator from .coordinator import MetDataUpdateCoordinator, MetWeatherConfigEntry
PLATFORMS = [Platform.WEATHER] PLATFORMS = [Platform.WEATHER]
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
type MetWeatherConfigEntry = ConfigEntry[MetDataUpdateCoordinator]
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, config_entry: MetWeatherConfigEntry hass: HomeAssistant, config_entry: MetWeatherConfigEntry

View File

@ -31,6 +31,8 @@ URL = "https://aa015h6buqvih86i1.api.met.no/weatherapi/locationforecast/2.0/comp
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
type MetWeatherConfigEntry = ConfigEntry[MetDataUpdateCoordinator]
class CannotConnect(HomeAssistantError): class CannotConnect(HomeAssistantError):
"""Unable to connect to the web site.""" """Unable to connect to the web site."""
@ -89,7 +91,11 @@ class MetWeatherData:
class MetDataUpdateCoordinator(DataUpdateCoordinator[MetWeatherData]): class MetDataUpdateCoordinator(DataUpdateCoordinator[MetWeatherData]):
"""Class to manage fetching Met data.""" """Class to manage fetching Met data."""
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None: config_entry: MetWeatherConfigEntry
def __init__(
self, hass: HomeAssistant, config_entry: MetWeatherConfigEntry
) -> None:
"""Initialize global Met data updater.""" """Initialize global Met data updater."""
self._unsub_track_home: Callable[[], None] | None = None self._unsub_track_home: Callable[[], None] | None = None
self.weather = MetWeatherData(hass, config_entry.data) self.weather = MetWeatherData(hass, config_entry.data)
@ -97,7 +103,13 @@ class MetDataUpdateCoordinator(DataUpdateCoordinator[MetWeatherData]):
update_interval = timedelta(minutes=randrange(55, 65)) update_interval = timedelta(minutes=randrange(55, 65))
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=update_interval) super().__init__(
hass,
_LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=update_interval,
)
async def _async_update_data(self) -> MetWeatherData: async def _async_update_data(self) -> MetWeatherData:
"""Fetch data from Met.""" """Fetch data from Met."""

View File

@ -37,7 +37,6 @@ from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.unit_system import METRIC_SYSTEM from homeassistant.util.unit_system import METRIC_SYSTEM
from . import MetWeatherConfigEntry
from .const import ( from .const import (
ATTR_CONDITION_CLEAR_NIGHT, ATTR_CONDITION_CLEAR_NIGHT,
ATTR_CONDITION_SUNNY, ATTR_CONDITION_SUNNY,
@ -47,7 +46,7 @@ from .const import (
DOMAIN, DOMAIN,
FORECAST_MAP, FORECAST_MAP,
) )
from .coordinator import MetDataUpdateCoordinator from .coordinator import MetDataUpdateCoordinator, MetWeatherConfigEntry
DEFAULT_NAME = "Met.no" DEFAULT_NAME = "Met.no"