1 """Config flow to configure Freedompro."""
5 from pyfreedompro
import get_list
6 import voluptuous
as vol
14 from .const
import DOMAIN
16 STEP_USER_DATA_SCHEMA = vol.Schema({vol.Required(CONF_API_KEY): str})
20 """Freedompro Hub class."""
22 def __init__(self, hass: HomeAssistant, api_key: str) ->
None:
23 """Freedompro Hub class init."""
28 """Freedompro Hub class authenticate."""
29 return await get_list(
30 aiohttp_client.async_get_clientsession(self.
_hass_hass), self.
_api_key_api_key
35 """Validate api key."""
36 hub =
Hub(hass, api_key)
37 result = await hub.authenticate()
38 if result[
"state"]
is False:
39 if result[
"code"] == -201:
41 if result[
"code"] == -200:
46 """Handle a config flow."""
51 self, user_input: dict[str, Any] |
None =
None
52 ) -> ConfigFlowResult:
53 """Show the setup form to the user."""
54 if user_input
is None:
56 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA
64 errors[
"base"] =
"cannot_connect"
66 errors[
"base"] =
"invalid_auth"
71 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
76 """Error to indicate we cannot connect."""
79 class InvalidAuth(HomeAssistantError):
80 """Error to indicate there is invalid auth."""
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None __init__(self, HomeAssistant hass, str api_key)
dict[str, Any] authenticate(self)
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)
None validate_input(HomeAssistant hass, str api_key)