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 1616
1717async def async_setup_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
1818 """Set up IEC from a config entry."""
19+ if DOMAIN not in hass .data :
20+ hass .data [DOMAIN ] = {}
1921
2022 iec_coordinator = IecApiCoordinator (hass , entry )
21- await iec_coordinator .async_config_entry_first_refresh ()
2223 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 )
2329
2430 await hass .config_entries .async_forward_entry_setups (entry , PLATFORMS )
2531
@@ -40,6 +46,8 @@ async def handle_debug_get_coordinator_data(call) -> None: # noqa: ANN001 ARG00
4046async def async_unload_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
4147 """Unload a config entry."""
4248 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 ()
4452
4553 return unload_ok
You can’t perform that action at this time.
0 commit comments