1 """Support for Devialet Phantom speakers."""
3 from __future__
import annotations
8 from devialet.devialet_api
import DevialetApi
9 import voluptuous
as vol
16 from .const
import DOMAIN
18 LOGGER = logging.getLogger(__package__)
22 """Config flow for Devialet."""
32 """Initialize flow."""
33 self._errors: dict[str, str] = {}
36 """Validate the input using the Devialet API."""
40 client = DevialetApi(self.
_host_host, session)
42 if not await client.async_update()
or client.serial
is None:
43 self._errors[
"base"] =
"cannot_connect"
44 LOGGER.error(
"Cannot connect")
51 title=client.device_name,
52 data={CONF_HOST: self.
_host_host, CONF_NAME: client.device_name},
56 self, user_input: dict[str, Any] |
None =
None
57 ) -> ConfigFlowResult:
58 """Handle a flow initialized by the user or zeroconf."""
60 if user_input
is not None:
61 self.
_host_host = user_input[CONF_HOST]
63 if result
is not None:
68 data_schema=vol.Schema({vol.Required(CONF_HOST): str}),
73 self, discovery_info: zeroconf.ZeroconfServiceInfo
74 ) -> ConfigFlowResult:
75 """Handle a flow initialized by zeroconf discovery."""
76 LOGGER.debug(
"Devialet device found via ZEROCONF: %s", discovery_info)
78 self.
_host_host = discovery_info.host
79 self.
_name_name = discovery_info.name.split(
".", 1)[0]
80 self.
_model_model = discovery_info.properties[
"model"]
81 self.
_serial_serial = discovery_info.properties[
"serialNumber"]
86 self.context[
"title_placeholders"] = {
"title": self.
_name_name}
90 self, user_input: dict[str, Any] |
None =
None
91 ) -> ConfigFlowResult:
92 """Handle user-confirmation of discovered node."""
93 title = f
"{self._name} ({self._model})"
95 if user_input
is not None:
97 if result
is not None:
102 description_placeholders={
"device": self.
_model_model,
"title": title},
ConfigFlowResult async_step_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
ConfigFlowResult|None async_validate_input(self)
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_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)
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)