11"""The pvpc_hourly_pricing integration to collect Spain official electric prices."""
22
3- from homeassistant .config_entries import ConfigEntry
43from homeassistant .const import CONF_API_TOKEN , Platform
54from homeassistant .core import HomeAssistant
65from homeassistant .helpers import entity_registry as er
76
8- from .const import ATTR_POWER , ATTR_POWER_P3 , DOMAIN
9- from .coordinator import ElecPricesDataUpdateCoordinator
7+ from .const import ATTR_POWER , ATTR_POWER_P3
8+ from .coordinator import ElecPricesDataUpdateCoordinator , PVPCConfigEntry
109from .helpers import get_enabled_sensor_keys
1110
1211PLATFORMS : list [Platform ] = [Platform .SENSOR ]
1312
1413
15- async def async_setup_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
14+ async def async_setup_entry (hass : HomeAssistant , entry : PVPCConfigEntry ) -> bool :
1615 """Set up pvpc hourly pricing from a config entry."""
1716 entity_registry = er .async_get (hass )
1817 sensor_keys = get_enabled_sensor_keys (
@@ -22,13 +21,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
2221 coordinator = ElecPricesDataUpdateCoordinator (hass , entry , sensor_keys )
2322 await coordinator .async_config_entry_first_refresh ()
2423
25- hass . data . setdefault ( DOMAIN , {})[ entry .entry_id ] = coordinator
24+ entry .runtime_data = coordinator
2625 await hass .config_entries .async_forward_entry_setups (entry , PLATFORMS )
2726 entry .async_on_unload (entry .add_update_listener (async_update_options ))
2827 return True
2928
3029
31- async def async_update_options (hass : HomeAssistant , entry : ConfigEntry ) -> None :
30+ async def async_update_options (hass : HomeAssistant , entry : PVPCConfigEntry ) -> None :
3231 """Handle options update."""
3332 if any (
3433 entry .data .get (attrib ) != entry .options .get (attrib )
@@ -41,9 +40,6 @@ async def async_update_options(hass: HomeAssistant, entry: ConfigEntry) -> None:
4140 await hass .config_entries .async_reload (entry .entry_id )
4241
4342
44- async def async_unload_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
43+ async def async_unload_entry (hass : HomeAssistant , entry : PVPCConfigEntry ) -> bool :
4544 """Unload a config entry."""
46- unload_ok = await hass .config_entries .async_unload_platforms (entry , PLATFORMS )
47- if unload_ok :
48- hass .data [DOMAIN ].pop (entry .entry_id )
49- return unload_ok
45+ return await hass .config_entries .async_unload_platforms (entry , PLATFORMS )
0 commit comments