1 """Config flow for WS66i 6-Zone Amplifier integration."""
3 from __future__
import annotations
8 from pyws66i
import WS66i, get_ws66i
9 import voluptuous
as vol
33 _LOGGER = logging.getLogger(__name__)
44 OPTIONS_SCHEMA = {vol.Optional(source): str
for source
in SOURCES}
46 DATA_SCHEMA = vol.Schema({vol.Required(CONF_IP_ADDRESS): str})
54 str(idx + 1): data.get(source)
for idx, source
in enumerate(SOURCES)
59 for index, name
in sources_config.items()
60 if (name
is not None and name.strip() !=
"")
65 """Verify a connection can be made to the WS66i."""
68 except ConnectionError
as err:
69 raise CannotConnect
from err
73 ret_val = ws66i.zone_status(FIRST_ZONE)
81 hass: HomeAssistant, input_data: dict[str, Any]
83 """Validate the user input.
85 Data has the keys from DATA_SCHEMA with values provided by the user.
87 ws66i: WS66i = get_ws66i(input_data[CONF_IP_ADDRESS])
89 is_valid: bool = await hass.async_add_executor_job(_verify_connection, ws66i)
94 return {CONF_IP_ADDRESS: input_data[CONF_IP_ADDRESS]}
98 """Handle a config flow for WS66i 6-Zone Amplifier."""
103 self, user_input: dict[str, Any] |
None =
None
104 ) -> ConfigFlowResult:
105 """Handle the initial step."""
107 if user_input
is not None:
110 except CannotConnect:
111 errors[
"base"] =
"cannot_connect"
113 _LOGGER.exception(
"Unexpected exception")
114 errors[
"base"] =
"unknown"
120 options={CONF_SOURCES: INIT_OPTIONS_DEFAULT},
124 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
130 config_entry: ConfigEntry,
131 ) -> Ws66iOptionsFlowHandler:
132 """Define the config flow to handle options."""
138 index: int, source: str, previous_sources: dict[str, str]
141 source, description={
"suggested_value": previous_sources[
str(index)]}
146 """Handle a WS66i options flow."""
149 self, user_input: dict[str, str] |
None =
None
150 ) -> ConfigFlowResult:
151 """Manage the options."""
152 if user_input
is not None:
154 title=
"Source Names",
162 for idx, source
in enumerate(SOURCES)
167 data_schema=vol.Schema(options),
172 """Error to indicate we cannot connect."""
Ws66iOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_init(self, dict[str, str]|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_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)
bool _verify_connection(WS66i ws66i)
vol.Required _key_for_source(int index, str source, dict[str, str] previous_sources)
dict[str, Any] validate_input(HomeAssistant hass, dict[str, Any] input_data)
dict[str, str] _sources_from_config(dict[str, str] data)