Skip to content
Snippets Groups Projects
Unverified Commit ca6b7596 authored by epenet's avatar epenet Committed by GitHub
Browse files

Use new reauth helpers in unifi (#128837)


* Use new reauth helpers in unifi

* Apply suggestions from code review

Co-authored-by: default avatarJoost Lekkerkerker <joostlek@outlook.com>

* Update config_flow.py

---------

Co-authored-by: default avatarJoost Lekkerkerker <joostlek@outlook.com>
parent f9d85721
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ import voluptuous as vol ...@@ -20,6 +20,7 @@ import voluptuous as vol
from homeassistant.components import ssdp from homeassistant.components import ssdp
from homeassistant.config_entries import ( from homeassistant.config_entries import (
SOURCE_REAUTH,
ConfigEntry, ConfigEntry,
ConfigEntryState, ConfigEntryState,
ConfigFlow, ConfigFlow,
...@@ -86,7 +87,6 @@ class UnifiFlowHandler(ConfigFlow, domain=UNIFI_DOMAIN): ...@@ -86,7 +87,6 @@ class UnifiFlowHandler(ConfigFlow, domain=UNIFI_DOMAIN):
def __init__(self) -> None: def __init__(self) -> None:
"""Initialize the UniFi Network flow.""" """Initialize the UniFi Network flow."""
self.config: dict[str, Any] = {} self.config: dict[str, Any] = {}
self.reauth_config_entry: ConfigEntry | None = None
self.reauth_schema: dict[vol.Marker, Any] = {} self.reauth_schema: dict[vol.Marker, Any] = {}
async def async_step_user( async def async_step_user(
...@@ -118,13 +118,14 @@ class UnifiFlowHandler(ConfigFlow, domain=UNIFI_DOMAIN): ...@@ -118,13 +118,14 @@ class UnifiFlowHandler(ConfigFlow, domain=UNIFI_DOMAIN):
else: else:
if ( if (
self.reauth_config_entry self.source == SOURCE_REAUTH
and self.reauth_config_entry.unique_id is not None and (
and self.reauth_config_entry.unique_id in self.sites (reauth_unique_id := self._get_reauth_entry().unique_id)
): is not None
return await self.async_step_site(
{CONF_SITE_ID: self.reauth_config_entry.unique_id}
) )
and reauth_unique_id in self.sites
):
return await self.async_step_site({CONF_SITE_ID: reauth_unique_id})
return await self.async_step_site() return await self.async_step_site()
...@@ -160,8 +161,8 @@ class UnifiFlowHandler(ConfigFlow, domain=UNIFI_DOMAIN): ...@@ -160,8 +161,8 @@ class UnifiFlowHandler(ConfigFlow, domain=UNIFI_DOMAIN):
config_entry = await self.async_set_unique_id(unique_id) config_entry = await self.async_set_unique_id(unique_id)
abort_reason = "configuration_updated" abort_reason = "configuration_updated"
if self.reauth_config_entry: if self.source == SOURCE_REAUTH:
config_entry = self.reauth_config_entry config_entry = self._get_reauth_entry()
abort_reason = "reauth_successful" abort_reason = "reauth_successful"
if config_entry: if config_entry:
...@@ -192,24 +193,20 @@ class UnifiFlowHandler(ConfigFlow, domain=UNIFI_DOMAIN): ...@@ -192,24 +193,20 @@ class UnifiFlowHandler(ConfigFlow, domain=UNIFI_DOMAIN):
self, entry_data: Mapping[str, Any] self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Trigger a reauthentication flow.""" """Trigger a reauthentication flow."""
config_entry = self.hass.config_entries.async_get_entry( reauth_entry = self._get_reauth_entry()
self.context["entry_id"]
)
assert config_entry
self.reauth_config_entry = config_entry
self.context["title_placeholders"] = { self.context["title_placeholders"] = {
CONF_HOST: config_entry.data[CONF_HOST], CONF_HOST: reauth_entry.data[CONF_HOST],
CONF_SITE_ID: config_entry.title, CONF_SITE_ID: reauth_entry.title,
} }
self.reauth_schema = { self.reauth_schema = {
vol.Required(CONF_HOST, default=config_entry.data[CONF_HOST]): str, vol.Required(CONF_HOST, default=reauth_entry.data[CONF_HOST]): str,
vol.Required(CONF_USERNAME, default=config_entry.data[CONF_USERNAME]): str, vol.Required(CONF_USERNAME, default=reauth_entry.data[CONF_USERNAME]): str,
vol.Required(CONF_PASSWORD): str, vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_PORT, default=config_entry.data[CONF_PORT]): int, vol.Required(CONF_PORT, default=reauth_entry.data[CONF_PORT]): int,
vol.Required( vol.Required(
CONF_VERIFY_SSL, default=config_entry.data[CONF_VERIFY_SSL] CONF_VERIFY_SSL, default=reauth_entry.data[CONF_VERIFY_SSL]
): bool, ): bool,
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment