1 """Config flow to configure the AdGuard Home integration."""
3 from __future__
import annotations
7 from adguardhome
import AdGuardHome, AdGuardHomeConnectionError
8 import voluptuous
as vol
22 from .const
import DOMAIN
26 """Handle a AdGuard Home config flow."""
30 _hassio_discovery: dict[str, Any] |
None =
None
33 self, errors: dict[str, str] |
None =
None
34 ) -> ConfigFlowResult:
35 """Show the setup form to the user."""
38 data_schema=vol.Schema(
40 vol.Required(CONF_HOST): str,
41 vol.Required(CONF_PORT, default=3000): vol.Coerce(int),
42 vol.Optional(CONF_USERNAME): str,
43 vol.Optional(CONF_PASSWORD): str,
44 vol.Required(CONF_SSL, default=
True): bool,
45 vol.Required(CONF_VERIFY_SSL, default=
True): bool,
51 async
def _show_hassio_form(
52 self, errors: dict[str, str] |
None =
None
53 ) -> ConfigFlowResult:
54 """Show the Hass.io confirmation form to the user."""
57 step_id=
"hassio_confirm",
58 description_placeholders={
"addon": self.
_hassio_discovery_hassio_discovery[
"addon"]},
63 self, user_input: dict[str, Any] |
None =
None
64 ) -> ConfigFlowResult:
65 """Handle a flow initiated by the user."""
66 if user_input
is None:
70 {CONF_HOST: user_input[CONF_HOST], CONF_PORT: user_input[CONF_PORT]}
77 username: str |
None = user_input.get(CONF_USERNAME)
78 password: str |
None = user_input.get(CONF_PASSWORD)
79 adguard = AdGuardHome(
80 user_input[CONF_HOST],
81 port=user_input[CONF_PORT],
84 tls=user_input[CONF_SSL],
85 verify_ssl=user_input[CONF_VERIFY_SSL],
90 await adguard.version()
91 except AdGuardHomeConnectionError:
92 errors[
"base"] =
"cannot_connect"
96 title=user_input[CONF_HOST],
98 CONF_HOST: user_input[CONF_HOST],
99 CONF_PASSWORD: user_input.get(CONF_PASSWORD),
100 CONF_PORT: user_input[CONF_PORT],
101 CONF_SSL: user_input[CONF_SSL],
102 CONF_USERNAME: user_input.get(CONF_USERNAME),
103 CONF_VERIFY_SSL: user_input[CONF_VERIFY_SSL],
108 self, discovery_info: HassioServiceInfo
109 ) -> ConfigFlowResult:
110 """Prepare configuration for a Hass.io AdGuard Home add-on.
112 This flow is triggered by the discovery component.
117 return await self.async_step_hassio_confirm()
119 async
def async_step_hassio_confirm(
120 self, user_input: dict[str, Any] |
None =
None
121 ) -> ConfigFlowResult:
122 """Confirm Supervisor discovery."""
123 if user_input
is None:
124 return await self._show_hassio_form()
131 adguard = AdGuardHome(
139 await adguard.version()
140 except AdGuardHomeConnectionError:
141 errors[
"base"] =
"cannot_connect"
142 return await self._show_hassio_form(errors)
152 CONF_VERIFY_SSL:
True,
ConfigFlowResult _show_setup_form(self, dict[str, str]|None errors=None)
None _async_handle_discovery_without_unique_id(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_step_hassio(self, HassioServiceInfo discovery_info)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=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)
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)