From 58f786f6d0f00b7f7695cfc730666026244ea7b6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:56:54 +0200 Subject: [PATCH] Use _get_reauth_entry in cloudflare config flow (#127385) --- .../components/cloudflare/config_flow.py | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/cloudflare/config_flow.py b/homeassistant/components/cloudflare/config_flow.py index 704e4c0fd47..a4276cf9dd3 100644 --- a/homeassistant/components/cloudflare/config_flow.py +++ b/homeassistant/components/cloudflare/config_flow.py @@ -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,