Use reauth helpers in google_generative_ai_conversation (#128583)
This commit is contained in:
parent
420070a1ee
commit
536d702d96
1 changed files with 7 additions and 12 deletions
|
@ -15,6 +15,7 @@ import google.generativeai as genai
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_REAUTH,
|
||||
ConfigEntry,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
|
@ -85,10 +86,6 @@ class GoogleGenerativeAIConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
VERSION = 1
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize a new GoogleGenerativeAIConfigFlow."""
|
||||
self.reauth_entry: ConfigEntry | None = None
|
||||
|
||||
async def async_step_api(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
|
@ -106,9 +103,9 @@ class GoogleGenerativeAIConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
_LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
else:
|
||||
if self.reauth_entry:
|
||||
if self.source == SOURCE_REAUTH:
|
||||
return self.async_update_reload_and_abort(
|
||||
self.reauth_entry,
|
||||
self._get_reauth_entry(),
|
||||
data=user_input,
|
||||
)
|
||||
return self.async_create_entry(
|
||||
|
@ -135,9 +132,6 @@ class GoogleGenerativeAIConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle configuration by re-auth."""
|
||||
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
||||
self.context["entry_id"]
|
||||
)
|
||||
return await self.async_step_reauth_confirm()
|
||||
|
||||
async def async_step_reauth_confirm(
|
||||
|
@ -146,12 +140,13 @@ class GoogleGenerativeAIConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
"""Dialog that informs the user that reauth is required."""
|
||||
if user_input is not None:
|
||||
return await self.async_step_api()
|
||||
assert self.reauth_entry
|
||||
|
||||
reauth_entry = self._get_reauth_entry()
|
||||
return self.async_show_form(
|
||||
step_id="reauth_confirm",
|
||||
description_placeholders={
|
||||
CONF_NAME: self.reauth_entry.title,
|
||||
CONF_API_KEY: self.reauth_entry.data.get(CONF_API_KEY, ""),
|
||||
CONF_NAME: reauth_entry.title,
|
||||
CONF_API_KEY: reauth_entry.data.get(CONF_API_KEY, ""),
|
||||
},
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue