Use _get_reauth_entry in cloudflare config flow (#127385)
parent
e2b1ef053f
commit
58f786f6d0
|
@ -10,7 +10,7 @@ import pycfdns
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_API_TOKEN, CONF_ZONE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
@ -77,8 +77,6 @@ class CloudflareConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
VERSION = 1
|
||||
|
||||
entry: ConfigEntry | None = None
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the Cloudflare config flow."""
|
||||
self.cloudflare_config: dict[str, Any] = {}
|
||||
|
@ -89,7 +87,6 @@ class CloudflareConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle initiation of re-authentication with Cloudflare."""
|
||||
self.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(
|
||||
|
@ -98,24 +95,19 @@ class CloudflareConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
"""Handle re-authentication with Cloudflare."""
|
||||
errors: dict[str, str] = {}
|
||||
|
||||
if user_input is not None and self.entry:
|
||||
if user_input is not None:
|
||||
_, errors = await self._async_validate_or_error(user_input)
|
||||
|
||||
if not errors:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self.entry,
|
||||
reauth_entry = self._get_reauth_entry()
|
||||
return self.async_update_reload_and_abort(
|
||||
reauth_entry,
|
||||
data={
|
||||
**self.entry.data,
|
||||
**reauth_entry.data,
|
||||
CONF_API_TOKEN: user_input[CONF_API_TOKEN],
|
||||
},
|
||||
)
|
||||
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.async_reload(self.entry.entry_id)
|
||||
)
|
||||
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="reauth_confirm",
|
||||
data_schema=DATA_SCHEMA,
|
||||
|
|
Loading…
Reference in New Issue