Use reauth/reconfigure helpers in reolink config flow (#128018)

This commit is contained in:
epenet 2024-10-09 17:26:08 +02:00 committed by GitHub
parent 7b6cac558d
commit 8dfb8ebe5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -139,13 +139,10 @@ class ReolinkFlowHandler(ConfigFlow, domain=DOMAIN):
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Perform a reconfiguration."""
config_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
assert config_entry is not None
self._host = config_entry.data[CONF_HOST]
self._username = config_entry.data[CONF_USERNAME]
self._password = config_entry.data[CONF_PASSWORD]
entry_data = self._get_reconfigure_entry().data
self._host = entry_data[CONF_HOST]
self._username = entry_data[CONF_USERNAME]
self._password = entry_data[CONF_PASSWORD]
return await self.async_step_user()
async def async_step_dhcp(
@ -260,17 +257,16 @@ class ReolinkFlowHandler(ConfigFlow, domain=DOMAIN):
user_input[CONF_USE_HTTPS] = host.api.use_https
mac_address = format_mac(host.api.mac_address)
existing_entry = await self.async_set_unique_id(
mac_address, raise_on_progress=False
)
if existing_entry and self.init_step in (
SOURCE_REAUTH,
SOURCE_RECONFIGURE,
):
await self.async_set_unique_id(mac_address, raise_on_progress=False)
if self.source == SOURCE_REAUTH:
self._abort_if_unique_id_mismatch()
return self.async_update_reload_and_abort(
entry=existing_entry,
data=user_input,
reason=f"{self.init_step}_successful",
entry=self._get_reauth_entry(), data=user_input
)
if self.source == SOURCE_RECONFIGURE:
self._abort_if_unique_id_mismatch()
return self.async_update_reload_and_abort(
entry=self._get_reconfigure_entry(), data=user_input
)
self._abort_if_unique_id_configured(updates=user_input)
@ -286,7 +282,7 @@ class ReolinkFlowHandler(ConfigFlow, domain=DOMAIN):
vol.Required(CONF_PASSWORD, default=self._password): str,
}
)
if self._host is None or self.init_step == SOURCE_RECONFIGURE or errors:
if self._host is None or self.source == SOURCE_RECONFIGURE or errors:
data_schema = data_schema.extend(
{
vol.Required(CONF_HOST, default=self._host): str,