1 """Config flow for the Velbus platform."""
3 from __future__
import annotations
7 import velbusaio.controller
8 from velbusaio.exceptions
import VelbusConnectionFailed
9 import voluptuous
as vol
16 from .const
import DOMAIN
20 """Handle a config flow."""
25 """Initialize the velbus config flow."""
26 self.
_errors_errors: dict[str, str] = {}
28 self.
_title_title: str =
""
31 """Create an entry async."""
35 """Try to connect to the velbus with the port specified."""
37 controller = velbusaio.controller.Velbus(prt)
38 await controller.connect(
True)
39 await controller.stop()
40 except VelbusConnectionFailed:
41 self.
_errors_errors[CONF_PORT] =
"cannot_connect"
46 self, user_input: dict[str, Any] |
None =
None
47 ) -> ConfigFlowResult:
48 """Step when user initializes a integration."""
50 if user_input
is not None:
51 name =
slugify(user_input[CONF_NAME])
52 prt = user_input[CONF_PORT]
58 user_input[CONF_NAME] =
""
59 user_input[CONF_PORT] =
""
63 data_schema=vol.Schema(
65 vol.Required(CONF_NAME, default=user_input[CONF_NAME]): str,
66 vol.Required(CONF_PORT, default=user_input[CONF_PORT]): str,
73 self, discovery_info: usb.UsbServiceInfo
74 ) -> ConfigFlowResult:
75 """Handle USB Discovery."""
77 f
"{discovery_info.vid}:{discovery_info.pid}_{discovery_info.serial_number}_{discovery_info.manufacturer}_{discovery_info.description}"
79 dev_path = discovery_info.device
93 self, user_input: dict[str, Any] |
None =
None
94 ) -> ConfigFlowResult:
95 """Handle Discovery confirmation."""
96 if user_input
is not None:
100 step_id=
"discovery_confirm",
101 description_placeholders={CONF_NAME: self.
_title_title},
ConfigFlowResult async_step_discovery_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult _create_device(self, str name, str prt)
bool _test_connection(self, str prt)
ConfigFlowResult async_step_usb(self, usb.UsbServiceInfo discovery_info)
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_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)
_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)