From c634f6067a58d6d5e61d87a237ab1a862df4c2e7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:48:09 +0200 Subject: [PATCH] Use reauth helpers in caldav config flow (#127440) --- homeassistant/components/caldav/config_flow.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/caldav/config_flow.py b/homeassistant/components/caldav/config_flow.py index 18a6023b3a2..26f758953f2 100644 --- a/homeassistant/components/caldav/config_flow.py +++ b/homeassistant/components/caldav/config_flow.py @@ -9,7 +9,7 @@ from caldav.lib.error import AuthorizationError, DAVError import requests import voluptuous as vol -from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult +from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME, CONF_VERIFY_SSL from homeassistant.helpers import config_validation as cv @@ -32,7 +32,6 @@ class CalDavConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow for caldav.""" VERSION = 1 - _reauth_entry: ConfigEntry async def async_step_user( self, user_input: dict[str, Any] | None = None @@ -91,7 +90,6 @@ class CalDavConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Perform reauth upon an API authentication error.""" - self._reauth_entry = self._get_reauth_entry() return await self.async_step_reauth_confirm() async def async_step_reauth_confirm( @@ -99,21 +97,18 @@ class CalDavConfigFlow(ConfigFlow, domain=DOMAIN): ) -> ConfigFlowResult: """Confirm reauth dialog.""" errors = {} + reauth_entry = self._get_reauth_entry() if user_input is not None: - user_input = {**self._reauth_entry.data, **user_input} + user_input = {**reauth_entry.data, **user_input} if error := await self._test_connection(user_input): errors["base"] = error else: - self.hass.config_entries.async_update_entry( - self._reauth_entry, data=user_input - ) - await self.hass.config_entries.async_reload(self._reauth_entry.entry_id) - return self.async_abort(reason="reauth_successful") + return self.async_update_reload_and_abort(reauth_entry, data=user_input) return self.async_show_form( description_placeholders={ - CONF_USERNAME: self._reauth_entry.data[CONF_USERNAME], + CONF_USERNAME: reauth_entry.data[CONF_USERNAME], }, step_id="reauth_confirm", data_schema=vol.Schema(