Explicitly pass in the config_entry in forecast_solar coordinator (#137824)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-08 13:16:03 +01:00 committed by GitHub
parent 0b1afc68b0
commit 5e99b06126
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 11 deletions

View File

@ -2,7 +2,6 @@
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
@ -12,14 +11,14 @@ from .const import (
CONF_DAMPING_MORNING,
CONF_MODULES_POWER,
)
from .coordinator import ForecastSolarDataUpdateCoordinator
from .coordinator import ForecastSolarConfigEntry, ForecastSolarDataUpdateCoordinator
PLATFORMS = [Platform.SENSOR]
type ForecastSolarConfigEntry = ConfigEntry[ForecastSolarDataUpdateCoordinator]
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_migrate_entry(
hass: HomeAssistant, entry: ForecastSolarConfigEntry
) -> bool:
"""Migrate old config entry."""
if entry.version == 1:
@ -53,11 +52,15 @@ async def async_setup_entry(
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(
hass: HomeAssistant, entry: ForecastSolarConfigEntry
) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
async def async_update_options(hass: HomeAssistant, entry: ConfigEntry) -> None:
async def async_update_options(
hass: HomeAssistant, entry: ForecastSolarConfigEntry
) -> None:
"""Update options."""
await hass.config_entries.async_reload(entry.entry_id)

View File

@ -23,15 +23,16 @@ from .const import (
LOGGER,
)
type ForecastSolarConfigEntry = ConfigEntry[ForecastSolarDataUpdateCoordinator]
class ForecastSolarDataUpdateCoordinator(DataUpdateCoordinator[Estimate]):
"""The Forecast.Solar Data Update Coordinator."""
config_entry: ConfigEntry
config_entry: ForecastSolarConfigEntry
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
def __init__(self, hass: HomeAssistant, entry: ForecastSolarConfigEntry) -> None:
"""Initialize the Forecast.Solar coordinator."""
self.config_entry = entry
# Our option flow may cause it to be an empty string,
# this if statement is here to catch that.
@ -61,7 +62,13 @@ class ForecastSolarDataUpdateCoordinator(DataUpdateCoordinator[Estimate]):
if api_key is not None:
update_interval = timedelta(minutes=30)
super().__init__(hass, LOGGER, name=DOMAIN, update_interval=update_interval)
super().__init__(
hass,
LOGGER,
config_entry=entry,
name=DOMAIN,
update_interval=update_interval,
)
async def _async_update_data(self) -> Estimate:
"""Fetch Forecast.Solar estimates."""