1 """Config flow for DirecTV."""
3 from __future__
import annotations
6 from typing
import Any, cast
7 from urllib.parse
import urlparse
9 from directv
import DIRECTV, DIRECTVError
10 import voluptuous
as vol
18 from .const
import CONF_RECEIVER_ID, DOMAIN
20 _LOGGER = logging.getLogger(__name__)
22 ERROR_CANNOT_CONNECT =
"cannot_connect"
23 ERROR_UNKNOWN =
"unknown"
27 """Validate the user input allows us to connect.
29 Data has the keys from DATA_SCHEMA with values provided by the user.
32 directv = DIRECTV(data[CONF_HOST], session=session)
33 device = await directv.update()
35 return {CONF_RECEIVER_ID: device.info.receiver_id}
39 """Handle a config flow for DirecTV."""
44 """Set up the instance."""
45 self.discovery_info: dict[str, Any] = {}
48 self, user_input: dict[str, Any] |
None =
None
49 ) -> ConfigFlowResult:
50 """Handle a flow initiated by the user."""
51 if user_input
is None:
59 _LOGGER.exception(
"Unexpected exception")
62 user_input[CONF_RECEIVER_ID] = info[CONF_RECEIVER_ID]
70 self, discovery_info: ssdp.SsdpServiceInfo
71 ) -> ConfigFlowResult:
72 """Handle SSDP discovery."""
75 host = cast(str, urlparse(discovery_info.ssdp_location).hostname)
78 if discovery_info.upnp.get(ssdp.ATTR_UPNP_SERIAL):
79 receiver_id = discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL][
83 self.context.
update({
"title_placeholders": {
"name": host}})
85 self.discovery_info.
update(
86 {CONF_HOST: host, CONF_NAME: host, CONF_RECEIVER_ID: receiver_id}
94 _LOGGER.exception(
"Unexpected exception")
97 self.discovery_info[CONF_RECEIVER_ID] = info[CONF_RECEIVER_ID]
101 updates={CONF_HOST: self.discovery_info[CONF_HOST]}
107 self, user_input: dict[str, Any] |
None =
None
108 ) -> ConfigFlowResult:
109 """Handle a confirmation flow initiated by SSDP."""
110 if user_input
is None:
112 step_id=
"ssdp_confirm",
113 description_placeholders={
"name": self.discovery_info[CONF_NAME]},
118 title=self.discovery_info[CONF_NAME],
119 data=self.discovery_info,
123 """Show the setup form to the user."""
126 data_schema=vol.Schema({vol.Required(CONF_HOST): str}),
ConfigFlowResult async_step_ssdp(self, ssdp.SsdpServiceInfo discovery_info)
ConfigFlowResult _show_setup_form(self, dict|None errors=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_ssdp_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, dict data)
IssData update(pyiss.ISS iss)
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)