1 """Config flow for the Deluge integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from ssl
import SSLError
9 from deluge_client.client
import DelugeRPCClient
10 import voluptuous
as vol
26 """Handle a config flow for Deluge."""
29 self, user_input: dict[str, Any] |
None =
None
30 ) -> ConfigFlowResult:
31 """Handle a flow initiated by the user."""
34 if user_input
is not None:
35 if (error := await self.validate_input(user_input))
is None:
38 user_input[CONF_HOST] == entry.data[CONF_HOST]
39 and user_input[CONF_PORT] == entry.data[CONF_PORT]
43 entry, data=user_input
50 errors[
"base"] = error
51 user_input = user_input
or {}
54 vol.Required(CONF_HOST, default=user_input.get(CONF_HOST)): cv.string,
56 CONF_USERNAME, default=user_input.get(CONF_USERNAME)
58 vol.Required(CONF_PASSWORD, default=
""): cv.string,
60 CONF_PORT, default=user_input.get(CONF_PORT, DEFAULT_RPC_PORT)
64 default=user_input.get(CONF_WEB_PORT, DEFAULT_WEB_PORT),
70 async
def async_step_reauth(
71 self, entry_data: Mapping[str, Any]
72 ) -> ConfigFlowResult:
73 """Handle a reauthorization flow request."""
76 async
def validate_input(self, user_input: dict[str, Any]) -> str |
None:
77 """Handle common flow input validation."""
78 host = user_input[CONF_HOST]
79 port = user_input[CONF_PORT]
80 username = user_input[CONF_USERNAME]
81 password = user_input[CONF_PASSWORD]
82 api = DelugeRPCClient(
83 host=host, port=port, username=username, password=password, decode_utf8=
True
86 await self.hass.async_add_executor_job(api.connect)
87 except (ConnectionRefusedError, TimeoutError, SSLError):
88 return "cannot_connect"
89 except Exception
as ex:
90 if type(ex).__name__ ==
"BadLoginError":
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)
list[ConfigEntry] _async_current_entries(self, bool|None include_ignore=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_step_user(self, dict[str, Any]|None user_input=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)
_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)
VersionInfo validate_input(HomeAssistant hass, dict user_input)