1 """Config flow for Lupusec integration."""
3 from json
import JSONDecodeError
8 import voluptuous
as vol
15 from .const
import DOMAIN
17 _LOGGER = logging.getLogger(__name__)
19 DATA_SCHEMA = vol.Schema(
21 vol.Required(CONF_HOST): str,
22 vol.Required(CONF_USERNAME): str,
23 vol.Required(CONF_PASSWORD): str,
29 """Lupusec config flow."""
32 self, user_input: dict[str, Any] |
None =
None
33 ) -> ConfigFlowResult:
34 """Handle a flow initiated by the user."""
37 if user_input
is not None:
39 host = user_input[CONF_HOST]
40 username = user_input[CONF_USERNAME]
41 password = user_input[CONF_PASSWORD]
46 errors[
"base"] =
"cannot_connect"
47 except JSONDecodeError:
48 errors[
"base"] =
"cannot_connect"
50 _LOGGER.exception(
"Unexpected exception")
51 errors[
"base"] =
"unknown"
60 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
65 hass: HomeAssistant, host: str, username: str, password: str
67 """Test if the host is reachable and is actually a Lupusec device."""
70 await hass.async_add_executor_job(lupupy.Lupusec, username, password, host)
71 except lupupy.LupusecException
as ex:
72 _LOGGER.error(
"Failed to connect to Lupusec device at %s", host)
73 raise CannotConnect
from ex
77 """Error to indicate we cannot connect."""
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)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=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)
def test_host_connection(HomeAssistant hass, str host, str username, str password)