mirror of
https://github.com/smkrv/ha-text-ai.git
synced 2026-07-31 09:23:55 +08:00
Update config_flow.py
This commit is contained in:
@@ -6,8 +6,7 @@ from typing import Any
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from openai import AsyncOpenAI
|
from openai import AsyncOpenAI
|
||||||
from openai import OpenAIError # Updated import
|
from openai import OpenAIError, AuthenticationError, APIConnectionError
|
||||||
from openai.exceptions import AuthenticationError, APIConnectionError
|
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@@ -25,16 +24,10 @@ from .const import (
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@config_entries.HANDLERS.register(DOMAIN)
|
|
||||||
class TextAIConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class TextAIConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for HA Text AI Integration."""
|
"""Handle a config flow for HA Text AI Integration."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
"""Initialize the config flow."""
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
@@ -86,8 +79,8 @@ class TextAIConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
raise ApiKeyError from err
|
raise ApiKeyError from err
|
||||||
except APIConnectionError as err:
|
except APIConnectionError as err:
|
||||||
raise ApiConnectionError from err
|
raise ApiConnectionError from err
|
||||||
except OpenAIError as err: # Changed from APIError
|
except OpenAIError as err:
|
||||||
if getattr(err, 'status_code', None) == 401: # Safe status_code check
|
if getattr(err, 'status_code', None) == 401:
|
||||||
raise ApiKeyError from err
|
raise ApiKeyError from err
|
||||||
raise ApiConnectionError from err
|
raise ApiConnectionError from err
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user