mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Explicitly pass in the config_entry in forecast_solar coordinator (#137824)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
0b1afc68b0
commit
5e99b06126
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
@ -12,14 +11,14 @@ from .const import (
|
|||||||
CONF_DAMPING_MORNING,
|
CONF_DAMPING_MORNING,
|
||||||
CONF_MODULES_POWER,
|
CONF_MODULES_POWER,
|
||||||
)
|
)
|
||||||
from .coordinator import ForecastSolarDataUpdateCoordinator
|
from .coordinator import ForecastSolarConfigEntry, ForecastSolarDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [Platform.SENSOR]
|
PLATFORMS = [Platform.SENSOR]
|
||||||
|
|
||||||
type ForecastSolarConfigEntry = ConfigEntry[ForecastSolarDataUpdateCoordinator]
|
|
||||||
|
|
||||||
|
async def async_migrate_entry(
|
||||||
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
hass: HomeAssistant, entry: ForecastSolarConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Migrate old config entry."""
|
"""Migrate old config entry."""
|
||||||
|
|
||||||
if entry.version == 1:
|
if entry.version == 1:
|
||||||
@ -53,11 +52,15 @@ async def async_setup_entry(
|
|||||||
return True
|
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."""
|
"""Unload a config entry."""
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
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."""
|
"""Update options."""
|
||||||
await hass.config_entries.async_reload(entry.entry_id)
|
await hass.config_entries.async_reload(entry.entry_id)
|
||||||
|
@ -23,15 +23,16 @@ from .const import (
|
|||||||
LOGGER,
|
LOGGER,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ForecastSolarConfigEntry = ConfigEntry[ForecastSolarDataUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class ForecastSolarDataUpdateCoordinator(DataUpdateCoordinator[Estimate]):
|
class ForecastSolarDataUpdateCoordinator(DataUpdateCoordinator[Estimate]):
|
||||||
"""The Forecast.Solar Data Update Coordinator."""
|
"""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."""
|
"""Initialize the Forecast.Solar coordinator."""
|
||||||
self.config_entry = entry
|
|
||||||
|
|
||||||
# Our option flow may cause it to be an empty string,
|
# Our option flow may cause it to be an empty string,
|
||||||
# this if statement is here to catch that.
|
# this if statement is here to catch that.
|
||||||
@ -61,7 +62,13 @@ class ForecastSolarDataUpdateCoordinator(DataUpdateCoordinator[Estimate]):
|
|||||||
if api_key is not None:
|
if api_key is not None:
|
||||||
update_interval = timedelta(minutes=30)
|
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:
|
async def _async_update_data(self) -> Estimate:
|
||||||
"""Fetch Forecast.Solar estimates."""
|
"""Fetch Forecast.Solar estimates."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user