1 """Config flow to configure the Pi-hole integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
10 from hole.exceptions
import HoleError
11 import voluptuous
as vol
33 _LOGGER = logging.getLogger(__name__)
37 """Handle a Pi-hole config flow."""
42 """Initialize the config flow."""
46 self, user_input: dict[str, Any] |
None =
None
47 ) -> ConfigFlowResult:
48 """Handle a flow initiated by the user."""
51 if user_input
is not None:
53 CONF_HOST: f
"{user_input[CONF_HOST]}:{user_input[CONF_PORT]}",
54 CONF_NAME: user_input[CONF_NAME],
55 CONF_LOCATION: user_input[CONF_LOCATION],
56 CONF_SSL: user_input[CONF_SSL],
57 CONF_VERIFY_SSL: user_input[CONF_VERIFY_SSL],
62 CONF_HOST: f
"{user_input[CONF_HOST]}:{user_input[CONF_PORT]}",
63 CONF_LOCATION: user_input[CONF_LOCATION],
69 title=user_input[CONF_NAME], data=self.
_config_config
72 if CONF_API_KEY
in errors:
75 user_input = user_input
or {}
78 data_schema=vol.Schema(
80 vol.Required(CONF_HOST, default=user_input.get(CONF_HOST,
"")): str,
82 CONF_PORT, default=user_input.get(CONF_PORT, 80)
85 CONF_NAME, default=user_input.get(CONF_NAME, DEFAULT_NAME)
89 default=user_input.get(CONF_LOCATION, DEFAULT_LOCATION),
93 default=user_input.get(CONF_SSL, DEFAULT_SSL),
97 default=user_input.get(CONF_VERIFY_SSL, DEFAULT_VERIFY_SSL),
105 self, user_input: dict[str, Any] |
None =
None
106 ) -> ConfigFlowResult:
107 """Handle step to setup API key."""
109 if user_input
is not None:
110 self.
_config_config[CONF_API_KEY] = user_input[CONF_API_KEY]
113 title=self.
_config_config[CONF_NAME],
119 data_schema=vol.Schema({vol.Required(CONF_API_KEY): str}),
124 self, entry_data: Mapping[str, Any]
125 ) -> ConfigFlowResult:
126 """Perform reauth upon an API authentication error."""
132 user_input: dict[str, Any] |
None =
None,
133 ) -> ConfigFlowResult:
134 """Perform reauth confirm upon an API authentication error."""
136 if user_input
is not None:
137 self.
_config_config = {**self.
_config_config, CONF_API_KEY: user_input[CONF_API_KEY]}
144 step_id=
"reauth_confirm",
145 description_placeholders={
146 CONF_HOST: self.
_config_config[CONF_HOST],
147 CONF_LOCATION: self.
_config_config[CONF_LOCATION],
149 data_schema=vol.Schema({vol.Required(CONF_API_KEY): str}),
156 self.
_config_config[CONF_HOST],
158 location=self.
_config_config[CONF_LOCATION],
159 tls=self.
_config_config[CONF_SSL],
160 api_token=self.
_config_config.
get(CONF_API_KEY),
163 await pi_hole.get_data()
164 except HoleError
as ex:
165 _LOGGER.debug(
"Connection failed: %s", ex)
166 return {
"base":
"cannot_connect"}
167 if not isinstance(pi_hole.data, dict):
168 return {CONF_API_KEY:
"invalid_auth"}
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_api_key(self, dict[str, Any]|None user_input=None)
dict[str, str] _async_try_connect(self)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
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_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)
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)
web.Response get(self, web.Request request, str config_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)