1 """Config flow for Gogogate2."""
3 from __future__
import annotations
7 from typing
import Any, Self
9 from ismartgate.common
import AbstractInfoResponse, ApiError
10 from ismartgate.const
import GogoGate2ApiErrorCode, ISmartGateApiErrorCode
11 import voluptuous
as vol
23 from .common
import get_api
24 from .const
import DEVICE_TYPE_GOGOGATE2, DEVICE_TYPE_ISMARTGATE, DOMAIN
27 DEVICE_TYPE_GOGOGATE2:
"Gogogate2",
28 DEVICE_TYPE_ISMARTGATE:
"ismartgate",
33 """Gogogate2 config flow."""
38 """Initialize the config flow."""
43 self, discovery_info: zeroconf.ZeroconfServiceInfo
44 ) -> ConfigFlowResult:
45 """Handle homekit discovery."""
47 discovery_info.properties[zeroconf.ATTR_PROPERTIES_ID]
52 self, discovery_info: dhcp.DhcpServiceInfo
53 ) -> ConfigFlowResult:
54 """Handle dhcp discovery."""
59 """Start the user flow from any discovery."""
65 if self.hass.config_entries.flow.async_has_matching_flow(self):
72 """Return True if other_flow is matching this flow."""
73 return other_flow._ip_address == self.
_ip_address_ip_address
76 self, user_input: dict[str, Any] |
None =
None
77 ) -> ConfigFlowResult:
78 """Handle user initiated flow."""
79 user_input = user_input
or {}
83 api =
get_api(self.hass, user_input)
85 data: AbstractInfoResponse = await api.async_info()
86 data_dict = dataclasses.asdict(data)
87 title = data_dict.get(
88 "gogogatename", data_dict.get(
"ismartgatename",
"Cover")
93 except ApiError
as api_error:
94 device_type = user_input[CONF_DEVICE]
96 device_type == DEVICE_TYPE_GOGOGATE2
99 GogoGate2ApiErrorCode.CREDENTIALS_NOT_SET,
100 GogoGate2ApiErrorCode.CREDENTIALS_INCORRECT,
103 device_type == DEVICE_TYPE_ISMARTGATE
106 ISmartGateApiErrorCode.CREDENTIALS_NOT_SET,
107 ISmartGateApiErrorCode.CREDENTIALS_INCORRECT,
112 errors[
"base"] =
"invalid_auth"
114 errors[
"base"] =
"cannot_connect"
117 errors[
"base"] =
"cannot_connect"
120 self.context[
"title_placeholders"] = {
121 CONF_DEVICE: DEVICE_NAMES[self.
_device_type_device_type],
126 data_schema=vol.Schema(
131 or user_input.get(CONF_DEVICE, DEVICE_TYPE_GOGOGATE2),
132 ): vol.In((DEVICE_TYPE_GOGOGATE2, DEVICE_TYPE_ISMARTGATE)),
135 default=user_input.get(CONF_IP_ADDRESS, self.
_ip_address_ip_address),
138 CONF_USERNAME, default=user_input.get(CONF_USERNAME,
"")
141 CONF_PASSWORD, default=user_input.get(CONF_PASSWORD,
"")
ConfigFlowResult _async_discovery_handler(self, str ip_address)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_dhcp(self, dhcp.DhcpServiceInfo discovery_info)
bool is_matching(self, Self other_flow)
ConfigFlowResult async_step_homekit(self, zeroconf.ZeroconfServiceInfo discovery_info)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
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_step_user(self, dict[str, Any]|None user_input=None)
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)
Freepybox get_api(HomeAssistant hass, str host)