From 5e99b061260e8f3496ce9f97e0885f1b79806166 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Sat, 8 Feb 2025 13:16:03 +0100 Subject: [PATCH] Explicitly pass in the config_entry in forecast_solar coordinator (#137824) explicitly pass in the config_entry in coordinator --- .../components/forecast_solar/__init__.py | 17 ++++++++++------- .../components/forecast_solar/coordinator.py | 15 +++++++++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/forecast_solar/__init__.py b/homeassistant/components/forecast_solar/__init__.py index 00be13f1235..171341f7226 100644 --- a/homeassistant/components/forecast_solar/__init__.py +++ b/homeassistant/components/forecast_solar/__init__.py @@ -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) diff --git a/homeassistant/components/forecast_solar/coordinator.py b/homeassistant/components/forecast_solar/coordinator.py index c9c062a0c88..efed954e490 100644 --- a/homeassistant/components/forecast_solar/coordinator.py +++ b/homeassistant/components/forecast_solar/coordinator.py @@ -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."""