from __future__ import annotations from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from .const import DOMAIN from .coordinator import EaseeSolarCoordinator PLATFORMS = ["sensor", "switch"] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: coordinator = EaseeSolarCoordinator(hass, entry) await coordinator.async_config_entry_first_refresh() hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) # Full reload on options change so coordinator and entity state are rebuilt cleanly. entry.async_on_unload(entry.add_update_listener(_async_options_updated)) return True async def _async_options_updated(hass: HomeAssistant, entry: ConfigEntry) -> None: await hass.config_entries.async_reload(entry.entry_id) async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: """Called by HA when the user presses Reload in the UI.""" await async_unload_entry(hass, entry) await async_setup_entry(hass, entry) async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) return unload_ok