1 """Config flow for SMLIGHT Zigbee integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from pysmlight
import Api2
9 from pysmlight.exceptions
import SmlightAuthError, SmlightConnectionError
10 import voluptuous
as vol
18 from .const
import DOMAIN
20 STEP_USER_DATA_SCHEMA = vol.Schema(
22 vol.Required(CONF_HOST): str,
26 STEP_AUTH_DATA_SCHEMA = vol.Schema(
28 vol.Required(CONF_USERNAME): str,
29 vol.Required(CONF_PASSWORD): str,
35 """Handle a config flow for SMLIGHT Zigbee."""
40 """Initialize the config flow."""
44 self, user_input: dict[str, Any] |
None =
None
45 ) -> ConfigFlowResult:
46 """Handle the initial step."""
47 errors: dict[str, str] = {}
49 if user_input
is not None:
50 self.
hosthost = user_input[CONF_HOST]
56 except SmlightConnectionError:
57 errors[
"base"] =
"cannot_connect"
58 except SmlightAuthError:
62 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
66 self, user_input: dict[str, Any] |
None =
None
67 ) -> ConfigFlowResult:
68 """Handle authentication to SLZB-06 device."""
69 errors: dict[str, str] = {}
71 if user_input
is not None:
75 except SmlightConnectionError:
77 except SmlightAuthError:
78 errors[
"base"] =
"invalid_auth"
81 step_id=
"auth", data_schema=STEP_AUTH_DATA_SCHEMA, errors=errors
85 self, discovery_info: zeroconf.ZeroconfServiceInfo
86 ) -> ConfigFlowResult:
87 """Handle a discovered Lan coordinator."""
88 local_name = discovery_info.hostname[:-1]
89 node_name = local_name.removesuffix(
".local")
91 self.
hosthost = local_name
92 self.context[
"title_placeholders"] = {CONF_NAME: node_name}
95 mac = discovery_info.properties.get(
"mac")
100 except SmlightConnectionError:
111 self, user_input: dict[str, Any] |
None =
None
112 ) -> ConfigFlowResult:
113 """Handle discovery confirm."""
114 errors: dict[str, str] = {}
116 if user_input
is not None:
117 user_input[CONF_HOST] = self.
hosthost
122 except SmlightConnectionError:
125 except SmlightAuthError:
131 step_id=
"confirm_discovery",
132 description_placeholders={
"host": self.
hosthost},
137 self, entry_data: Mapping[str, Any]
138 ) -> ConfigFlowResult:
139 """Handle reauth when API Authentication failed."""
141 self.
hosthost = entry_data[CONF_HOST]
147 self, user_input: dict[str, Any] |
None =
None
148 ) -> ConfigFlowResult:
149 """Handle re-authentication of an existing config entry."""
151 if user_input
is not None:
154 user_input[CONF_USERNAME], user_input[CONF_PASSWORD]
156 except SmlightAuthError:
157 errors[
"base"] =
"invalid_auth"
158 except SmlightConnectionError:
166 step_id=
"reauth_confirm",
167 data_schema=STEP_AUTH_DATA_SCHEMA,
168 description_placeholders=self.context[
"title_placeholders"],
173 """Check if auth required and attempt to authenticate."""
174 if await self.
clientclient.check_auth_needed():
175 if user_input.get(CONF_USERNAME)
and user_input.get(CONF_PASSWORD):
177 user_input[CONF_USERNAME], user_input[CONF_PASSWORD]
179 raise SmlightAuthError
183 self, user_input: dict[str, Any]
184 ) -> ConfigFlowResult:
189 if user_input.get(CONF_HOST)
is None:
190 user_input[CONF_HOST] = self.
hosthost
192 assert info.model
is not None
193 title = self.context.
get(
"title_placeholders", {}).
get(CONF_NAME)
or info.model
bool _async_check_auth_required(self, dict[str, Any] user_input)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult _async_complete_entry(self, dict[str, Any] user_input)
ConfigFlowResult async_step_confirm_discovery(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_auth(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)
None _set_confirm_only(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_abort(self, *str reason, Mapping[str, str]|None description_placeholders=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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
web.Response get(self, web.Request request, str config_key)
dict[str, Any]|None get_info(HomeAssistant hass)
dict[str, str|bool] authenticate(HomeAssistant hass, str host, str security_code)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)