1 """Config flow to configure Heos."""
3 from typing
import TYPE_CHECKING, Any
4 from urllib.parse
import urlparse
6 from pyheos
import Heos, HeosError
7 import voluptuous
as vol
13 from .const
import DATA_DISCOVERED_HOSTS, DOMAIN
17 """Format the title for config entries."""
18 return f
"Controller ({host})"
22 """Define a flow for HEOS."""
27 self, discovery_info: ssdp.SsdpServiceInfo
28 ) -> ConfigFlowResult:
29 """Handle a discovered Heos device."""
32 assert discovery_info.ssdp_location
33 hostname = urlparse(discovery_info.ssdp_location).hostname
35 f
"{discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME]} ({hostname})"
37 self.hass.data.setdefault(DATA_DISCOVERED_HOSTS, {})
38 self.hass.data[DATA_DISCOVERED_HOSTS][friendly_name] = hostname
47 """Occurs when an entry is setup through config."""
48 host = import_data[CONF_HOST]
55 self, user_input: dict[str, Any] |
None =
None
56 ) -> ConfigFlowResult:
57 """Obtain host and validate connection."""
58 self.hass.data.setdefault(DATA_DISCOVERED_HOSTS, {})
65 if user_input
is not None:
66 host = user_input[CONF_HOST]
68 host = self.hass.data[DATA_DISCOVERED_HOSTS].
get(host, host)
72 self.hass.data.pop(DATA_DISCOVERED_HOSTS)
75 errors[CONF_HOST] =
"cannot_connect"
77 await heos.disconnect()
82 if not self.hass.data[DATA_DISCOVERED_HOSTS]
83 else vol.In(
list(self.hass.data[DATA_DISCOVERED_HOSTS]))
87 data_schema=vol.Schema({vol.Required(CONF_HOST, default=host): host_type}),
ConfigFlowResult async_step_import(self, dict[str, Any] import_data)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_ssdp(self, ssdp.SsdpServiceInfo discovery_info)
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)
list[ConfigEntry] _async_current_entries(self, bool|None include_ignore=None)
list[ConfigFlowResult] _async_in_progress(self, bool include_uninitialized=False, dict[str, Any]|None match_context=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)
web.Response get(self, web.Request request, str config_key)
str format_title(str host)