Use reauth_confirm in mqtt (#128696)

This commit is contained in:
epenet 2024-10-19 09:30:57 +02:00 committed by GitHub
parent a023b71ce0
commit 22491afa58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -210,7 +210,6 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
VERSION = 1
entry: ConfigEntry | None
_hassio_discovery: dict[str, Any] | None = None
_addon_manager: AddonManager
@ -398,7 +397,6 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle re-authentication with MQTT broker."""
self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
if is_hassio(self.hass):
# Check if entry setup matches the add-on discovery config
addon_manager = get_addon_manager(self.hass)
@ -437,18 +435,18 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
"""Confirm re-authentication with MQTT broker."""
errors: dict[str, str] = {}
assert self.entry is not None
reauth_entry = self._get_reauth_entry()
if user_input:
substituted_used_data = update_password_from_user_input(
self.entry.data.get(CONF_PASSWORD), user_input
reauth_entry.data.get(CONF_PASSWORD), user_input
)
new_entry_data = {**self.entry.data, **substituted_used_data}
new_entry_data = {**reauth_entry.data, **substituted_used_data}
if await self.hass.async_add_executor_job(
try_connection,
new_entry_data,
):
return self.async_update_reload_and_abort(
self.entry, data=new_entry_data
reauth_entry, data=new_entry_data
)
errors["base"] = "invalid_auth"
@ -456,7 +454,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
schema = self.add_suggested_values_to_schema(
REAUTH_SCHEMA,
{
CONF_USERNAME: self.entry.data.get(CONF_USERNAME),
CONF_USERNAME: reauth_entry.data.get(CONF_USERNAME),
CONF_PASSWORD: PWD_NOT_CHANGED,
},
)