1 """Config flow for Glances."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from glances_api.exceptions
import (
9 GlancesApiAuthorizationError,
10 GlancesApiConnectionError,
12 import voluptuous
as vol
24 from .
import ServerVersionMismatch, get_api
25 from .const
import DEFAULT_HOST, DEFAULT_PORT, DOMAIN
27 DATA_SCHEMA = vol.Schema(
29 vol.Required(CONF_HOST, default=DEFAULT_HOST): str,
30 vol.Optional(CONF_USERNAME): str,
31 vol.Optional(CONF_PASSWORD): str,
32 vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
33 vol.Optional(CONF_SSL, default=
False): bool,
34 vol.Optional(CONF_VERIFY_SSL, default=
False): bool,
40 """Handle a Glances config flow."""
45 self, entry_data: Mapping[str, Any]
46 ) -> ConfigFlowResult:
47 """Perform reauth upon an API authentication error."""
51 self, user_input: dict[str, str] |
None =
None
52 ) -> ConfigFlowResult:
53 """Confirm reauth dialog."""
57 if user_input
is not None:
58 user_input = {**reauth_entry.data, **user_input}
60 await
get_api(self.hass, user_input)
61 except GlancesApiAuthorizationError:
62 errors[
"base"] =
"invalid_auth"
63 except GlancesApiConnectionError:
64 errors[
"base"] =
"cannot_connect"
66 self.hass.config_entries.async_update_entry(
67 reauth_entry, data=user_input
69 await self.hass.config_entries.async_reload(reauth_entry.entry_id)
73 description_placeholders={CONF_USERNAME: reauth_entry.data[CONF_USERNAME]},
74 step_id=
"reauth_confirm",
75 data_schema=vol.Schema(
77 vol.Required(CONF_PASSWORD): str,
84 self, user_input: dict[str, Any] |
None =
None
85 ) -> ConfigFlowResult:
86 """Handle the initial step."""
88 if user_input
is not None:
90 {CONF_HOST: user_input[CONF_HOST], CONF_PORT: user_input[CONF_PORT]}
93 await
get_api(self.hass, user_input)
94 except GlancesApiAuthorizationError:
95 errors[
"base"] =
"invalid_auth"
96 except (GlancesApiConnectionError, ServerVersionMismatch):
97 errors[
"base"] =
"cannot_connect"
100 title=f
"{user_input[CONF_HOST]}:{user_input[CONF_PORT]}",
105 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
ConfigFlowResult async_step_reauth_confirm(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigEntry _get_reauth_entry(self)
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_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=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)
_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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
Glances get_api(HomeAssistant hass, dict[str, Any] entry_data)