1 """Config flow to configure LinkPlay component."""
6 from aiohttp
import ClientSession
7 from linkplay.bridge
import LinkPlayBridge
8 from linkplay.discovery
import linkplay_factory_httpapi_bridge
9 from linkplay.exceptions
import LinkPlayRequestException
10 import voluptuous
as vol
16 from .const
import DOMAIN
17 from .utils
import async_get_client_session
19 _LOGGER = logging.getLogger(__name__)
23 """LinkPlay config flow."""
26 """Initialize the LinkPlay config flow."""
27 self.data: dict[str, Any] = {}
30 self, discovery_info: zeroconf.ZeroconfServiceInfo
31 ) -> ConfigFlowResult:
32 """Handle Zeroconf discovery."""
35 bridge: LinkPlayBridge |
None =
None
38 bridge = await linkplay_factory_httpapi_bridge(discovery_info.host, session)
39 except LinkPlayRequestException:
41 "Failed to connect to LinkPlay device at %s", discovery_info.host
45 self.data[CONF_HOST] = discovery_info.host
46 self.data[CONF_MODEL] = bridge.device.name
51 self.context[
"title_placeholders"] = {
52 "name": self.data[CONF_MODEL],
57 self, user_input: dict[str, Any] |
None =
None
58 ) -> ConfigFlowResult:
59 """Confirm discovery."""
60 if user_input
is not None:
62 title=self.data[CONF_MODEL],
63 data={CONF_HOST: self.data[CONF_HOST]},
68 step_id=
"discovery_confirm",
69 description_placeholders={
70 "name": self.data[CONF_MODEL],
75 self, user_input: dict[str, Any] |
None =
None
76 ) -> ConfigFlowResult:
77 """Handle a flow initialized by the user."""
78 errors: dict[str, str] = {}
81 bridge: LinkPlayBridge |
None =
None
84 bridge = await linkplay_factory_httpapi_bridge(
85 user_input[CONF_HOST], session
87 except LinkPlayRequestException:
89 "Failed to connect to LinkPlay device at %s", user_input[CONF_HOST]
91 errors[
"base"] =
"cannot_connect"
93 if bridge
is not None:
94 self.data[CONF_HOST] = user_input[CONF_HOST]
95 self.data[CONF_MODEL] = bridge.device.name
98 bridge.device.uuid, raise_on_progress=
False
101 updates={CONF_HOST: self.data[CONF_HOST]}
105 title=self.data[CONF_MODEL],
106 data={CONF_HOST: self.data[CONF_HOST]},
111 data_schema=vol.Schema({vol.Required(CONF_HOST): str}),
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_discovery_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
None _set_confirm_only(self)
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)
ClientSession async_get_client_session(HomeAssistant hass)