Use reauth helpers in co2signal (#128566)

Do not cache reauth entry in co2signal
This commit is contained in:
epenet 2024-10-18 04:10:57 +02:00 committed by GitHub
parent 9037421a85
commit 0e667dfe36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,7 +13,7 @@ from aioelectricitymaps import (
)
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 @@ class ElectricityMapsConfigFlow(ConfigFlow, domain=DOMAIN):
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 @@ class ElectricityMapsConfigFlow(ConfigFlow, domain=DOMAIN):
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(