1 """The yalexs_ble integration models."""
3 from __future__
import annotations
7 from yalexs_ble
import local_name_is_unique
10 BluetoothServiceInfoBleak,
11 async_discovered_service_info,
16 BluetoothCallbackMatcher,
22 local_name: str, address: str
23 ) -> BluetoothCallbackMatcher:
24 """Return a BluetoothCallbackMatcher for the given local_name and address."""
28 if local_name_is_unique(local_name)
and platform.system() ==
"Darwin":
38 hass: HomeAssistant, local_name: str, address: str
39 ) -> BluetoothServiceInfoBleak |
None:
40 """Return the service info for the given local_name and address."""
41 has_unique_local_name = local_name_is_unique(local_name)
43 device = service_info.device
45 has_unique_local_name
and device.name == local_name
46 )
or device.address == address:
52 """Convert a Bluetooth address to a short address."""
53 split_address = address.replace(
"-",
":").split(
":")
54 return f
"{split_address[-2].upper()}{split_address[-1].upper()}"[-4:]
58 """Return a human readable name for the given name, local_name, and address."""
59 return f
"{name or local_name} ({short_address(address)})"
Iterable[BluetoothServiceInfoBleak] async_discovered_service_info(HomeAssistant hass, bool connectable=True)
str short_address(str address)
BluetoothServiceInfoBleak|None async_find_existing_service_info(HomeAssistant hass, str local_name, str address)
str human_readable_name(str|None name, str local_name, str address)
BluetoothCallbackMatcher bluetooth_callback_matcher(str local_name, str address)