1 """Config flow for Aranet integration."""
3 from __future__
import annotations
7 from aranet4.client
import Aranet4Advertisement, Version
as AranetVersion
8 from bluetooth_data_tools
import human_readable_name
9 import voluptuous
as vol
12 BluetoothServiceInfoBleak,
13 async_discovered_service_info,
19 from .const
import DOMAIN
21 MIN_VERSION = AranetVersion(1, 2, 0)
24 def _title(discovery_info: BluetoothServiceInfoBleak) -> str:
26 None,
"Aranet", discovery_info.address
31 """Handle a config flow for Aranet."""
36 """Set up a new config flow for Aranet."""
37 self.
_discovery_info_discovery_info: BluetoothServiceInfoBleak |
None =
None
39 self._discovered_devices: dict[str, tuple[str, Aranet4Advertisement]] = {}
42 """Raise any configuration errors that apply to an advertisement."""
44 if not adv.manufacturer_data
or adv.manufacturer_data.version < MIN_VERSION:
48 if not adv.manufacturer_data.integrations:
52 self, discovery_info: BluetoothServiceInfoBleak
53 ) -> ConfigFlowResult:
54 """Handle the Bluetooth discovery step."""
57 adv = Aranet4Advertisement(discovery_info.device, discovery_info.advertisement)
65 self, user_input: dict[str, Any] |
None =
None
66 ) -> ConfigFlowResult:
67 """Confirm discovery."""
70 if user_input
is not None:
74 placeholders = {
"name": title}
75 self.context[
"title_placeholders"] = placeholders
77 step_id=
"bluetooth_confirm", description_placeholders=placeholders
81 self, user_input: dict[str, Any] |
None =
None
82 ) -> ConfigFlowResult:
83 """Handle the user step to pick discovered device."""
84 if user_input
is not None:
85 address = user_input[CONF_ADDRESS]
86 adv = self._discovered_devices[address][1]
92 title=self._discovered_devices[address][0], data={}
97 address = discovery_info.address
98 if address
in current_addresses
or address
in self._discovered_devices:
101 adv = Aranet4Advertisement(
102 discovery_info.device, discovery_info.advertisement
104 if adv.manufacturer_data:
105 self._discovered_devices[address] = (
_title(discovery_info), adv)
107 if not self._discovered_devices:
112 data_schema=vol.Schema(
114 vol.Required(CONF_ADDRESS): vol.In(
117 for (addr, dev)
in self._discovered_devices.items()
None _raise_for_advertisement_errors(self, Aranet4Advertisement adv)
ConfigFlowResult async_step_bluetooth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_bluetooth(self, BluetoothServiceInfoBleak discovery_info)
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)
str _title(BluetoothServiceInfoBleak discovery_info)
Iterable[BluetoothServiceInfoBleak] async_discovered_service_info(HomeAssistant hass, bool connectable=True)
str human_readable_name(str hostname, str vendor, str mac_address)