1 """Config flow for the Jellyfin integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 import voluptuous
as vol
16 from .
import JellyfinConfigEntry
17 from .client_wrapper
import CannotConnect, InvalidAuth, create_client, validate_input
18 from .const
import CONF_CLIENT_DEVICE_ID, DOMAIN, SUPPORTED_AUDIO_CODECS
20 _LOGGER = logging.getLogger(__name__)
22 STEP_USER_DATA_SCHEMA = vol.Schema(
24 vol.Required(CONF_URL): str,
25 vol.Required(CONF_USERNAME): str,
26 vol.Optional(CONF_PASSWORD, default=
""): str,
30 REAUTH_DATA_SCHEMA = vol.Schema(
32 vol.Optional(CONF_PASSWORD, default=
""): str,
37 OPTIONAL_DATA_SCHEMA = vol.Schema(
38 {vol.Optional(
"audio_codec"): vol.In(SUPPORTED_AUDIO_CODECS)}
43 """Generate a random UUID4 string to identify ourselves."""
48 """Handle a config flow for Jellyfin."""
53 """Initialize the Jellyfin config flow."""
57 self, user_input: dict[str, Any] |
None =
None
58 ) -> ConfigFlowResult:
59 """Handle a user defined configuration."""
60 errors: dict[str, str] = {}
62 if user_input
is not None:
69 self.hass, user_input, client
72 errors[
"base"] =
"cannot_connect"
74 errors[
"base"] =
"invalid_auth"
76 errors[
"base"] =
"unknown"
77 _LOGGER.exception(
"Unexpected exception")
79 entry_title = user_input[CONF_URL]
81 server_info: dict[str, Any] = connect_result[
"Servers"][0]
83 if server_name := server_info.get(
"Name"):
84 entry_title = server_name
91 data={CONF_CLIENT_DEVICE_ID: self.
client_device_idclient_device_id, **user_input},
97 STEP_USER_DATA_SCHEMA, user_input
103 self, entry_data: Mapping[str, Any]
104 ) -> ConfigFlowResult:
105 """Perform reauth upon an API authentication error."""
109 self, user_input: dict[str, Any] |
None =
None
110 ) -> ConfigFlowResult:
111 """Dialog that informs the user that reauth is required."""
112 errors: dict[str, str] = {}
114 if user_input
is not None:
116 new_input = reauth_entry.data | user_input
124 except CannotConnect:
125 errors[
"base"] =
"cannot_connect"
127 errors[
"base"] =
"invalid_auth"
129 errors[
"base"] =
"unknown"
130 _LOGGER.exception(
"Unexpected exception")
135 step_id=
"reauth_confirm", data_schema=REAUTH_DATA_SCHEMA, errors=errors
141 config_entry: JellyfinConfigEntry,
142 ) -> OptionsFlowHandler:
143 """Create the options flow."""
148 """Handle an option flow for jellyfin."""
151 self, user_input: dict[str, Any] |
None =
None
152 ) -> ConfigFlowResult:
153 """Manage the options."""
154 if user_input
is not None:
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
OptionsFlowHandler async_get_options_flow(JellyfinConfigEntry config_entry)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry _get_reauth_entry(self)
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_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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_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)
JellyfinClient create_client(str device_id, str|None device_name=None)
str _generate_client_device_id()
VersionInfo validate_input(HomeAssistant hass, dict user_input)