Do not cache reauth/reconfigure entry in pyload config flow (#128017)
parent
2d093e9692
commit
021e7ce49b
|
@ -30,7 +30,6 @@ from homeassistant.helpers.selector import (
|
||||||
TextSelectorType,
|
TextSelectorType,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import PyLoadConfigEntry
|
|
||||||
from .const import DEFAULT_HOST, DEFAULT_NAME, DEFAULT_PORT, DOMAIN
|
from .const import DEFAULT_HOST, DEFAULT_NAME, DEFAULT_PORT, DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -101,7 +100,6 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for pyLoad."""
|
"""Handle a config flow for pyLoad."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
config_entry: PyLoadConfigEntry
|
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
@ -156,7 +154,6 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Perform reauth upon an API authentication error."""
|
"""Perform reauth upon an API authentication error."""
|
||||||
self.config_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(
|
||||||
|
@ -164,9 +161,10 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Dialog that informs the user that reauth is required."""
|
"""Dialog that informs the user that reauth is required."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
reauth_entry = self._get_reauth_entry()
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
new_input = self.config_entry.data | user_input
|
new_input = reauth_entry.data | user_input
|
||||||
try:
|
try:
|
||||||
await validate_input(self.hass, new_input)
|
await validate_input(self.hass, new_input)
|
||||||
except (CannotConnect, ParserError):
|
except (CannotConnect, ParserError):
|
||||||
|
@ -177,9 +175,7 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
else:
|
else:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(reauth_entry, data=new_input)
|
||||||
self.config_entry, data=new_input
|
|
||||||
)
|
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
|
@ -188,10 +184,10 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
{
|
{
|
||||||
CONF_USERNAME: user_input[CONF_USERNAME]
|
CONF_USERNAME: user_input[CONF_USERNAME]
|
||||||
if user_input is not None
|
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,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -199,7 +195,6 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Perform a reconfiguration."""
|
"""Perform a reconfiguration."""
|
||||||
self.config_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(
|
||||||
|
@ -207,6 +202,7 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle the reconfiguration flow."""
|
"""Handle the reconfiguration flow."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
reconfig_entry = self._get_reconfigure_entry()
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
try:
|
try:
|
||||||
|
@ -220,18 +216,17 @@ class PyLoadConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
else:
|
else:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self.config_entry,
|
reconfig_entry,
|
||||||
data=user_input,
|
data=user_input,
|
||||||
reload_even_if_entry_is_unchanged=False,
|
reload_even_if_entry_is_unchanged=False,
|
||||||
reason="reconfigure_successful",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reconfigure_confirm",
|
step_id="reconfigure_confirm",
|
||||||
data_schema=self.add_suggested_values_to_schema(
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
STEP_USER_DATA_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,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue