From bbe5013896e8c4c7bba249bdadd2ed62b207ed25 Mon Sep 17 00:00:00 2001 From: David Buezas Date: Fri, 16 Dec 2022 18:01:13 +0100 Subject: [PATCH 1/4] Add async_get_discovered_devices_and_advertisement_data_by_address to bluetooth.md Goes together with https://github.com/home-assistant/core/pull/83733 --- docs/bluetooth.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/bluetooth.md b/docs/bluetooth.md index d0c07b3a321..5b870b39140 100644 --- a/docs/bluetooth.md +++ b/docs/bluetooth.md @@ -166,6 +166,16 @@ from homeassistant.components import bluetooth service_infos = bluetooth.async_discovered_service_info(hass, connectable=True) ``` +### Fetching all discovered devices and advertisment data by each bluetooth adapter + +To access the list of previous discoveries and advertisment data received by each adapter independently, call the `bluetooth.async_get_discovered_devices_and_advertisement_data_by_address` API. The same device and advertisment data may appear multiple times, once per bluetooth adapter that reached it. + +```python +from homeassistant.components import bluetooth + +discovered_devices_and_advertisement_data = bluetooth.async_get_discovered_devices_and_advertisement_data_by_address(hass, "44:44:33:11:23:42", connectable=True) +``` + ### 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 +225,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 +``` From 5c23555ba4c58c51ba504836665ff804952619b2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Jan 2023 13:32:16 -1000 Subject: [PATCH 2/4] Update docs/bluetooth.md --- docs/bluetooth.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/bluetooth.md b/docs/bluetooth.md index 5b870b39140..0cd4d8fae01 100644 --- a/docs/bluetooth.md +++ b/docs/bluetooth.md @@ -168,7 +168,7 @@ service_infos = bluetooth.async_discovered_service_info(hass, connectable=True) ### Fetching all discovered devices and advertisment data by each bluetooth adapter -To access the list of previous discoveries and advertisment data received by each adapter independently, call the `bluetooth.async_get_discovered_devices_and_advertisement_data_by_address` API. The same device and advertisment data may appear multiple times, once per bluetooth adapter that reached it. +To access the list of previous discoveries and advertisment 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 advertisment data may appear multiple times, once per bluetooth adapter that reached it. ```python from homeassistant.components import bluetooth From b61641047555a1b9fcaa18dea54fb90df635710a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Jan 2023 13:32:20 -1000 Subject: [PATCH 3/4] Update docs/bluetooth.md --- docs/bluetooth.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/bluetooth.md b/docs/bluetooth.md index 0cd4d8fae01..dc344e243e0 100644 --- a/docs/bluetooth.md +++ b/docs/bluetooth.md @@ -173,7 +173,10 @@ To access the list of previous discoveries and advertisment data received by eac ```python from homeassistant.components import bluetooth -discovered_devices_and_advertisement_data = bluetooth.async_get_discovered_devices_and_advertisement_data_by_address(hass, "44:44:33:11:23:42", connectable=True) +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 From 09dce7ececa305262cf07311906b95b94eea6e81 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Jan 2023 14:08:44 -1000 Subject: [PATCH 4/4] Apply suggestions from code review --- docs/bluetooth.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/bluetooth.md b/docs/bluetooth.md index dc344e243e0..8971e0c691b 100644 --- a/docs/bluetooth.md +++ b/docs/bluetooth.md @@ -166,9 +166,9 @@ from homeassistant.components import bluetooth service_infos = bluetooth.async_discovered_service_info(hass, connectable=True) ``` -### Fetching all discovered devices and advertisment data by each bluetooth adapter +### Fetching all discovered devices and advertisement data by each Bluetooth adapter -To access the list of previous discoveries and advertisment 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 advertisment data may appear multiple times, once per bluetooth adapter that reached it. +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