File tree Expand file tree Collapse file tree 3 files changed +116
-93
lines changed Expand file tree Collapse file tree 3 files changed +116
-93
lines changed Original file line number Diff line number Diff line change 16
16
17
17
async def async_setup_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
18
18
"""Set up IEC from a config entry."""
19
+ if DOMAIN not in hass .data :
20
+ hass .data [DOMAIN ] = {}
19
21
20
22
iec_coordinator = IecApiCoordinator (hass , entry )
21
- await iec_coordinator .async_config_entry_first_refresh ()
22
23
hass .data .setdefault (DOMAIN , {})[entry .entry_id ] = iec_coordinator
24
+ try :
25
+ await hass .data [DOMAIN ][entry .entry_id ].async_config_entry_first_refresh ()
26
+ except Exception as err :
27
+ # Log the error but don't fail the setup
28
+ _LOGGER .error ("Failed to fetch initial data: %s" , err )
23
29
24
30
await hass .config_entries .async_forward_entry_setups (entry , PLATFORMS )
25
31
@@ -40,6 +46,8 @@ async def handle_debug_get_coordinator_data(call) -> None: # noqa: ANN001 ARG00
40
46
async def async_unload_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
41
47
"""Unload a config entry."""
42
48
if unload_ok := await hass .config_entries .async_unload_platforms (entry , PLATFORMS ):
43
- hass .data [DOMAIN ].pop (entry .entry_id )
49
+ coordinator = hass .data [DOMAIN ].pop (entry .entry_id , None )
50
+ if coordinator :
51
+ await coordinator .async_unload ()
44
52
45
53
return unload_ok
You can’t perform that action at this time.
0 commit comments