1 """Config flow to configure russound_rio component."""
3 from __future__
import annotations
9 from aiorussound
import RussoundClient, RussoundTcpConnectionHandler
10 import voluptuous
as vol
16 from .const
import CONNECT_TIMEOUT, DOMAIN, RUSSOUND_RIO_EXCEPTIONS
18 DATA_SCHEMA = vol.Schema(
20 vol.Required(CONF_HOST): cv.string,
21 vol.Optional(CONF_PORT, default=9621): cv.port,
25 _LOGGER = logging.getLogger(__name__)
29 """Russound RIO configuration flow."""
34 self, user_input: dict[str, Any] |
None =
None
35 ) -> ConfigFlowResult:
36 """Handle a flow initialized by the user."""
37 errors: dict[str, str] = {}
38 if user_input
is not None:
39 host = user_input[CONF_HOST]
40 port = user_input[CONF_PORT]
42 client = RussoundClient(RussoundTcpConnectionHandler(host, port))
44 async
with asyncio.timeout(CONNECT_TIMEOUT):
45 await client.connect()
46 controller = client.controllers[1]
47 await client.disconnect()
48 except RUSSOUND_RIO_EXCEPTIONS:
49 _LOGGER.exception(
"Could not connect to Russound RIO")
50 errors[
"base"] =
"cannot_connect"
54 data = {CONF_HOST: host, CONF_PORT: port}
56 title=controller.controller_type, data=data
60 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
64 """Attempt to import the existing configuration."""
66 host = import_data[CONF_HOST]
67 port = import_data.get(CONF_PORT, 9621)
70 client = RussoundClient(RussoundTcpConnectionHandler(host, port))
72 async
with asyncio.timeout(CONNECT_TIMEOUT):
73 await client.connect()
74 controller = client.controllers[1]
75 await client.disconnect()
76 except RUSSOUND_RIO_EXCEPTIONS:
77 _LOGGER.exception(
"Could not connect to Russound RIO")
79 reason=
"cannot_connect", description_placeholders={}
84 data = {CONF_HOST: host, CONF_PORT: port}
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_import(self, dict[str, Any] import_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_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)