1 """Config flow to configure the Twinkly integration."""
3 from __future__
import annotations
8 from aiohttp
import ClientError
9 from ttls.client
import Twinkly
10 from voluptuous
import Required, Schema
17 from .const
import DEV_ID, DEV_MODEL, DEV_NAME, DOMAIN
19 _LOGGER = logging.getLogger(__name__)
23 """Handle twinkly config flow."""
28 """Initialize the config flow."""
32 self, user_input: dict[str, Any] |
None =
None
33 ) -> ConfigFlowResult:
34 """Handle config steps."""
35 host = user_input[CONF_HOST]
if user_input
else None
37 schema = {Required(CONF_HOST, default=host): str}
42 device_info = await Twinkly(
45 except (TimeoutError, ClientError):
46 errors[CONF_HOST] =
"cannot_connect"
54 step_id=
"user", data_schema=
Schema(schema), errors=errors
58 self, discovery_info: dhcp.DhcpServiceInfo
59 ) -> ConfigFlowResult:
60 """Handle dhcp discovery for twinkly."""
62 device_info = await Twinkly(
72 """Confirm discovery."""
76 if user_input
is not None:
81 "model": device_info[DEV_MODEL],
82 "name": device_info[DEV_NAME],
86 step_id=
"discovery_confirm", description_placeholders=placeholders
90 self, device_info: dict[str, Any], host: str
91 ) -> ConfigFlowResult:
92 """Create entry from device data."""
94 title=device_info[DEV_NAME],
97 CONF_ID: device_info[DEV_ID],
98 CONF_NAME: device_info[DEV_NAME],
99 CONF_MODEL: device_info[DEV_MODEL],
ConfigFlowResult async_step_dhcp(self, dhcp.DhcpServiceInfo discovery_info)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult _create_entry_from_device(self, dict[str, Any] device_info, str host)
ConfigFlowResult async_step_discovery_confirm(self, 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")
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)
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)
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)