Use new reauth helpers in unifiprotect (#128775)

This commit is contained in:
epenet 2024-10-19 19:21:09 +02:00 committed by GitHub
parent 062b61affb
commit fd8f5b9ff0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -104,7 +104,6 @@ class ProtectFlowHandler(ConfigFlow, domain=DOMAIN):
def __init__(self) -> None: def __init__(self) -> None:
"""Init the config flow.""" """Init the config flow."""
super().__init__() super().__init__()
self.entry: ConfigEntry | None = None
self._discovered_device: dict[str, str] = {} self._discovered_device: dict[str, str] = {}
async def async_step_dhcp( async def async_step_dhcp(
@ -295,8 +294,6 @@ class ProtectFlowHandler(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.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
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(
@ -304,21 +301,21 @@ class ProtectFlowHandler(ConfigFlow, domain=DOMAIN):
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Confirm reauth.""" """Confirm reauth."""
errors: dict[str, str] = {} errors: dict[str, str] = {}
assert self.entry is not None
# prepopulate fields # prepopulate fields
form_data = {**self.entry.data} reauth_entry = self._get_reauth_entry()
form_data = {**reauth_entry.data}
if user_input is not None: if user_input is not None:
form_data.update(user_input) form_data.update(user_input)
# validate login data # validate login data
_, errors = await self._async_get_nvr_data(form_data) _, errors = await self._async_get_nvr_data(form_data)
if not errors: if not errors:
return self.async_update_reload_and_abort(self.entry, data=form_data) return self.async_update_reload_and_abort(reauth_entry, data=form_data)
self.context["title_placeholders"] = { self.context["title_placeholders"] = {
"name": self.entry.title, "name": reauth_entry.title,
"ip_address": self.entry.data[CONF_HOST], "ip_address": reauth_entry.data[CONF_HOST],
} }
return self.async_show_form( return self.async_show_form(
step_id="reauth_confirm", step_id="reauth_confirm",