mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Use _get_reauth_entry in cloudflare config flow (#127385)
This commit is contained in:
parent
e2b1ef053f
commit
58f786f6d0
@ -10,7 +10,7 @@ import pycfdns
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import persistent_notification
|
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.const import CONF_API_TOKEN, CONF_ZONE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -77,8 +77,6 @@ class CloudflareConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize the Cloudflare config flow."""
|
"""Initialize the Cloudflare config flow."""
|
||||||
self.cloudflare_config: dict[str, Any] = {}
|
self.cloudflare_config: dict[str, Any] = {}
|
||||||
@ -89,7 +87,6 @@ class CloudflareConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle initiation of re-authentication with Cloudflare."""
|
"""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()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
@ -98,24 +95,19 @@ class CloudflareConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle re-authentication with Cloudflare."""
|
"""Handle re-authentication with Cloudflare."""
|
||||||
errors: dict[str, str] = {}
|
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)
|
_, errors = await self._async_validate_or_error(user_input)
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
self.hass.config_entries.async_update_entry(
|
reauth_entry = self._get_reauth_entry()
|
||||||
self.entry,
|
return self.async_update_reload_and_abort(
|
||||||
|
reauth_entry,
|
||||||
data={
|
data={
|
||||||
**self.entry.data,
|
**reauth_entry.data,
|
||||||
CONF_API_TOKEN: user_input[CONF_API_TOKEN],
|
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(
|
return self.async_show_form(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
data_schema=DATA_SCHEMA,
|
data_schema=DATA_SCHEMA,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user