1 """Config flow for Comelit integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from aiocomelit
import (
9 ComeliteSerialBridgeApi,
11 exceptions
as aiocomelit_exceptions,
13 from aiocomelit.api
import ComelitCommonApi
14 from aiocomelit.const
import BRIDGE
15 import voluptuous
as vol
23 from .const
import _LOGGER, DEFAULT_PORT, DEVICE_TYPE_LIST, DOMAIN
25 DEFAULT_HOST =
"192.168.1.252"
30 """Return user form schema."""
31 user_input = user_input
or {}
34 vol.Required(CONF_HOST, default=DEFAULT_HOST): cv.string,
35 vol.Required(CONF_PORT, default=DEFAULT_PORT): cv.port,
36 vol.Optional(CONF_PIN, default=DEFAULT_PIN): cv.positive_int,
37 vol.Required(CONF_TYPE, default=BRIDGE): vol.In(DEVICE_TYPE_LIST),
42 STEP_REAUTH_DATA_SCHEMA = vol.Schema({vol.Required(CONF_PIN): cv.positive_int})
45 async
def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, str]:
46 """Validate the user input allows us to connect."""
49 if data.get(CONF_TYPE, BRIDGE) == BRIDGE:
50 api = ComeliteSerialBridgeApi(data[CONF_HOST], data[CONF_PORT], data[CONF_PIN])
52 api = ComelitVedoApi(data[CONF_HOST], data[CONF_PORT], data[CONF_PIN])
56 except aiocomelit_exceptions.CannotConnect
as err:
57 raise CannotConnect
from err
58 except aiocomelit_exceptions.CannotAuthenticate
as err:
59 raise InvalidAuth
from err
64 return {
"title": data[CONF_HOST]}
68 """Handle a config flow for Comelit."""
73 self, user_input: dict[str, Any] |
None =
None
74 ) -> ConfigFlowResult:
75 """Handle the initial step."""
76 if user_input
is None:
88 errors[
"base"] =
"cannot_connect"
90 errors[
"base"] =
"invalid_auth"
92 _LOGGER.exception(
"Unexpected exception")
93 errors[
"base"] =
"unknown"
102 self, entry_data: Mapping[str, Any]
103 ) -> ConfigFlowResult:
104 """Handle reauth flow."""
105 self.context[
"title_placeholders"] = {
"host": entry_data[CONF_HOST]}
109 self, user_input: dict[str, Any] |
None =
None
110 ) -> ConfigFlowResult:
111 """Handle reauth confirm."""
115 entry_data = reauth_entry.data
117 if user_input
is not None:
122 CONF_HOST: entry_data[CONF_HOST],
123 CONF_PORT: entry_data.get(CONF_PORT, DEFAULT_PORT),
124 CONF_TYPE: entry_data.get(CONF_TYPE, BRIDGE),
128 except CannotConnect:
129 errors[
"base"] =
"cannot_connect"
131 errors[
"base"] =
"invalid_auth"
133 _LOGGER.exception(
"Unexpected exception")
134 errors[
"base"] =
"unknown"
139 CONF_HOST: entry_data[CONF_HOST],
140 CONF_PORT: entry_data.get(CONF_PORT, DEFAULT_PORT),
141 CONF_PIN: user_input[CONF_PIN],
142 CONF_TYPE: entry_data.get(CONF_TYPE, BRIDGE),
147 step_id=
"reauth_confirm",
148 description_placeholders={CONF_HOST: entry_data[CONF_HOST]},
149 data_schema=STEP_REAUTH_DATA_SCHEMA,
155 """Error to indicate we cannot connect."""
159 """Error to indicate there is invalid auth."""
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)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigEntry _get_reauth_entry(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_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)
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)
vol.Schema user_form_schema(dict[str, Any]|None user_input)
dict[str, str] validate_input(HomeAssistant hass, dict[str, Any] data)