1 """Config flow for NZBGet."""
3 from __future__
import annotations
8 import voluptuous
as vol
21 from .const
import DEFAULT_NAME, DEFAULT_PORT, DEFAULT_SSL, DEFAULT_VERIFY_SSL, DOMAIN
22 from .coordinator
import NZBGetAPI, NZBGetAPIException
24 _LOGGER = logging.getLogger(__name__)
28 """Validate the user input allows us to connect.
30 Data has the keys from DATA_SCHEMA with values provided by the user.
32 nzbget_api = NZBGetAPI(
34 data.get(CONF_USERNAME),
35 data.get(CONF_PASSWORD),
37 data[CONF_VERIFY_SSL],
45 """Handle a config flow for NZBGet."""
50 self, user_input: dict[str, Any] |
None =
None
51 ) -> ConfigFlowResult:
52 """Handle a flow initiated by the user."""
55 if user_input
is not None:
56 if CONF_VERIFY_SSL
not in user_input:
57 user_input[CONF_VERIFY_SSL] = DEFAULT_VERIFY_SSL
60 await self.hass.async_add_executor_job(_validate_input, user_input)
61 except NZBGetAPIException:
62 errors[
"base"] =
"cannot_connect"
64 _LOGGER.exception(
"Unexpected exception")
68 title=user_input[CONF_HOST],
73 vol.Required(CONF_HOST): str,
74 vol.Optional(CONF_NAME, default=DEFAULT_NAME): str,
75 vol.Optional(CONF_USERNAME): str,
76 vol.Optional(CONF_PASSWORD): str,
77 vol.Optional(CONF_PORT, default=DEFAULT_PORT): int,
78 vol.Optional(CONF_SSL, default=DEFAULT_SSL): bool,
82 data_schema[vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL)] = (
88 data_schema=vol.Schema(data_schema),
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
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)
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)
bool show_advanced_options(self)
_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)
None _validate_input(dict[str, Any] data)