1 """Music Player Daemon config flow."""
3 from asyncio
import timeout
4 from contextlib
import suppress
5 from socket
import gaierror
9 from mpd.asyncio
import MPDClient
10 import voluptuous
as vol
15 from .const
import DOMAIN, LOGGER
19 vol.Required(CONF_HOST): str,
20 vol.Optional(CONF_PASSWORD): str,
21 vol.Optional(CONF_PORT, default=6600): int,
27 """Music Player Daemon config flow."""
30 self, user_input: dict[str, Any] |
None =
None
31 ) -> ConfigFlowResult:
32 """Handle a flow initiated by the user."""
36 {CONF_HOST: user_input[CONF_HOST], CONF_PORT: user_input[CONF_PORT]}
40 client.idletimeout = 10
42 async
with timeout(35):
43 await client.connect(user_input[CONF_HOST], user_input[CONF_PORT])
44 if CONF_PASSWORD
in user_input:
45 await client.password(user_input[CONF_PASSWORD])
46 with suppress(mpd.ConnectionError):
54 errors[
"base"] =
"cannot_connect"
56 LOGGER.exception(
"Unknown exception")
57 errors[
"base"] =
"unknown"
60 title=
"Music Player Daemon",
70 async
def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
71 """Attempt to import the existing configuration."""
75 client.idletimeout = 10
77 async
with timeout(35):
78 await client.connect(import_data[CONF_HOST], import_data[CONF_PORT])
79 if CONF_PASSWORD
in import_data:
80 await client.password(import_data[CONF_PASSWORD])
81 with suppress(mpd.ConnectionError):
91 LOGGER.exception(
"Unknown exception")
95 title=import_data.get(CONF_NAME,
"Music Player Daemon"),
97 CONF_HOST: import_data[CONF_HOST],
98 CONF_PORT: import_data[CONF_PORT],
99 CONF_PASSWORD: import_data.get(CONF_PASSWORD),
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)
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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
config_entries.ConfigFlowResult async_step_import(self, dict[str, Any]|None _)