Document async_track_unavailable in bluetooth (#1408)

This commit is contained in:
J. Nick Koston 2022-07-22 14:56:45 -05:00 committed by GitHub
parent ae24119e77
commit e998f5b7c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,6 +77,20 @@ entry.async_on_unload(
) )
``` ```
### Subscribing to unavailable callbacks
To get a callback when the Bluetooth stack can no longer see a device, call the `bluetooth.async_track_unavailable` API. For performance reasons, it may take up to five minutes to get a callback once the device is no longer seen.
```python
from homeassistant.components import bluetooth
def _unavailable_callback(address: str) -> None:
_LOGGER.debug("%s is no longer seen", address)
cancel = bluetooth.async_track_unavailable(hass, _unavailable_callback, "44:44:33:11:23:42")
```
### Fetching the bleak `BLEDevice` from the `address` ### Fetching the bleak `BLEDevice` from the `address`
Integrations wishing to avoid the overhead of starting an additional scanner to resolve the address may call the `bluetooth.async_ble_device_from_address` API, which returns a `BLEDevice` if the `bluetooth` integration scanner has recently seen the device. Integration MUST fall back to connecting via the `address` if the `BLEDevice` is unavailable. Integrations wishing to avoid the overhead of starting an additional scanner to resolve the address may call the `bluetooth.async_ble_device_from_address` API, which returns a `BLEDevice` if the `bluetooth` integration scanner has recently seen the device. Integration MUST fall back to connecting via the `address` if the `BLEDevice` is unavailable.