1 """Config flow for Fibaro integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from slugify
import slugify
10 import voluptuous
as vol
16 from .
import FibaroAuthFailed, FibaroConnectFailed, init_controller
17 from .const
import CONF_IMPORT_PLUGINS, DOMAIN
19 _LOGGER = logging.getLogger(__name__)
21 STEP_USER_DATA_SCHEMA = vol.Schema(
23 vol.Required(CONF_URL): str,
24 vol.Required(CONF_USERNAME): str,
25 vol.Required(CONF_PASSWORD): str,
26 vol.Optional(CONF_IMPORT_PLUGINS, default=
False): bool,
31 async
def _validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
32 """Validate the user input allows us to connect.
34 Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
36 controller = await hass.async_add_executor_job(init_controller, data)
39 "Successfully connected to fibaro home center %s with name %s",
40 controller.hub_serial,
44 "serial_number":
slugify(controller.hub_serial),
45 "name": controller.hub_name,
50 """Try to fix errors in the entered url.
52 We know that the url should be in the format http://<HOST>/api/
54 if url.endswith(
"/api"):
56 if not url.endswith(
"/api/"):
57 return f
"{url}api/" if url.endswith(
"/")
else f
"{url}/api/"
62 """Handle a config flow for Fibaro."""
67 self, user_input: dict[str, Any] |
None =
None
68 ) -> ConfigFlowResult:
69 """Handle the initial step."""
72 if user_input
is not None:
76 except FibaroConnectFailed:
77 errors[
"base"] =
"cannot_connect"
78 except FibaroAuthFailed:
79 errors[
"base"] =
"invalid_auth"
86 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
90 self, entry_data: Mapping[str, Any]
91 ) -> ConfigFlowResult:
92 """Handle reauthentication."""
96 self, user_input: dict[str, Any] |
None =
None
97 ) -> ConfigFlowResult:
98 """Handle a flow initiated by reauthentication."""
103 if user_input
is not None:
104 new_data = reauth_entry.data | user_input
107 except FibaroConnectFailed:
108 errors[
"base"] =
"cannot_connect"
109 except FibaroAuthFailed:
110 errors[
"base"] =
"invalid_auth"
113 reauth_entry, data_updates=user_input
117 step_id=
"reauth_confirm",
118 data_schema=vol.Schema({vol.Required(CONF_PASSWORD): str}),
120 description_placeholders={
121 CONF_USERNAME: reauth_entry.data[CONF_USERNAME],
122 CONF_NAME: reauth_entry.title,
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry _get_reauth_entry(self)
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_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
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)
str _normalize_url(str url)
dict[str, Any] _validate_input(HomeAssistant hass, dict[str, Any] data)