1 """Adds config flow for NextDNS."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from aiohttp.client_exceptions
import ClientConnectorError
9 from nextdns
import ApiError, InvalidApiKeyError, NextDns
10 from tenacity
import RetryError
11 import voluptuous
as vol
18 from .const
import CONF_PROFILE_ID, DOMAIN
20 AUTH_SCHEMA = vol.Schema({vol.Required(CONF_API_KEY): str})
24 """Check if credentials are valid."""
27 return await NextDns.create(websession, api_key)
31 """Config flow for NextDNS."""
36 """Initialize the config flow."""
41 self, user_input: dict[str, Any] |
None =
None
42 ) -> ConfigFlowResult:
43 """Handle a flow initialized by the user."""
44 errors: dict[str, str] = {}
46 if user_input
is not None:
47 self.
api_keyapi_key = user_input[CONF_API_KEY]
50 except InvalidApiKeyError:
51 errors[
"base"] =
"invalid_api_key"
52 except (ApiError, ClientConnectorError, RetryError, TimeoutError):
53 errors[
"base"] =
"cannot_connect"
55 errors[
"base"] =
"unknown"
61 data_schema=AUTH_SCHEMA,
66 self, user_input: dict[str, Any] |
None =
None
67 ) -> ConfigFlowResult:
68 """Handle the profiles step."""
69 errors: dict[str, str] = {}
71 if user_input
is not None:
72 profile_name = user_input[CONF_PROFILE_NAME]
73 profile_id = self.
nextdnsnextdns.get_profile_id(profile_name)
80 data={CONF_PROFILE_ID: profile_id, CONF_API_KEY: self.
api_keyapi_key},
85 data_schema=vol.Schema(
87 vol.Required(CONF_PROFILE_NAME): vol.In(
88 [profile.name
for profile
in self.
nextdnsnextdns.profiles]
96 self, entry_data: Mapping[str, Any]
97 ) -> ConfigFlowResult:
98 """Handle configuration by re-auth."""
102 self, user_input: dict[str, Any] |
None =
None
103 ) -> ConfigFlowResult:
104 """Dialog that informs the user that reauth is required."""
105 errors: dict[str, str] = {}
107 if user_input
is not None:
110 except InvalidApiKeyError:
111 errors[
"base"] =
"invalid_api_key"
112 except (ApiError, ClientConnectorError, RetryError, TimeoutError):
113 errors[
"base"] =
"cannot_connect"
115 errors[
"base"] =
"unknown"
122 step_id=
"reauth_confirm",
123 data_schema=AUTH_SCHEMA,
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_profiles(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
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_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)
NextDns async_init_nextdns(HomeAssistant hass, str api_key)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)