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
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
@ -15,14 +14,12 @@ from .const import (
DEFAULT_HOME_LONGITUDE,
DOMAIN,
)
from .coordinator import MetDataUpdateCoordinator
from .coordinator import MetDataUpdateCoordinator, MetWeatherConfigEntry
PLATFORMS = [Platform.WEATHER]
_LOGGER = logging.getLogger(__name__)
type MetWeatherConfigEntry = ConfigEntry[MetDataUpdateCoordinator]
async def async_setup_entry(
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__)
type MetWeatherConfigEntry = ConfigEntry[MetDataUpdateCoordinator]
class CannotConnect(HomeAssistantError):
"""Unable to connect to the web site."""
@ -89,7 +91,11 @@ class MetWeatherData:
class MetDataUpdateCoordinator(DataUpdateCoordinator[MetWeatherData]):
"""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."""
self._unsub_track_home: Callable[[], None] | None = None
self.weather = MetWeatherData(hass, config_entry.data)
@ -97,7 +103,13 @@ class MetDataUpdateCoordinator(DataUpdateCoordinator[MetWeatherData]):
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:
"""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.util.unit_system import METRIC_SYSTEM
from . import MetWeatherConfigEntry
from .const import (
ATTR_CONDITION_CLEAR_NIGHT,
ATTR_CONDITION_SUNNY,
@ -47,7 +46,7 @@ from .const import (
DOMAIN,
FORECAST_MAP,
)
from .coordinator import MetDataUpdateCoordinator
from .coordinator import MetDataUpdateCoordinator, MetWeatherConfigEntry
DEFAULT_NAME = "Met.no"