From cb5af0ecc44a99fbd7c4ee4f6c144a9a506d7ec3 Mon Sep 17 00:00:00 2001 From: David Buezas Date: Mon, 9 Jan 2023 01:15:14 +0100 Subject: [PATCH] Add async_scanner_devices_by_address to Bluetooth (#1589) Co-authored-by: J. Nick Koston --- docs/bluetooth.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/bluetooth.md b/docs/bluetooth.md index d0c07b3a..8971e0c6 100644 --- a/docs/bluetooth.md +++ b/docs/bluetooth.md @@ -166,6 +166,19 @@ from homeassistant.components import bluetooth service_infos = bluetooth.async_discovered_service_info(hass, connectable=True) ``` +### Fetching all discovered devices and advertisement data by each Bluetooth adapter + +To access the list of previous discoveries and advertisement data received by each adapter independently, call the `bluetooth.async_scanner_devices_by_address` API. The call returns a list of `BluetoothScannerDevice` objects. The same device and advertisement data may appear multiple times, once per Bluetooth adapter that reached it. + +```python +from homeassistant.components import bluetooth + +device = bluetooth.async_scanner_devices_by_address(hass, "44:44:33:11:23:42", connectable=True) +# device.ble_device is a bleak `BLEDevice` +# device.advertisement is a bleak `AdvertisementData` +# device.scanner is the scanner that found the device +``` + ### Triggering rediscovery of devices When a configuration entry or device is removed from Home Assistant, trigger rediscovery of its address to make sure they are available to be set up without restarting Home Assistant. You can make use of the Bluetooth connection property of the device registry if your integration manages multiple devices per configuration entry. @@ -215,4 +228,4 @@ The scanner will need to feed advertisement data to the central Bluetooth manage callback = bluetooth.async_get_advertisement_callback(hass) callback(BluetoothServiceInfoBleak(...)) -``` \ No newline at end of file +```