@@ -109,59 +109,41 @@ async def async_setup_entry(hass: HomeAssistant, entry: AIHubConfigEntry) -> boo
109109 """Set up AI Hub from a config entry."""
110110
111111 # Get API key (may be None if not provided)
112+ # No startup validation - each entity validates on actual use
112113 api_key = get_configured_api_key (entry )
113114
114- # Validate API key by testing API connection only if provided
115- if api_key and api_key .strip ():
116- try :
117- from .config_flow_validation import validate_input
118-
119- await validate_input (hass , {CONF_API_KEY : api_key })
120- except aiohttp .ClientError as err :
121- _LOGGER .error ("Failed to connect to API: %s" , err )
122- raise ConfigEntryNotReady (f"Failed to connect: { err } " ) from err
123- except ValueError as err :
124- reason = str (err )
125- if reason == "invalid_auth" :
126- raise ConfigEntryAuthFailed ("Invalid API key" ) from err
127- if reason == "cannot_connect" :
128- raise ConfigEntryNotReady ("API test failed" ) from err
129- if reason .startswith ("cannot_connect:" ):
130- detail = reason .split (":" , 1 )[1 ].strip ()
131- raise ConfigEntryNotReady (f"API test failed: { detail } " ) from err
132- _LOGGER .error ("API validation failed: %s" , err )
133- raise ConfigEntryNotReady (f"API validation failed: { err } " ) from err
134- except ConfigEntryAuthFailed :
135- raise
136- except Exception as err :
137- _LOGGER .error ("API validation failed: %s" , err )
138- raise ConfigEntryNotReady (f"API validation failed: { err } " ) from err
139-
140115 # Initialize runtime data in hass.data
141116 ai_hub_data = get_or_create_ai_hub_data (hass )
142117 ai_hub_data .api_key = api_key
143118
144119 # Store in entry.runtime_data
145120 entry .runtime_data = api_key
146121
147- # Sync auto-generated intent lists before loading local intent config
148- from .intents .loader import async_sync_intent_lists
149- await async_sync_intent_lists (hass )
150-
151- # Set up intent handlers
152- from .intents import async_setup_intents
153- await async_setup_intents (hass )
154-
155- # Set up services
156- from .services import async_setup_services
157- await async_setup_services (hass , entry )
158-
159- # Forward setup to platforms last. If any initialization above fails and Home
160- # Assistant retries the config entry, delaying platform setup prevents the
161- # entity component from seeing the same entry as already configured.
162- _LOGGER .debug ("Setting up AI Hub platforms: %s" , PLATFORMS )
163- await hass .config_entries .async_forward_entry_setups (entry , PLATFORMS )
164- _LOGGER .debug ("Platforms setup completed" )
122+ # Each step is independent - one failure does not block others
123+ try :
124+ from .intents .loader import async_sync_intent_lists
125+ await async_sync_intent_lists (hass )
126+ except Exception as err :
127+ _LOGGER .warning ("Intent list sync failed (non-fatal): %s" , err )
128+
129+ try :
130+ from .intents import async_setup_intents
131+ await async_setup_intents (hass )
132+ except Exception as err :
133+ _LOGGER .warning ("Intent handlers setup failed (non-fatal): %s" , err )
134+
135+ try :
136+ from .services import async_setup_services
137+ await async_setup_services (hass , entry )
138+ except Exception as err :
139+ _LOGGER .warning ("Services setup failed (non-fatal): %s" , err )
140+
141+ # Forward setup to platforms individually - one failure should not block others
142+ for platform in PLATFORMS :
143+ try :
144+ await hass .config_entries .async_forward_entry_setups (entry , [platform ])
145+ except Exception as err :
146+ _LOGGER .warning ("Platform %s setup failed (others continue): %s" , platform , err )
165147
166148 # Listen for options updates
167149 entry .async_on_unload (entry .add_update_listener (async_update_options ))
@@ -182,9 +164,15 @@ async def async_unload_entry(hass: HomeAssistant, entry: AIHubConfigEntry) -> bo
182164 if config_entry .entry_id != entry .entry_id
183165 ]
184166
185- unload_ok = await hass .config_entries .async_unload_platforms (entry , PLATFORMS )
186- if not unload_ok :
187- return False
167+ all_ok = True
168+ for platform in PLATFORMS :
169+ try :
170+ if not await hass .config_entries .async_unload_platforms (entry , [platform ]):
171+ _LOGGER .warning ("Failed to unload platform %s" , platform )
172+ all_ok = False
173+ except Exception as err :
174+ _LOGGER .warning ("Error unloading platform %s: %s" , platform , err )
175+ all_ok = False
188176
189177 from .services import async_unload_services
190178 await async_unload_services (hass , entry .entry_id )
@@ -195,7 +183,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: AIHubConfigEntry) -> bo
195183 ai_hub_data .cleanup ()
196184 hass .data .pop (DOMAIN , None )
197185
198- return True
186+ return all_ok
199187
200188
201189async def async_migrate_entry (hass : HomeAssistant , entry : ConfigEntry ) -> bool :
0 commit comments