1 """Config flow for melnor."""
3 from __future__
import annotations
7 import voluptuous
as vol
14 from .const
import DOMAIN, MANUFACTURER_DATA_START, MANUFACTURER_ID
18 """Handle a config flow for melnor."""
23 """Initialize the config flow."""
25 self._discovered_addresses: list[str] = []
28 """Create an entry for a discovered device."""
33 CONF_ADDRESS: address,
38 self, user_input: dict[str, Any] |
None =
None
39 ) -> ConfigFlowResult:
40 """Handle user-confirmation of discovered device."""
42 if user_input
is not None:
46 step_id=
"bluetooth_confirm",
51 self, discovery_info: BluetoothServiceInfoBleak
52 ) -> ConfigFlowResult:
53 """Handle a flow initialized by Bluetooth discovery."""
55 address = discovery_info.address
62 self.context[
"title_placeholders"] = {
"name": address}
66 self, user_input: dict[str, Any] |
None =
None
67 ) -> ConfigFlowResult:
68 """Handle the step to pick discovered device."""
70 if user_input
is not None:
71 address = user_input[CONF_ADDRESS]
80 self.hass, connectable=
True
82 if discovery_info.manufacturer_id == MANUFACTURER_ID
and any(
83 manufacturer_data.startswith(MANUFACTURER_DATA_START)
84 for manufacturer_data
in discovery_info.manufacturer_data.values()
86 address = discovery_info.address
88 address
not in current_addresses
89 and address
not in self._discovered_addresses
91 self._discovered_addresses.append(address)
95 for address
in self._discovered_addresses
96 if address
not in current_addresses
104 step_id=
"pick_device",
105 data_schema=vol.Schema({vol.Required(CONF_ADDRESS): vol.In(addresses)}),
109 self, user_input: dict[str, Any] |
None =
None
110 ) -> ConfigFlowResult:
111 """Handle a flow initialized by the user."""
ConfigFlowResult async_step_bluetooth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult _create_entry(self, str address)
ConfigFlowResult async_step_bluetooth(self, BluetoothServiceInfoBleak discovery_info)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_pick_device(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")
set[str|None] _async_current_ids(self, bool include_ignore=True)
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)
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)
Iterable[BluetoothServiceInfoBleak] async_discovered_service_info(HomeAssistant hass, bool connectable=True)