Explicitly pass in the config_entry in weatherflow_cloud coordinator (#137871)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-08 21:58:33 +01:00 committed by GitHub
parent a2a55d9ff0
commit 52fb99f967
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 7 deletions

View File

@ -3,7 +3,7 @@
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_TOKEN, Platform
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from .const import DOMAIN
@ -15,10 +15,7 @@ PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.WEATHER]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up WeatherFlowCloud from a config entry."""
data_coordinator = WeatherFlowCloudDataUpdateCoordinator(
hass=hass,
api_token=entry.data[CONF_API_TOKEN],
)
data_coordinator = WeatherFlowCloudDataUpdateCoordinator(hass, entry)
await data_coordinator.async_config_entry_first_refresh()
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = data_coordinator

View File

@ -6,6 +6,8 @@ from aiohttp import ClientResponseError
from weatherflow4py.api import WeatherFlowRestAPI
from weatherflow4py.models.rest.unified import WeatherFlowDataREST
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_TOKEN
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
@ -18,12 +20,17 @@ class WeatherFlowCloudDataUpdateCoordinator(
):
"""Class to manage fetching REST Based WeatherFlow Forecast data."""
def __init__(self, hass: HomeAssistant, api_token: str) -> None:
config_entry: ConfigEntry
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Initialize global WeatherFlow forecast data updater."""
self.weather_api = WeatherFlowRestAPI(api_token=api_token)
self.weather_api = WeatherFlowRestAPI(
api_token=config_entry.data[CONF_API_TOKEN]
)
super().__init__(
hass,
LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=timedelta(seconds=60),
)