1 """Config flow for RTSPtoWebRTC."""
3 from __future__
import annotations
7 from urllib.parse
import urlparse
10 import voluptuous
as vol
23 from .
import CONF_STUN_SERVER, DATA_SERVER_URL, DOMAIN
25 _LOGGER = logging.getLogger(__name__)
27 DATA_SCHEMA = vol.Schema({vol.Required(DATA_SERVER_URL): str})
31 """RTSPtoWebRTC config flow."""
33 _hassio_discovery: dict[str, Any]
36 self, user_input: dict[str, Any] |
None =
None
37 ) -> ConfigFlowResult:
38 """Configure the RTSPtoWebRTC server url."""
42 if user_input
is None:
45 url = user_input[DATA_SERVER_URL]
46 result = urlparse(url)
47 if not all([result.scheme, result.netloc]):
50 data_schema=DATA_SCHEMA,
51 errors={DATA_SERVER_URL:
"invalid_url"},
54 if error_code := await self._test_connection(url):
57 data_schema=DATA_SCHEMA,
58 errors={
"base": error_code},
64 data={DATA_SERVER_URL: url},
67 async
def _test_connection(self, url: str) -> str |
None:
68 """Test the connection and return any relevant errors."""
71 await client.heartbeat()
72 except rtsp_to_webrtc.exceptions.ResponseError
as err:
73 _LOGGER.error(
"RTSPtoWebRTC server failure: %s",
str(err))
74 return "server_failure"
75 except rtsp_to_webrtc.exceptions.ClientError
as err:
76 _LOGGER.error(
"RTSPtoWebRTC communication failure: %s",
str(err))
77 return "server_unreachable"
81 self, discovery_info: HassioServiceInfo
82 ) -> ConfigFlowResult:
83 """Prepare configuration for the RTSPtoWebRTC server add-on discovery."""
88 return await self.async_step_hassio_confirm()
90 async
def async_step_hassio_confirm(
91 self, user_input: dict[str, Any] |
None =
None
92 ) -> ConfigFlowResult:
93 """Confirm Add-on discovery."""
95 if user_input
is not None:
99 url = f
"http://{host}:{port}"
100 if error_code := await self._test_connection(url):
103 if user_input
is None or errors:
106 step_id=
"hassio_confirm",
107 description_placeholders={
"addon": self.
_hassio_discovery_hassio_discovery[
"addon"]},
113 data={DATA_SERVER_URL: url},
119 config_entry: ConfigEntry,
121 """Create an options flow."""
126 """RTSPtoWeb Options flow."""
129 self, user_input: dict[str, Any] |
None =
None
130 ) -> ConfigFlowResult:
131 """Manage the options."""
132 if user_input
is not None:
137 data_schema=vol.Schema(
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
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)
ConfigFlowResult async_step_hassio(self, HassioServiceInfo discovery_info)
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)
OptionsFlow async_get_options_flow(ConfigEntry config_entry)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_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)
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)