ble-bond
Bonded Bluetooth LE sessions for devices that pair in a button window and answer one request at a time.
Some devices accept a new bond only for a few seconds after a button is pressed, drop any link that is not encrypted, and then answer requests with no request id, so a late or stray reply can be taken for the wrong request. Reaching them through a Home Assistant Bluetooth proxy adds its own traps: the bond lives on one proxy, Home Assistant picks the proxy for each attempt, and a refusal through the wrong proxy says nothing about the bond. ble-bond handles that part, built on bleak and bleak-retry-connector, and leaves framing and the device's protocol to the device library.
Used by grundfos-ble (Grundfos ALPHA2 GO pumps) and mira-ble (Mira digital showers).
What it does
- Pairs on every connection: on an ESPHome proxy a quick re-encrypt with the stored bond, real
pairing otherwise. A refusal (ESP-IDF reason 82, BlueZ
AuthenticationFailed) raisesPairingRequired; a proxy that cannot pair at all raisesPairingUnsupported. - Records which adapter or proxy each attempt went through (
last_source), refused attempts included, so a refusal can be pinned on the path that saw it. - On a local Linux adapter, registers a BlueZ pairing agent, one at a time, only while a new
bond is expected;
remove_bluez_bondmakes BlueZ forget a bond the device dropped. - Runs one request at a time. A frame is taken as the reply only when the caller's check accepts it; a request that does not finish (timeout, cancellation, failed write) closes the link, so its late reply cannot answer the next request.
- What differs between devices (pauses, retries, how weak evidence about the bond is reported,
write size, connection parameters) is one
LinkPolicy.
Usage
import asyncio
from bleak import BleakScanner
from ble_bond import BondedLink, LinkPolicy, PairingRequired
REPLY_UUID = "0000ffe1-0000-1000-8000-00805f9b34fb"
class LengthFramed:
"""The device's framing: here, a length byte that counts the whole frame."""
def __init__(self) -> None:
self.buffer = bytearray()
def feed(self, data: bytes | bytearray) -> list[bytes]:
self.buffer += data
frames = []
while self.buffer and len(self.buffer) >= self.buffer[0] > 0:
frames.append(bytes(self.buffer[: self.buffer[0]]))
del self.buffer[: self.buffer[0]]
return frames
def reset(self) -> None:
self.buffer.clear()
async def main() -> None:
device = await BleakScanner.find_device_by_address("AA:BB:CC:DD:EE:FF")
policy = LinkPolicy(settle_after_subscribe=0.5)
try:
async with BondedLink(
device, notify_uuid=REPLY_UUID, assembler=LengthFramed(), policy=policy
) as link:
reply = await link.request(b"\x02\x01", accept=lambda frame: frame[1] == 0x01)
print(reply.hex(" "), "via", link.last_source)
except PairingRequired:
print("Press the device's button, then connect with expect_new_bond=True.")
asyncio.run(main())
Debug logging for ble_bond shows the link's events: connecting, pairing evidence, retries,
frames no request was waiting for. Every frame sent and received goes to ble_bond.frames,
which stays at INFO unless you set it to debug.
ble_bond.testing has a fake bleak client and a patch for the connection call, so a device
library can test its transport without hardware.
Compatibility
Every 1.x release is backward compatible: several device libraries may be installed in one Home
Assistant, which then holds a single copy of this package. Depend on ble-bond>=1.0,<2.
Acknowledgements
The BlueZ pairing agent is adapted from alpha-hwr (MIT); its notice is in THIRD_PARTY_NOTICES.md. The pause after subscribing follows ESPHome's measurement in esphome/esphome#22651.
Licence
MIT
Metadata
Release files for ble-bond 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ble_bond-1.1.0.tar.gz | 25.9 kB | With provenance | Details for ble_bond-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ble_bond-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for ble_bond-1.1.0-py3-none-any.whl |
Total release size: 46.9 kB
Release files / ble_bond-1.1.0.tar.gz
| Download URL | ble_bond-1.1.0.tar.gz |
|---|---|
| Size | 25.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b98714ffa511a541ac1ab351039e4d60501856759d0f8a2acbb211bef5a557f
|
|
BLAKE2b-256 checksum How to use checksums |
6c17a9ef89e3d2f57ab972ac82c979c94aef85eae3ce2880926995d65797dfdd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logRelease files / ble_bond-1.1.0-py3-none-any.whl
| Download URL | ble_bond-1.1.0-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6eba6e004e0353ac1742a18fddbb9a86f2bef6ac274f57fa15db7c518eb9c835
|
|
BLAKE2b-256 checksum How to use checksums |
4f2cf8ee567d69ca58c19ee0a4a894c6f9ca7a8fa08481721e135a1fd2092605
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logSecurity for ble-bond 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for ble_bond-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.