1 """Config flow for Discord integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from aiohttp.client_exceptions
import ClientConnectorError
11 import voluptuous
as vol
16 from .const
import DOMAIN, URL_PLACEHOLDER
18 _LOGGER = logging.getLogger(__name__)
20 CONFIG_SCHEMA = vol.Schema({vol.Required(CONF_API_TOKEN): str})
24 """Handle a config flow for Discord."""
27 self, entry_data: Mapping[str, Any]
28 ) -> ConfigFlowResult:
29 """Handle a reauthorization flow request."""
30 return await self.async_step_reauth_confirm()
32 async
def async_step_reauth_confirm(
33 self, user_input: dict[str, str] |
None =
None
34 ) -> ConfigFlowResult:
35 """Confirm reauth dialog."""
42 entry, data=entry.data | user_input
45 errors[
"base"] = error
47 user_input = user_input
or {}
49 step_id=
"reauth_confirm",
50 data_schema=CONFIG_SCHEMA,
51 description_placeholders=URL_PLACEHOLDER,
56 self, user_input: dict[str, str] |
None =
None
57 ) -> ConfigFlowResult:
58 """Handle a flow initiated by the user."""
61 if user_input
is not None:
64 errors[
"base"] = error
65 elif info
is not None:
70 data=user_input | {CONF_NAME: info.name},
73 user_input = user_input
or {}
76 data_schema=CONFIG_SCHEMA,
77 description_placeholders=URL_PLACEHOLDER,
83 """Try connecting to Discord."""
84 discord_bot = nextcord.Client()
86 await discord_bot.login(token)
87 info = await discord_bot.application_info()
88 except nextcord.LoginFailure:
89 return "invalid_auth",
None
90 except (ClientConnectorError, nextcord.HTTPException, nextcord.NotFound):
91 return "cannot_connect",
None
93 _LOGGER.exception(
"Unexpected exception")
94 return "unknown",
None
95 await discord_bot.close()
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
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_step_user(self, dict[str, Any]|None user_input=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)
tuple[str|None, nextcord.AppInfo|None] _async_try_connect(str token)