From 021e7ce49b6a6c1cfe3c6dd81c855ff766b595b2 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:03:19 +0200 Subject: [PATCH] Do not cache reauth/reconfigure entry in pyload config flow (#128017) --- .../components/pyload/config_flow.py | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/pyload/config_flow.py b/homeassistant/components/pyload/config_flow.py index 936cc5f3ea9..bac0f795343 100644 --- a/homeassistant/components/pyload/config_flow.py +++ b/homeassistant/components/pyload/config_flow.py @@ -30,7 +30,6 @@ from homeassistant.helpers.selector import ( TextSelectorType, ) -from . import PyLoadConfigEntry from .const import DEFAULT_HOST, DEFAULT_NAME, DEFAULT_PORT, DOMAIN _LOGGER = logging.getLogger(__name__) @@ -101,7 +100,6 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow for pyLoad.""" VERSION = 1 - config_entry: PyLoadConfigEntry async def async_step_user( self, user_input: dict[str, Any] | None = None @@ -156,7 +154,6 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Perform reauth upon an API authentication error.""" - self.config_entry = self._get_reauth_entry() return await self.async_step_reauth_confirm() async def async_step_reauth_confirm( @@ -164,9 +161,10 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN): ) -> ConfigFlowResult: """Dialog that informs the user that reauth is required.""" errors = {} + reauth_entry = self._get_reauth_entry() if user_input is not None: - new_input = self.config_entry.data | user_input + new_input = reauth_entry.data | user_input try: await validate_input(self.hass, new_input) except (CannotConnect, ParserError): @@ -177,9 +175,7 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.exception("Unexpected exception") errors["base"] = "unknown" else: - return self.async_update_reload_and_abort( - self.config_entry, data=new_input - ) + return self.async_update_reload_and_abort(reauth_entry, data=new_input) return self.async_show_form( step_id="reauth_confirm", @@ -188,10 +184,10 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN): { CONF_USERNAME: user_input[CONF_USERNAME] if user_input is not None - else self.config_entry.data[CONF_USERNAME] + else reauth_entry.data[CONF_USERNAME] }, ), - description_placeholders={CONF_NAME: self.config_entry.data[CONF_USERNAME]}, + description_placeholders={CONF_NAME: reauth_entry.data[CONF_USERNAME]}, errors=errors, ) @@ -199,7 +195,6 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN): self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: """Perform a reconfiguration.""" - self.config_entry = self._get_reconfigure_entry() return await self.async_step_reconfigure_confirm() async def async_step_reconfigure_confirm( @@ -207,6 +202,7 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN): ) -> ConfigFlowResult: """Handle the reconfiguration flow.""" errors = {} + reconfig_entry = self._get_reconfigure_entry() if user_input is not None: try: @@ -220,18 +216,17 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN): errors["base"] = "unknown" else: return self.async_update_reload_and_abort( - self.config_entry, + reconfig_entry, data=user_input, reload_even_if_entry_is_unchanged=False, - reason="reconfigure_successful", ) return self.async_show_form( step_id="reconfigure_confirm", data_schema=self.add_suggested_values_to_schema( STEP_USER_DATA_SCHEMA, - user_input or self.config_entry.data, + user_input or reconfig_entry.data, ), - description_placeholders={CONF_NAME: self.config_entry.data[CONF_USERNAME]}, + description_placeholders={CONF_NAME: reconfig_entry.data[CONF_USERNAME]}, errors=errors, )