Do not cache reconfigure entry in smhi config flow (#128021)

pull/128029/head
epenet 2024-10-09 16:06:59 +02:00 committed by GitHub
parent 3fa460a42a
commit 6da8b69ff8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 9 deletions

View File

@ -8,7 +8,7 @@ from smhi.smhi_lib import Smhi, SmhiForecastException
import voluptuous as vol
from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_LATITUDE, CONF_LOCATION, CONF_LONGITUDE, CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers import (
@ -39,7 +39,6 @@ class SmhiFlowHandler(ConfigFlow, domain=DOMAIN):
"""Config flow for SMHI component."""
VERSION = 2
config_entry: ConfigEntry
async def async_step_user(
self, user_input: dict[str, Any] | None = None
@ -85,7 +84,6 @@ class SmhiFlowHandler(ConfigFlow, domain=DOMAIN):
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle a reconfiguration flow initialized by the user."""
self.config_entry = self._get_reconfigure_entry()
return await self.async_step_reconfigure_confirm()
async def async_step_reconfigure_confirm(
@ -93,6 +91,7 @@ class SmhiFlowHandler(ConfigFlow, domain=DOMAIN):
) -> ConfigFlowResult:
"""Handle a reconfiguration flow initialized by the user."""
errors: dict[str, str] = {}
reconfigure_entry = self._get_reconfigure_entry()
if user_input is not None:
lat: float = user_input[CONF_LOCATION][CONF_LATITUDE]
@ -102,8 +101,8 @@ class SmhiFlowHandler(ConfigFlow, domain=DOMAIN):
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured()
old_lat = self.config_entry.data[CONF_LOCATION][CONF_LATITUDE]
old_lon = self.config_entry.data[CONF_LOCATION][CONF_LONGITUDE]
old_lat = reconfigure_entry.data[CONF_LOCATION][CONF_LATITUDE]
old_lon = reconfigure_entry.data[CONF_LOCATION][CONF_LONGITUDE]
entity_reg = er.async_get(self.hass)
if entity := entity_reg.async_get_entity_id(
@ -122,16 +121,15 @@ class SmhiFlowHandler(ConfigFlow, domain=DOMAIN):
)
return self.async_update_reload_and_abort(
self.config_entry,
reconfigure_entry,
unique_id=unique_id,
data={**self.config_entry.data, **user_input},
reason="reconfigure_successful",
data_updates=user_input,
)
errors["base"] = "wrong_location"
schema = self.add_suggested_values_to_schema(
vol.Schema({vol.Required(CONF_LOCATION): LocationSelector()}),
self.config_entry.data,
reconfigure_entry.data,
)
return self.async_show_form(
step_id="reconfigure_confirm", data_schema=schema, errors=errors