1 """Config flow to configure the Tailwind integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from gotailwind
import (
9 MIN_REQUIRED_FIRMWARE_VERSION,
11 TailwindAuthenticationError,
12 TailwindConnectionError,
13 TailwindUnsupportedFirmwareVersionError,
14 tailwind_device_id_to_mac_address,
16 import voluptuous
as vol
31 from .const
import DOMAIN, LOGGER
33 LOCAL_CONTROL_KEY_URL = (
34 "https://web.gotailwind.com/client/integration/local-control-key"
39 """Handle a Tailwind config flow."""
46 self, user_input: dict[str, Any] |
None =
None
47 ) -> ConfigFlowResult:
48 """Handle a flow initiated by the user."""
51 if user_input
is not None:
54 host=user_input[CONF_HOST],
55 token=user_input[CONF_TOKEN],
59 except TailwindAuthenticationError:
60 errors[CONF_TOKEN] =
"invalid_auth"
61 except TailwindConnectionError:
62 errors[CONF_HOST] =
"cannot_connect"
64 LOGGER.exception(
"Unexpected exception")
65 errors[
"base"] =
"unknown"
71 data_schema=vol.Schema(
74 CONF_HOST, default=user_input.get(CONF_HOST)
81 description_placeholders={
"url": LOCAL_CONTROL_KEY_URL},
86 self, discovery_info: zeroconf.ZeroconfServiceInfo
87 ) -> ConfigFlowResult:
88 """Handle zeroconf discovery of a Tailwind device."""
89 if not (device_id := discovery_info.properties.get(
"device_id")):
93 version := discovery_info.properties.get(
"SW ver")
94 )
and version < MIN_REQUIRED_FIRMWARE_VERSION:
98 format_mac(tailwind_device_id_to_mac_address(device_id))
102 self.
hosthost = discovery_info.host
105 "title_placeholders": {
106 "name": f
"Tailwind {discovery_info.properties.get('product')}"
108 "configuration_url": LOCAL_CONTROL_KEY_URL,
114 self, user_input: dict[str, Any] |
None =
None
115 ) -> ConfigFlowResult:
116 """Handle a flow initiated by zeroconf."""
119 if user_input
is not None:
123 token=user_input[CONF_TOKEN],
125 except TailwindAuthenticationError:
126 errors[CONF_TOKEN] =
"invalid_auth"
127 except TailwindConnectionError:
128 errors[
"base"] =
"cannot_connect"
130 LOGGER.exception(
"Unexpected exception")
131 errors[
"base"] =
"unknown"
134 step_id=
"zeroconf_confirm",
135 data_schema=vol.Schema(
142 description_placeholders={
"url": LOCAL_CONTROL_KEY_URL},
147 self, entry_data: Mapping[str, Any]
148 ) -> ConfigFlowResult:
149 """Handle initiation of re-authentication with a Tailwind device."""
153 self, user_input: dict[str, Any] |
None =
None
154 ) -> ConfigFlowResult:
155 """Handle re-authentication with a Tailwind device."""
158 if user_input
is not None:
162 token=user_input[CONF_TOKEN],
164 except TailwindAuthenticationError:
165 errors[CONF_TOKEN] =
"invalid_auth"
166 except TailwindConnectionError:
167 errors[
"base"] =
"cannot_connect"
169 LOGGER.exception(
"Unexpected exception")
170 errors[
"base"] =
"unknown"
173 step_id=
"reauth_confirm",
174 data_schema=vol.Schema(
181 description_placeholders={
"url": LOCAL_CONTROL_KEY_URL},
186 self, discovery_info: DhcpServiceInfo
187 ) -> ConfigFlowResult:
188 """Handle dhcp discovery to update existing entries.
190 This flow is triggered only by DHCP discovery of known devices.
201 self, *, host: str, token: str
202 ) -> ConfigFlowResult:
209 status = await tailwind.status()
210 except TailwindUnsupportedFirmwareVersionError:
223 format_mac(status.mac_address), raise_on_progress=
False
233 title=f
"Tailwind {status.product}",
234 data={CONF_HOST: host, CONF_TOKEN: token},
ConfigFlowResult _async_step_create_entry(self, *str host, str token)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
ConfigFlowResult async_step_zeroconf_confirm(self, dict[str, Any]|None user_input=None)
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)
ConfigFlowResult async_step_dhcp(self, DhcpServiceInfo 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 _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_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)
IssData update(pyiss.ISS iss)
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)