mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Do not cache reauth/reconfigure entry in solarlog config flow (#128023)
This commit is contained in:
parent
11245dbb82
commit
f13f4a4851
@ -17,7 +17,6 @@ from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
|||||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
from . import SolarlogConfigEntry
|
|
||||||
from .const import CONF_HAS_PWD, DEFAULT_HOST, DEFAULT_NAME, DOMAIN
|
from .const import CONF_HAS_PWD, DEFAULT_HOST, DEFAULT_NAME, DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -26,7 +25,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
|
class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for solarlog."""
|
"""Handle a config flow for solarlog."""
|
||||||
|
|
||||||
_entry: SolarlogConfigEntry
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
MINOR_VERSION = 3
|
MINOR_VERSION = 3
|
||||||
|
|
||||||
@ -141,32 +139,28 @@ class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a reconfiguration flow initialized by the user."""
|
"""Handle a reconfiguration flow initialized by the user."""
|
||||||
self._entry = self._get_reconfigure_entry()
|
|
||||||
|
|
||||||
return await self.async_step_reconfigure_confirm()
|
return await self.async_step_reconfigure_confirm()
|
||||||
|
|
||||||
async def async_step_reconfigure_confirm(
|
async def async_step_reconfigure_confirm(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a reconfiguration flow initialized by the user."""
|
"""Handle a reconfiguration flow initialized by the user."""
|
||||||
|
reconfigure_entry = self._get_reconfigure_entry()
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
if not user_input[CONF_HAS_PWD] or user_input.get(CONF_PASSWORD, "") == "":
|
if not user_input[CONF_HAS_PWD] or user_input.get(CONF_PASSWORD, "") == "":
|
||||||
user_input[CONF_PASSWORD] = ""
|
user_input[CONF_PASSWORD] = ""
|
||||||
user_input[CONF_HAS_PWD] = False
|
user_input[CONF_HAS_PWD] = False
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self._entry,
|
reconfigure_entry, data_updates=user_input
|
||||||
reason="reconfigure_successful",
|
|
||||||
data={**self._entry.data, **user_input},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if await self._test_extended_data(
|
if await self._test_extended_data(
|
||||||
self._entry.data[CONF_HOST], user_input.get(CONF_PASSWORD, "")
|
reconfigure_entry.data[CONF_HOST], user_input.get(CONF_PASSWORD, "")
|
||||||
):
|
):
|
||||||
# if password has been provided, only save if extended data is available
|
# if password has been provided, only save if extended data is available
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self._entry,
|
reconfigure_entry,
|
||||||
reason="reconfigure_successful",
|
data_updates=user_input,
|
||||||
data={**self._entry.data, **user_input},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
@ -174,7 +168,7 @@ class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
data_schema=vol.Schema(
|
data_schema=vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_HAS_PWD, default=self._entry.data[CONF_HAS_PWD]
|
CONF_HAS_PWD, default=reconfigure_entry.data[CONF_HAS_PWD]
|
||||||
): bool,
|
): bool,
|
||||||
vol.Optional(CONF_PASSWORD): str,
|
vol.Optional(CONF_PASSWORD): str,
|
||||||
}
|
}
|
||||||
@ -185,24 +179,24 @@ class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle flow upon an API authentication error."""
|
"""Handle flow upon an API authentication error."""
|
||||||
self._entry = self._get_reauth_entry()
|
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle reauthorization flow."""
|
"""Handle reauthorization flow."""
|
||||||
|
reauth_entry = self._get_reauth_entry()
|
||||||
if user_input and await self._test_extended_data(
|
if user_input and await self._test_extended_data(
|
||||||
self._entry.data[CONF_HOST], user_input.get(CONF_PASSWORD, "")
|
reauth_entry.data[CONF_HOST], user_input.get(CONF_PASSWORD, "")
|
||||||
):
|
):
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self._entry, data={**self._entry.data, **user_input}
|
reauth_entry, data_updates=user_input
|
||||||
)
|
)
|
||||||
|
|
||||||
data_schema = vol.Schema(
|
data_schema = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_HAS_PWD, default=self._entry.data[CONF_HAS_PWD]
|
CONF_HAS_PWD, default=reauth_entry.data[CONF_HAS_PWD]
|
||||||
): bool,
|
): bool,
|
||||||
vol.Optional(CONF_PASSWORD): str,
|
vol.Optional(CONF_PASSWORD): str,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user