1 """Config flow for Evil Genius Labs integration."""
3 from __future__
import annotations
11 import voluptuous
as vol
18 from .const
import DOMAIN
20 _LOGGER = logging.getLogger(__name__)
23 async
def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
24 """Validate the user input allows us to connect.
26 Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
28 hub = pyevilgenius.EvilGeniusDevice(
29 data[
"host"], aiohttp_client.async_get_clientsession(hass)
33 async
with asyncio.timeout(10):
34 data = await hub.get_all()
35 info = await hub.get_info()
36 except aiohttp.ClientError
as err:
37 _LOGGER.debug(
"Unable to connect: %s", err)
38 raise CannotConnect
from err
40 return {
"title": data[
"name"][
"value"],
"unique_id": info[
"wiFiChipId"]}
44 """Handle a config flow for Evil Genius Labs."""
49 self, user_input: dict[str, Any] |
None =
None
50 ) -> ConfigFlowResult:
51 """Handle the initial step."""
52 if user_input
is None:
55 data_schema=vol.Schema(
57 vol.Required(
"host"): str,
67 errors[
"base"] =
"timeout"
69 errors[
"base"] =
"cannot_connect"
71 _LOGGER.exception(
"Unexpected exception")
72 errors[
"base"] =
"unknown"
79 data_schema=vol.Schema(
81 vol.Required(
"host", default=user_input[
"host"]): str,
89 """Error to indicate we cannot connect."""
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)
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)