mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Explicitly pass in the config_entry in weatherflow_cloud coordinator (#137871)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
a2a55d9ff0
commit
52fb99f967
@ -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
|
||||
|
@ -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),
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user