1 """Config flow for Ruckus integration."""
3 from collections.abc
import Mapping
7 from aioruckus
import AjaxSession, SystemStat
8 from aioruckus.exceptions
import AuthenticationError, SchemaError
9 import voluptuous
as vol
19 API_SYS_SYSINFO_SERIAL,
25 _LOGGER = logging.getLogger(__package__)
27 DATA_SCHEMA = vol.Schema(
29 vol.Required(CONF_HOST): str,
30 vol.Required(CONF_USERNAME): str,
31 vol.Required(CONF_PASSWORD): str,
37 """Validate the user input allows us to connect.
39 Data has the keys from DATA_SCHEMA with values provided by the user.
43 async
with AjaxSession.async_create(
44 data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD]
46 mesh_info = await ruckus.api.get_mesh_info()
47 system_info = await ruckus.api.get_system_info(SystemStat.SYSINFO)
48 except AuthenticationError
as autherr:
49 raise InvalidAuth
from autherr
50 except (ConnectionError, SchemaError)
as connerr:
51 raise CannotConnect
from connerr
53 mesh_name = mesh_info[API_MESH_NAME]
54 zd_serial = system_info[API_SYS_SYSINFO][API_SYS_SYSINFO_SERIAL]
57 KEY_SYS_TITLE: mesh_name,
58 KEY_SYS_SERIAL: zd_serial,
63 """Handle a config flow for Ruckus."""
68 self, user_input: dict[str, Any] |
None =
None
69 ) -> ConfigFlowResult:
70 """Handle the initial step."""
72 if user_input
is not None:
76 errors[
"base"] =
"cannot_connect"
78 errors[
"base"] =
"invalid_auth"
80 _LOGGER.exception(
"Unexpected exception")
81 errors[
"base"] =
"unknown"
87 title=info[KEY_SYS_TITLE], data=user_input
90 if info[KEY_SYS_SERIAL] == reauth_entry.unique_id:
92 reauth_entry, data=user_input
94 errors[
"base"] =
"invalid_host"
96 data_schema = DATA_SCHEMA
102 step_id=
"user", data_schema=data_schema, errors=errors
106 self, entry_data: Mapping[str, Any]
107 ) -> ConfigFlowResult:
108 """Perform reauth upon an API authentication error."""
113 """Error to indicate we cannot connect."""
117 """Error to indicate there is invalid auth."""
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry _get_reauth_entry(self)
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult async_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)
def validate_input(HomeAssistant hass, data)