1 """Config flow for sensirion_ble."""
3 from __future__
import annotations
7 from sensirion_ble
import SensirionBluetoothDeviceData
8 import voluptuous
as vol
11 BluetoothServiceInfoBleak,
12 async_discovered_service_info,
17 from .const
import DOMAIN
21 """Handle a config flow for sensirion_ble."""
26 """Initialize the config flow."""
27 self.
_discovery_info_discovery_info: BluetoothServiceInfoBleak |
None =
None
29 self._discovered_devices: dict[str, str] = {}
32 self, discovery_info: BluetoothServiceInfoBleak
33 ) -> ConfigFlowResult:
34 """Handle the bluetooth discovery step."""
37 device = SensirionBluetoothDeviceData()
38 if not device.supported(discovery_info):
45 self, user_input: dict[str, Any] |
None =
None
46 ) -> ConfigFlowResult:
47 """Confirm discovery."""
52 title = device.title
or device.get_device_name()
or discovery_info.name
53 if user_input
is not None:
57 placeholders = {
"name": title}
58 self.context[
"title_placeholders"] = placeholders
60 step_id=
"bluetooth_confirm", description_placeholders=placeholders
64 self, user_input: dict[str, Any] |
None =
None
65 ) -> ConfigFlowResult:
66 """Handle the user step to pick discovered device."""
67 if user_input
is not None:
68 address = user_input[CONF_ADDRESS]
72 title=self._discovered_devices[address], data={}
77 address = discovery_info.address
78 if address
in current_addresses
or address
in self._discovered_devices:
80 device = SensirionBluetoothDeviceData()
81 if device.supported(discovery_info):
82 self._discovered_devices[address] = (
83 device.title
or device.get_device_name()
or discovery_info.name
86 if not self._discovered_devices:
91 data_schema=vol.Schema(
92 {vol.Required(CONF_ADDRESS): vol.In(self._discovered_devices)}
ConfigFlowResult async_step_bluetooth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_bluetooth(self, BluetoothServiceInfoBleak discovery_info)
ConfigFlowResult async_step_user(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")
None _set_confirm_only(self)
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)