22from .constants import DOMAIN , PLATFORMS
33
44from homeassistant .core import HomeAssistant , SupportsResponse
5- from homeassistant .helpers . typing import ConfigType
5+ from homeassistant .config_entries import ConfigEntry
66from homeassistant .helpers import service
7+ from homeassistant .helpers .typing import ConfigType
78from homeassistant .helpers .update_coordinator import (
89 CoordinatorEntity ,
910)
11+ import homeassistant .helpers .config_validation as cv
1012
1113import voluptuous as vol
12- import homeassistant .helpers .config_validation as cv
1314import logging
1415
1516from .coordinator import new_coordinator
1617
1718_LOGGER = logging .getLogger (__name__ )
1819
19-
2020CONFIG_SCHEMA = vol .Schema ({
2121 DOMAIN : vol .Schema ({
2222 }),
@@ -28,19 +28,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
2828
2929 device = new_coordinator (hass , data , hass .data [DOMAIN ]['devices' ])
3030
31+ hass .data [DOMAIN ]['devices' ][entry .entry_id ] = device # Backward compatibility
32+ entry .runtime_data = device # New style
33+
3134 await device .coordinator .async_config_entry_first_refresh ()
32- hass .data [DOMAIN ]['devices' ][entry .entry_id ] = device
33- for p in PLATFORMS :
34- hass .async_create_task (
35- hass .config_entries .async_forward_entry_setup (entry , p )
36- )
35+ await hass .config_entries .async_forward_entry_setups (entry , PLATFORMS )
36+
3737 return True
3838
3939
4040async def async_unload_entry (hass : HomeAssistant , entry : ConfigEntry ):
41- for p in PLATFORMS :
42- await hass .config_entries .async_forward_entry_unload (entry , p )
41+ await hass .config_entries .async_unload_platforms (entry , PLATFORMS )
42+
43+ entry .runtime_data = None
4344 hass .data [DOMAIN ]['devices' ].pop (entry .entry_id )
45+
4446 return True
4547
4648
0 commit comments