From 0e667dfe3683765b985356f7eab70d3f31a6111b Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 18 Oct 2024 04:10:57 +0200 Subject: [PATCH] Use reauth helpers in co2signal (#128566) Do not cache reauth entry in co2signal --- homeassistant/components/co2signal/config_flow.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/co2signal/config_flow.py b/homeassistant/components/co2signal/config_flow.py index 3313d01be85eb8..622c09f0d38260 100644 --- a/homeassistant/components/co2signal/config_flow.py +++ b/homeassistant/components/co2signal/config_flow.py @@ -13,7 +13,7 @@ ) import voluptuous as vol -from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult +from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult from homeassistant.const import ( CONF_API_KEY, CONF_COUNTRY_CODE, @@ -42,7 +42,6 @@ class ElectricityMapsConfigFlow(ConfigFlow, domain=DOMAIN): VERSION = 1 _data: dict | None - _reauth_entry: ConfigEntry | None = None async def async_step_user( self, user_input: dict[str, Any] | None = None @@ -128,9 +127,6 @@ async def async_step_reauth( self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle the reauth step.""" - self._reauth_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( @@ -165,12 +161,10 @@ async def _validate_and_create( except ElectricityMapsError: errors["base"] = "unknown" else: - if self._reauth_entry: + if self.source == SOURCE_REAUTH: return self.async_update_reload_and_abort( - self._reauth_entry, - data={ - CONF_API_KEY: data[CONF_API_KEY], - }, + self._get_reauth_entry(), + data_updates={CONF_API_KEY: data[CONF_API_KEY]}, ) return self.async_create_entry(