1 """Config flow for the BLE Tracker."""
3 from __future__
import annotations
9 import voluptuous
as vol
14 from .const
import DOMAIN
15 from .coordinator
import async_last_service_info
17 _LOGGER = logging.getLogger(__name__)
23 if irk.startswith(
"irk:"):
28 irk_bytes = bytes(reversed(base64.b64decode(irk)))
29 except binascii.Error:
34 irk_bytes = binascii.unhexlify(irk)
35 except binascii.Error:
39 if len(irk_bytes) != 16:
47 """Handle a config flow for BLE Device Tracker."""
52 self, user_input: dict[str, str] |
None =
None
53 ) -> ConfigFlowResult:
55 errors: dict[str, str] = {}
57 if not bluetooth.async_scanner_count(self.hass, connectable=
False):
60 if user_input
is not None:
61 irk = user_input[CONF_IRK]
64 errors[CONF_IRK] =
"irk_not_valid"
66 errors[CONF_IRK] =
"irk_not_found"
70 title=service_info.name
or "BLE Device Tracker",
71 data={CONF_IRK: irk_bytes.hex()},
74 data_schema = vol.Schema({CONF_IRK: str})
76 step_id=
"user", data_schema=data_schema, errors=errors
ConfigFlowResult async_step_user(self, dict[str, str]|None user_input=None)
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)
BluetoothServiceInfoBleak|None async_last_service_info(HomeAssistant hass, str address, bool connectable=True)
bytes|None _parse_irk(str irk)