1 """Config flow to configure forked-daapd devices."""
3 from contextlib
import suppress
7 from pyforked_daapd
import ForkedDaapdAPI
8 import voluptuous
as vol
22 CONF_LIBRESPOT_JAVA_PORT,
27 DEFAULT_TTS_PAUSE_TIME,
32 _LOGGER = logging.getLogger(__name__)
37 vol.Required(CONF_HOST): str,
38 vol.Optional(CONF_PORT, default=DEFAULT_PORT): int,
39 vol.Optional(CONF_PASSWORD, default=
""): str,
42 TEST_CONNECTION_ERROR_DICT = {
43 "forbidden":
"forbidden",
45 "websocket_not_enabled":
"websocket_not_enabled",
46 "wrong_host_or_port":
"wrong_host_or_port",
47 "wrong_password":
"wrong_password",
48 "wrong_server_type":
"wrong_server_type",
53 """Handle a forked-daapd options flow."""
56 self, user_input: dict[str, Any] |
None =
None
57 ) -> ConfigFlowResult:
58 """Manage the options."""
59 if user_input
is not None:
64 data_schema=vol.Schema(
69 CONF_TTS_PAUSE_TIME, DEFAULT_TTS_PAUSE_TIME
75 CONF_TTS_VOLUME, DEFAULT_TTS_VOLUME
79 CONF_LIBRESPOT_JAVA_PORT,
81 CONF_LIBRESPOT_JAVA_PORT, 24879
94 """Fill in schema dict defaults from user_input."""
96 for field, _type
in DATA_SCHEMA_DICT.items():
97 if some_input.get(
str(field)):
98 schema_dict[vol.Optional(
str(field), default=some_input[
str(field)])] = (
102 schema_dict[field] = _type
107 """Handle a forked-daapd config flow."""
118 config_entry: ConfigEntry,
119 ) -> ForkedDaapdOptionsFlowHandler:
120 """Return options flow handler."""
124 """Validate the user input."""
126 validate_result = await ForkedDaapdAPI.test_connection(
127 websession=websession,
128 host=user_input[CONF_HOST],
129 port=user_input[CONF_PORT],
130 password=user_input[CONF_PASSWORD],
132 validate_result[0] = TEST_CONNECTION_ERROR_DICT.get(
133 validate_result[0],
"unknown_error"
135 return validate_result
138 self, user_input: dict[str, Any] |
None =
None
139 ) -> ConfigFlowResult:
140 """Handle a forked-daapd config flow start.
142 Manage device specific parameters.
144 if user_input
is not None:
147 validate_result = await self.
validate_inputvalidate_input(user_input)
148 if validate_result[0] ==
"ok":
149 _LOGGER.debug(
"Connected successfully. Creating entry")
151 title=validate_result[1], data=user_input
156 errors={
"base": validate_result[0]},
160 step_id=
"user", data_schema=self.
discovery_schemadiscovery_schema, errors={}
163 step_id=
"user", data_schema=vol.Schema(DATA_SCHEMA_DICT), errors={}
167 self, discovery_info: zeroconf.ZeroconfServiceInfo
168 ) -> ConfigFlowResult:
169 """Prepare configuration for a discovered forked-daapd device."""
171 zeroconf_properties = discovery_info.properties
172 if zeroconf_properties.get(
"Machine Name"):
173 with suppress(ValueError):
175 zeroconf_properties.get(
"mtd-version",
"0").split(
".")[0]
184 if entry.data.get(CONF_HOST) != discovery_info.host:
186 self.hass.config_entries.async_update_entry(
188 title=zeroconf_properties[
"Machine Name"],
193 CONF_HOST: discovery_info.host,
194 CONF_PORT: discovery_info.port,
195 CONF_NAME: zeroconf_properties[
"Machine Name"],
198 self.context.
update({
"title_placeholders": zeroconf_data})
def validate_input(self, user_input)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ForkedDaapdOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
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|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)
list[ConfigEntry] _async_current_entries(self, bool|None include_ignore=None)
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)
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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_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)
def fill_in_schema_dict(some_input)
IssData update(pyiss.ISS iss)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)