mirror of
https://github.com/smkrv/ha-text-ai.git
synced 2026-07-29 12:23:55 +08:00
fix: Address code review findings for v2.4.0
- Fix 404 accepted as valid API response in config_flow validation (both ConfigFlow and OptionsFlow) - Sanitize catch-all exception in config_flow (str(e) → "unknown" error key) - Add exception chaining (from err) to ConfigEntryNotReady raise - Replace datetime.now() with dt_util.utcnow() for HA timezone convention - Add defensive raise after retry loop in api_client._make_request - Remove unused CONF_API_KEY/CONF_NAME imports from const.py - Restore google-genai dependency in manifest (required for Gemini provider)
This commit is contained in:
@@ -306,7 +306,7 @@ class HATextAIConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
vol.Required(CONF_API_ENDPOINT, default=input_copy.get(CONF_API_ENDPOINT, get_default_endpoint(self._provider))): str,
|
||||
# Other fields remain the same
|
||||
}),
|
||||
errors={"base": str(e)}
|
||||
errors={"base": "unknown"}
|
||||
)
|
||||
|
||||
# All validation passed, create the entry
|
||||
@@ -378,7 +378,7 @@ class HATextAIConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
if response.status == 401:
|
||||
self._errors["base"] = "invalid_auth"
|
||||
return False
|
||||
elif response.status not in [200, 404]:
|
||||
elif response.status != 200:
|
||||
self._errors["base"] = "cannot_connect"
|
||||
return False
|
||||
return True
|
||||
@@ -514,7 +514,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||
if response.status == 401:
|
||||
self._errors["base"] = "invalid_auth"
|
||||
return False
|
||||
elif response.status not in [200, 404]:
|
||||
elif response.status != 200:
|
||||
self._errors["base"] = "cannot_connect"
|
||||
return False
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user