1 """Config flow for youless integration."""
3 from __future__
import annotations
7 from urllib.error
import HTTPError, URLError
9 import voluptuous
as vol
10 from youless_api
import YoulessAPI
15 from .const
import DOMAIN
17 _LOGGER = logging.getLogger(__name__)
19 DATA_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str})
23 """Handle a config flow for youless."""
28 self, user_input: dict[str, Any] |
None =
None
29 ) -> ConfigFlowResult:
30 """Handle the initial step."""
32 if user_input
is not None:
34 api = YoulessAPI(user_input[CONF_HOST])
35 await self.hass.async_add_executor_job(api.initialize)
36 except (HTTPError, URLError):
37 _LOGGER.exception(
"Cannot connect to host")
38 errors[
"base"] =
"cannot_connect"
41 title=user_input[CONF_HOST],
43 CONF_HOST: user_input[CONF_HOST],
44 CONF_DEVICE: api.mac_address,
49 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
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)