mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Use new reauth helpers in ruckus_unleashed (#128727)
This commit is contained in:
parent
061ece55f3
commit
31a58a21c6
@ -8,7 +8,7 @@ from aioruckus import AjaxSession, SystemStat
|
|||||||
from aioruckus.exceptions import AuthenticationError, SchemaError
|
from aioruckus.exceptions import AuthenticationError, SchemaError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -64,8 +64,6 @@ class RuckusConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
_reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
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
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
@ -82,27 +80,24 @@ class RuckusConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
else:
|
else:
|
||||||
if self._reauth_entry is None:
|
await self.async_set_unique_id(info[KEY_SYS_SERIAL])
|
||||||
await self.async_set_unique_id(info[KEY_SYS_SERIAL])
|
if self.source != SOURCE_REAUTH:
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=info[KEY_SYS_TITLE], data=user_input
|
title=info[KEY_SYS_TITLE], data=user_input
|
||||||
)
|
)
|
||||||
if info[KEY_SYS_SERIAL] == self._reauth_entry.unique_id:
|
reauth_entry = self._get_reauth_entry()
|
||||||
self.hass.config_entries.async_update_entry(
|
if info[KEY_SYS_SERIAL] == reauth_entry.unique_id:
|
||||||
self._reauth_entry, data=user_input
|
return self.async_update_reload_and_abort(
|
||||||
|
reauth_entry, data=user_input
|
||||||
)
|
)
|
||||||
self.hass.async_create_task(
|
|
||||||
self.hass.config_entries.async_reload(
|
|
||||||
self._reauth_entry.entry_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
errors["base"] = "invalid_host"
|
errors["base"] = "invalid_host"
|
||||||
|
|
||||||
data_schema = self.add_suggested_values_to_schema(
|
data_schema = DATA_SCHEMA
|
||||||
DATA_SCHEMA, self._reauth_entry.data if self._reauth_entry else {}
|
if self.source == SOURCE_REAUTH:
|
||||||
)
|
data_schema = self.add_suggested_values_to_schema(
|
||||||
|
data_schema, self._get_reauth_entry().data
|
||||||
|
)
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user", data_schema=data_schema, errors=errors
|
step_id="user", data_schema=data_schema, errors=errors
|
||||||
)
|
)
|
||||||
@ -111,9 +106,6 @@ class RuckusConfigFlow(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._reauth_entry = self.hass.config_entries.async_get_entry(
|
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user