1 """Config flow for the Vallox integration."""
3 from __future__
import annotations
8 from vallox_websocket_api
import Vallox, ValloxApiException
9 import voluptuous
as vol
17 from .const
import DEFAULT_NAME, DOMAIN
19 _LOGGER = logging.getLogger(__name__)
21 CONFIG_SCHEMA = vol.Schema(
23 vol.Required(CONF_HOST): str,
29 """Validate that the user input allows us to connect."""
35 await client.fetch_metric_data()
39 """Handle a config flow for the Vallox integration."""
44 self, user_input: dict[str, Any] |
None =
None
45 ) -> ConfigFlowResult:
46 """Handle the initial step."""
47 if user_input
is None:
50 data_schema=CONFIG_SCHEMA,
53 errors: dict[str, str] = {}
55 host = user_input[CONF_HOST]
62 errors[CONF_HOST] =
"invalid_host"
63 except ValloxApiException:
64 errors[CONF_HOST] =
"cannot_connect"
66 _LOGGER.exception(
"Unexpected exception")
67 errors[CONF_HOST] =
"unknown"
73 CONF_NAME: DEFAULT_NAME,
80 CONFIG_SCHEMA, {CONF_HOST: host}
86 self, user_input: dict[str, Any] |
None =
None
87 ) -> ConfigFlowResult:
88 """Handle reconfiguration of the Vallox device host address."""
92 step_id=
"reconfigure",
94 CONFIG_SCHEMA, {CONF_HOST: reconfigure_entry.data.get(CONF_HOST)}
98 updated_host = user_input[CONF_HOST]
100 if reconfigure_entry.data.get(CONF_HOST) != updated_host:
103 errors: dict[str, str] = {}
108 errors[CONF_HOST] =
"invalid_host"
109 except ValloxApiException:
110 errors[CONF_HOST] =
"cannot_connect"
112 _LOGGER.exception(
"Unexpected exception")
113 errors[CONF_HOST] =
"unknown"
116 reconfigure_entry, data_updates={CONF_HOST: updated_host}
120 step_id=
"reconfigure",
122 CONFIG_SCHEMA, {CONF_HOST: updated_host}
129 """Error to indicate an invalid host was input."""
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reconfigure(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)
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)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=None)
ConfigEntry _get_reconfigure_entry(self)
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)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_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_host(HomeAssistant hass, str host)
bool is_ip_address(str address)