1 """Config flow for mütesync integration."""
3 from __future__
import annotations
10 import voluptuous
as vol
17 from .const
import DOMAIN
19 STEP_USER_DATA_SCHEMA = vol.Schema({vol.Required(
"host"): str})
22 async
def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
23 """Validate the user input allows us to connect.
25 Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
29 async
with asyncio.timeout(5):
30 token = await mutesync.authenticate(session, data[
"host"])
31 except aiohttp.ClientResponseError
as error:
32 if error.status == 403:
33 raise InvalidAuth
from error
34 raise CannotConnect
from error
35 except (aiohttp.ClientError, TimeoutError)
as error:
36 raise CannotConnect
from error
42 """Handle a config flow for mütesync."""
47 self, user_input: dict[str, Any] |
None =
None
48 ) -> ConfigFlowResult:
49 """Handle the initial step."""
50 if user_input
is None:
52 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA
60 errors[
"base"] =
"cannot_connect"
62 errors[
"base"] =
"invalid_auth"
64 errors[
"base"] =
"unknown"
67 title=user_input[
"host"],
68 data={
"token": token,
"host": user_input[
"host"]},
72 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
77 """Error to indicate we cannot connect."""
81 """Error to indicate there is invalid auth."""
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)
dict[str, Any] validate_input(HomeAssistant hass, dict[str, Any] data)
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)