1 """Config flow for wiffi component.
3 Used by UI to setup a wiffi integration.
6 from __future__
import annotations
11 import voluptuous
as vol
12 from wiffi
import WiffiTcpServer
23 from .const
import DEFAULT_PORT, DEFAULT_TIMEOUT, DOMAIN
27 """Wiffi server setup config flow."""
34 config_entry: ConfigEntry,
35 ) -> OptionsFlowHandler:
36 """Create Wiffi server setup option flow."""
40 self, user_input: dict[str, Any] |
None =
None
41 ) -> ConfigFlowResult:
42 """Handle the start of the config flow.
44 Called after wiffi integration has been selected in the 'add integration
45 UI'. The user_input is set to None in this case. We will open a config
47 This function is also called if the form has been submitted. user_input
48 contains a dict with the user entered values then.
50 if user_input
is None:
58 server = WiffiTcpServer(user_input[CONF_PORT])
59 await server.start_server()
60 await server.close_server()
62 title=f
"Port {user_input[CONF_PORT]}", data=user_input
64 except OSError
as exc:
65 if exc.errno == errno.EADDRINUSE:
71 """Show the config flow form to the user."""
72 data_schema = {vol.Required(CONF_PORT, default=DEFAULT_PORT): int}
75 step_id=
"user", data_schema=vol.Schema(data_schema), errors=errors
or {}
80 """Wiffi server setup option flow."""
83 self, user_input: dict[str, int] |
None =
None
84 ) -> ConfigFlowResult:
85 """Manage the options."""
86 if user_input
is not None:
91 data_schema=vol.Schema(
96 CONF_TIMEOUT, DEFAULT_TIMEOUT
ConfigFlowResult async_step_init(self, dict[str, int]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
OptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
def _async_show_form(self, errors=None)
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_abort(self, *str reason, Mapping[str, str]|None description_placeholders=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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_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)