1 """Config flow for Volumio integration."""
3 from __future__
import annotations
8 from pyvolumio
import CannotConnectError, Volumio
9 import voluptuous
as vol
18 from .const
import DOMAIN
20 _LOGGER = logging.getLogger(__name__)
23 DATA_SCHEMA = vol.Schema(
24 {vol.Required(CONF_HOST): str, vol.Required(CONF_PORT, default=3000): int}
28 async
def validate_input(hass: HomeAssistant, host: str, port: int) -> dict[str, Any]:
29 """Validate the user input allows us to connect."""
33 return await volumio.get_system_info()
34 except CannotConnectError
as error:
35 raise CannotConnect
from error
39 """Handle a config flow for Volumio."""
51 title=self.
_name_name,
53 CONF_NAME: self.
_name_name,
54 CONF_HOST: self.
_host_host,
55 CONF_PORT: self.
_port_port,
56 CONF_ID: self.
_uuid_uuid,
64 CONF_HOST: self.
_host_host,
65 CONF_PORT: self.
_port_port,
66 CONF_NAME: self.
_name_name,
71 self, user_input: dict[str, Any] |
None =
None
72 ) -> ConfigFlowResult:
73 """Handle the initial step."""
75 if user_input
is not None:
77 self.
_host_host = user_input[CONF_HOST]
78 self.
_port_port = user_input[CONF_PORT]
82 errors[
"base"] =
"cannot_connect"
84 _LOGGER.exception(
"Unexpected exception")
85 errors[
"base"] =
"unknown"
89 self.
_uuid_uuid = info.get(
"id")
90 if self.
_uuid_uuid
is not None:
96 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
100 self, discovery_info: zeroconf.ZeroconfServiceInfo
101 ) -> ConfigFlowResult:
102 """Handle zeroconf discovery."""
103 self.
_host_host = discovery_info.host
104 self.
_port_port = discovery_info.port
or 3000
105 self.
_name_name = discovery_info.properties[
"volumioName"]
106 self.
_uuid_uuid = discovery_info.properties[
"UUID"]
113 self, user_input: dict[str, Any] |
None =
None
114 ) -> ConfigFlowResult:
115 """Handle user-confirmation of discovered node."""
116 if user_input
is not None:
120 except CannotConnect:
124 step_id=
"discovery_confirm", description_placeholders={
"name": self.
_name_name}
129 """Error to indicate we cannot connect."""
def _set_uid_and_abort(self)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult _async_get_entry(self)
ConfigFlowResult async_step_discovery_confirm(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)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=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)
dict[str, Any] validate_input(HomeAssistant hass, str host, int port)
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)