1 """Config flow for Livisi Home Assistant."""
3 from __future__
import annotations
5 from contextlib
import suppress
8 from aiohttp
import ClientConnectorError
9 from aiolivisi
import AioLivisi, errors
as livisi_errors
10 import voluptuous
as vol
16 from .const
import DOMAIN, LOGGER
20 """Handle a Livisi Smart Home config flow."""
23 """Create the configuration file."""
27 vol.Required(CONF_HOST): str,
28 vol.Required(CONF_PASSWORD): str,
33 self, user_input: dict[str, str] |
None =
None
34 ) -> ConfigFlowResult:
35 """Handle the initial step."""
36 if user_input
is None:
41 await self.
_login_login(user_input)
42 except livisi_errors.WrongCredentialException:
43 errors[
"base"] =
"wrong_password"
44 except livisi_errors.ShcUnreachableException:
45 errors[
"base"] =
"cannot_connect"
46 except livisi_errors.IncorrectIpAddressException:
47 errors[
"base"] =
"wrong_ip_address"
49 controller_info: dict[str, Any] = {}
50 with suppress(ClientConnectorError):
53 return await self.
create_entitycreate_entity(user_input, controller_info)
54 errors[
"base"] =
"cannot_connect"
57 step_id=
"user", data_schema=self.
data_schemadata_schema, errors=errors
60 async
def _login(self, user_input: dict[str, str]) ->
None:
61 """Login into Livisi Smart Home."""
62 web_session = aiohttp_client.async_get_clientsession(self.hass)
64 livisi_connection_data = {
65 "ip_address": user_input[CONF_HOST],
66 "password": user_input[CONF_PASSWORD],
69 await self.
aio_livisiaio_livisi.async_set_token(livisi_connection_data)
72 self, user_input: dict[str, str], controller_info: dict[str, Any]
73 ) -> ConfigFlowResult:
74 """Create LIVISI entity."""
75 if (controller_data := controller_info.get(
"gateway"))
is None:
76 controller_data = controller_info
77 controller_type = controller_data[
"controllerType"]
79 "Integrating SHC %s with serial number: %s",
81 controller_data[
"serialNumber"],
85 title=f
"SHC {controller_type}",
None _login(self, dict[str, str] user_input)
ConfigFlowResult create_entity(self, dict[str, str] user_input, dict[str, Any] controller_info)
ConfigFlowResult async_step_user(self, dict[str, str]|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)
Controller|None async_get_controller(HomeAssistant hass, str ip_address, str password, int port, bool ssl)