ble-bond 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ble_bond-1.0.0/.gitignore +31 -0
- ble_bond-1.0.0/CHANGELOG.md +24 -0
- ble_bond-1.0.0/LICENSE +21 -0
- ble_bond-1.0.0/PKG-INFO +128 -0
- ble_bond-1.0.0/README.md +99 -0
- ble_bond-1.0.0/THIRD_PARTY_NOTICES.md +35 -0
- ble_bond-1.0.0/pyproject.toml +122 -0
- ble_bond-1.0.0/src/ble_bond/__init__.py +39 -0
- ble_bond-1.0.0/src/ble_bond/bluez.py +220 -0
- ble_bond-1.0.0/src/ble_bond/exceptions.py +59 -0
- ble_bond-1.0.0/src/ble_bond/link.py +624 -0
- ble_bond-1.0.0/src/ble_bond/py.typed +0 -0
- ble_bond-1.0.0/src/ble_bond/testing.py +91 -0
- ble_bond-1.0.0/tests/__init__.py +0 -0
- ble_bond-1.0.0/tests/test_bluez.py +237 -0
- ble_bond-1.0.0/tests/test_link.py +691 -0
- ble_bond-1.0.0/tests/test_readme.py +30 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
.venv/
|
|
8
|
+
.mypy_cache/
|
|
9
|
+
.pytest_cache/
|
|
10
|
+
.ruff_cache/
|
|
11
|
+
.coverage
|
|
12
|
+
coverage.xml
|
|
13
|
+
htmlcov/
|
|
14
|
+
|
|
15
|
+
# Nix
|
|
16
|
+
result
|
|
17
|
+
.direnv/
|
|
18
|
+
|
|
19
|
+
# Editors
|
|
20
|
+
.idea/
|
|
21
|
+
.vscode/
|
|
22
|
+
*.swp
|
|
23
|
+
|
|
24
|
+
# Local environments and secrets
|
|
25
|
+
.venv-*/
|
|
26
|
+
.env
|
|
27
|
+
.env.*
|
|
28
|
+
.envrc
|
|
29
|
+
|
|
30
|
+
# macOS
|
|
31
|
+
.DS_Store
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/): every 1.x release is backward compatible.
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [1.0.0]
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `BondedLink`: a bonded BLE link that pairs on every connection, records the adapter or proxy
|
|
14
|
+
each attempt used, runs one request at a time with a caller-supplied reply check, and closes
|
|
15
|
+
the link on any request that does not finish. Taken from grundfos-ble 0.2.0 and mira-ble,
|
|
16
|
+
where it ran on real devices.
|
|
17
|
+
- `LinkPolicy` and `SubscribeRetry` for what differs between devices.
|
|
18
|
+
- `PairingRequired` (with `refused`), `PairingUnsupported`, `ConnectionLost`,
|
|
19
|
+
`RequestTimeout`, all `LinkError`s.
|
|
20
|
+
- The BlueZ pairing agent (`bluez_pairing_agent`), `remove_bluez_bond` and `bluez_device_path`.
|
|
21
|
+
- `ble_bond.testing`: `FakeClient` and `patched_establish`.
|
|
22
|
+
|
|
23
|
+
[Unreleased]: https://github.com/83noit/ble-bond/compare/v1.0.0...HEAD
|
|
24
|
+
[1.0.0]: https://github.com/83noit/ble-bond/releases/tag/v1.0.0
|
ble_bond-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 83noit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ble_bond-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ble-bond
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Bonded Bluetooth LE sessions for devices that pair in a button window and answer one request at a time
|
|
5
|
+
Project-URL: Homepage, https://github.com/83noit/ble-bond
|
|
6
|
+
Project-URL: Repository, https://github.com/83noit/ble-bond
|
|
7
|
+
Project-URL: Issues, https://github.com/83noit/ble-bond/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/83noit/ble-bond/blob/main/CHANGELOG.md
|
|
9
|
+
Author: 83noit
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: THIRD_PARTY_NOTICES.md
|
|
13
|
+
Keywords: ble,bleak,bluetooth,bonding,esphome,home-assistant,pairing
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Framework :: AsyncIO
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
22
|
+
Classifier: Topic :: Home Automation
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.13
|
|
25
|
+
Requires-Dist: bleak-retry-connector>=4.7.1
|
|
26
|
+
Requires-Dist: bleak>=3.0.2
|
|
27
|
+
Requires-Dist: dbus-fast>=4.0; sys_platform == 'linux'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# ble-bond
|
|
31
|
+
|
|
32
|
+
[](https://github.com/83noit/ble-bond/actions/workflows/ci.yml)
|
|
33
|
+
[](https://pypi.org/project/ble-bond/)
|
|
34
|
+
[](https://github.com/83noit/ble-bond/blob/main/LICENSE)
|
|
35
|
+
|
|
36
|
+
Bonded Bluetooth LE sessions for devices that pair in a button window and answer one request at
|
|
37
|
+
a time.
|
|
38
|
+
|
|
39
|
+
Some devices accept a new bond only for a few seconds after a button is pressed, drop any link
|
|
40
|
+
that is not encrypted, and then answer requests with no request id, so a late or stray reply can
|
|
41
|
+
be taken for the wrong request. Reaching them through a Home Assistant Bluetooth proxy adds its
|
|
42
|
+
own traps: the bond lives on one proxy, Home Assistant picks the proxy for each attempt, and a
|
|
43
|
+
refusal through the wrong proxy says nothing about the bond. ble-bond handles that part, built
|
|
44
|
+
on [bleak](https://github.com/hbldh/bleak) and
|
|
45
|
+
[bleak-retry-connector](https://github.com/Bluetooth-Devices/bleak-retry-connector), and leaves
|
|
46
|
+
framing and the device's protocol to the device library.
|
|
47
|
+
|
|
48
|
+
Used by [grundfos-ble](https://github.com/83noit/grundfos-ble) (Grundfos ALPHA2 GO pumps) and
|
|
49
|
+
[mira-ble](https://github.com/83noit/mira-ble) (Mira digital showers).
|
|
50
|
+
|
|
51
|
+
## What it does
|
|
52
|
+
|
|
53
|
+
- Pairs on every connection: on an ESPHome proxy a quick re-encrypt with the stored bond, real
|
|
54
|
+
pairing otherwise. A refusal (ESP-IDF reason 82, BlueZ `AuthenticationFailed`) raises
|
|
55
|
+
`PairingRequired`; a proxy that cannot pair at all raises `PairingUnsupported`.
|
|
56
|
+
- Records which adapter or proxy each attempt went through (`last_source`), refused attempts
|
|
57
|
+
included, so a refusal can be pinned on the path that saw it.
|
|
58
|
+
- On a local Linux adapter, registers a BlueZ pairing agent, one at a time, only while a new
|
|
59
|
+
bond is expected; `remove_bluez_bond` makes BlueZ forget a bond the device dropped.
|
|
60
|
+
- Runs one request at a time. A frame is taken as the reply only when the caller's check
|
|
61
|
+
accepts it; a request that does not finish (timeout, cancellation, failed write) closes the
|
|
62
|
+
link, so its late reply cannot answer the next request.
|
|
63
|
+
- What differs between devices (pauses, retries, how weak evidence about the bond is reported,
|
|
64
|
+
write size, connection parameters) is one `LinkPolicy`.
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import asyncio
|
|
70
|
+
|
|
71
|
+
from bleak import BleakScanner
|
|
72
|
+
from ble_bond import BondedLink, LinkPolicy, PairingRequired
|
|
73
|
+
|
|
74
|
+
REPLY_UUID = "0000ffe1-0000-1000-8000-00805f9b34fb"
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class LengthFramed:
|
|
78
|
+
"""The device's framing: here, a length byte that counts the whole frame."""
|
|
79
|
+
|
|
80
|
+
def __init__(self) -> None:
|
|
81
|
+
self.buffer = bytearray()
|
|
82
|
+
|
|
83
|
+
def feed(self, data: bytes | bytearray) -> list[bytes]:
|
|
84
|
+
self.buffer += data
|
|
85
|
+
frames = []
|
|
86
|
+
while self.buffer and len(self.buffer) >= self.buffer[0] > 0:
|
|
87
|
+
frames.append(bytes(self.buffer[: self.buffer[0]]))
|
|
88
|
+
del self.buffer[: self.buffer[0]]
|
|
89
|
+
return frames
|
|
90
|
+
|
|
91
|
+
def reset(self) -> None:
|
|
92
|
+
self.buffer.clear()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
async def main() -> None:
|
|
96
|
+
device = await BleakScanner.find_device_by_address("AA:BB:CC:DD:EE:FF")
|
|
97
|
+
policy = LinkPolicy(settle_after_subscribe=0.5)
|
|
98
|
+
try:
|
|
99
|
+
async with BondedLink(
|
|
100
|
+
device, notify_uuid=REPLY_UUID, assembler=LengthFramed(), policy=policy
|
|
101
|
+
) as link:
|
|
102
|
+
reply = await link.request(b"\x02\x01", accept=lambda frame: frame[1] == 0x01)
|
|
103
|
+
print(reply.hex(" "), "via", link.last_source)
|
|
104
|
+
except PairingRequired:
|
|
105
|
+
print("Press the device's button, then connect with expect_new_bond=True.")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
asyncio.run(main())
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`ble_bond.testing` has a fake bleak client and a patch for the connection call, so a device
|
|
112
|
+
library can test its transport without hardware.
|
|
113
|
+
|
|
114
|
+
## Compatibility
|
|
115
|
+
|
|
116
|
+
Every 1.x release is backward compatible: several device libraries may be installed in one Home
|
|
117
|
+
Assistant, which then holds a single copy of this package. Depend on `ble-bond>=1.0,<2`.
|
|
118
|
+
|
|
119
|
+
## Acknowledgements
|
|
120
|
+
|
|
121
|
+
The BlueZ pairing agent is adapted from [alpha-hwr](https://github.com/eman/alpha-hwr) (MIT);
|
|
122
|
+
its notice is in [THIRD_PARTY_NOTICES.md](https://github.com/83noit/ble-bond/blob/main/THIRD_PARTY_NOTICES.md).
|
|
123
|
+
The pause after subscribing follows ESPHome's measurement in
|
|
124
|
+
[esphome/esphome#22651](https://github.com/esphome/esphome/pull/22651).
|
|
125
|
+
|
|
126
|
+
## Licence
|
|
127
|
+
|
|
128
|
+
MIT
|
ble_bond-1.0.0/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# ble-bond
|
|
2
|
+
|
|
3
|
+
[](https://github.com/83noit/ble-bond/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/ble-bond/)
|
|
5
|
+
[](https://github.com/83noit/ble-bond/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
Bonded Bluetooth LE sessions for devices that pair in a button window and answer one request at
|
|
8
|
+
a time.
|
|
9
|
+
|
|
10
|
+
Some devices accept a new bond only for a few seconds after a button is pressed, drop any link
|
|
11
|
+
that is not encrypted, and then answer requests with no request id, so a late or stray reply can
|
|
12
|
+
be taken for the wrong request. Reaching them through a Home Assistant Bluetooth proxy adds its
|
|
13
|
+
own traps: the bond lives on one proxy, Home Assistant picks the proxy for each attempt, and a
|
|
14
|
+
refusal through the wrong proxy says nothing about the bond. ble-bond handles that part, built
|
|
15
|
+
on [bleak](https://github.com/hbldh/bleak) and
|
|
16
|
+
[bleak-retry-connector](https://github.com/Bluetooth-Devices/bleak-retry-connector), and leaves
|
|
17
|
+
framing and the device's protocol to the device library.
|
|
18
|
+
|
|
19
|
+
Used by [grundfos-ble](https://github.com/83noit/grundfos-ble) (Grundfos ALPHA2 GO pumps) and
|
|
20
|
+
[mira-ble](https://github.com/83noit/mira-ble) (Mira digital showers).
|
|
21
|
+
|
|
22
|
+
## What it does
|
|
23
|
+
|
|
24
|
+
- Pairs on every connection: on an ESPHome proxy a quick re-encrypt with the stored bond, real
|
|
25
|
+
pairing otherwise. A refusal (ESP-IDF reason 82, BlueZ `AuthenticationFailed`) raises
|
|
26
|
+
`PairingRequired`; a proxy that cannot pair at all raises `PairingUnsupported`.
|
|
27
|
+
- Records which adapter or proxy each attempt went through (`last_source`), refused attempts
|
|
28
|
+
included, so a refusal can be pinned on the path that saw it.
|
|
29
|
+
- On a local Linux adapter, registers a BlueZ pairing agent, one at a time, only while a new
|
|
30
|
+
bond is expected; `remove_bluez_bond` makes BlueZ forget a bond the device dropped.
|
|
31
|
+
- Runs one request at a time. A frame is taken as the reply only when the caller's check
|
|
32
|
+
accepts it; a request that does not finish (timeout, cancellation, failed write) closes the
|
|
33
|
+
link, so its late reply cannot answer the next request.
|
|
34
|
+
- What differs between devices (pauses, retries, how weak evidence about the bond is reported,
|
|
35
|
+
write size, connection parameters) is one `LinkPolicy`.
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import asyncio
|
|
41
|
+
|
|
42
|
+
from bleak import BleakScanner
|
|
43
|
+
from ble_bond import BondedLink, LinkPolicy, PairingRequired
|
|
44
|
+
|
|
45
|
+
REPLY_UUID = "0000ffe1-0000-1000-8000-00805f9b34fb"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class LengthFramed:
|
|
49
|
+
"""The device's framing: here, a length byte that counts the whole frame."""
|
|
50
|
+
|
|
51
|
+
def __init__(self) -> None:
|
|
52
|
+
self.buffer = bytearray()
|
|
53
|
+
|
|
54
|
+
def feed(self, data: bytes | bytearray) -> list[bytes]:
|
|
55
|
+
self.buffer += data
|
|
56
|
+
frames = []
|
|
57
|
+
while self.buffer and len(self.buffer) >= self.buffer[0] > 0:
|
|
58
|
+
frames.append(bytes(self.buffer[: self.buffer[0]]))
|
|
59
|
+
del self.buffer[: self.buffer[0]]
|
|
60
|
+
return frames
|
|
61
|
+
|
|
62
|
+
def reset(self) -> None:
|
|
63
|
+
self.buffer.clear()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
async def main() -> None:
|
|
67
|
+
device = await BleakScanner.find_device_by_address("AA:BB:CC:DD:EE:FF")
|
|
68
|
+
policy = LinkPolicy(settle_after_subscribe=0.5)
|
|
69
|
+
try:
|
|
70
|
+
async with BondedLink(
|
|
71
|
+
device, notify_uuid=REPLY_UUID, assembler=LengthFramed(), policy=policy
|
|
72
|
+
) as link:
|
|
73
|
+
reply = await link.request(b"\x02\x01", accept=lambda frame: frame[1] == 0x01)
|
|
74
|
+
print(reply.hex(" "), "via", link.last_source)
|
|
75
|
+
except PairingRequired:
|
|
76
|
+
print("Press the device's button, then connect with expect_new_bond=True.")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
asyncio.run(main())
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`ble_bond.testing` has a fake bleak client and a patch for the connection call, so a device
|
|
83
|
+
library can test its transport without hardware.
|
|
84
|
+
|
|
85
|
+
## Compatibility
|
|
86
|
+
|
|
87
|
+
Every 1.x release is backward compatible: several device libraries may be installed in one Home
|
|
88
|
+
Assistant, which then holds a single copy of this package. Depend on `ble-bond>=1.0,<2`.
|
|
89
|
+
|
|
90
|
+
## Acknowledgements
|
|
91
|
+
|
|
92
|
+
The BlueZ pairing agent is adapted from [alpha-hwr](https://github.com/eman/alpha-hwr) (MIT);
|
|
93
|
+
its notice is in [THIRD_PARTY_NOTICES.md](https://github.com/83noit/ble-bond/blob/main/THIRD_PARTY_NOTICES.md).
|
|
94
|
+
The pause after subscribing follows ESPHome's measurement in
|
|
95
|
+
[esphome/esphome#22651](https://github.com/esphome/esphome/pull/22651).
|
|
96
|
+
|
|
97
|
+
## Licence
|
|
98
|
+
|
|
99
|
+
MIT
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
ble-bond is MIT-licensed (see `LICENSE`). It includes code adapted from the project below,
|
|
4
|
+
whose licence asks for its copyright and permission notice to travel with every copy.
|
|
5
|
+
|
|
6
|
+
## alpha-hwr
|
|
7
|
+
|
|
8
|
+
- Project: <https://github.com/eman/alpha-hwr>
|
|
9
|
+
- Used in: `src/ble_bond/bluez.py` (the BlueZ pairing agent and its one-at-a-time lock), adapted from
|
|
10
|
+
`src/alpha_hwr/core/pairing_agent.py`
|
|
11
|
+
- Licence: MIT
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
MIT License
|
|
15
|
+
|
|
16
|
+
Copyright (c) 2026 Emmanuel Levijarvi
|
|
17
|
+
|
|
18
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
19
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
20
|
+
in the Software without restriction, including without limitation the rights
|
|
21
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
22
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
23
|
+
furnished to do so, subject to the following conditions:
|
|
24
|
+
|
|
25
|
+
The above copyright notice and this permission notice shall be included in all
|
|
26
|
+
copies or substantial portions of the Software.
|
|
27
|
+
|
|
28
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
30
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
31
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
32
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
33
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
34
|
+
SOFTWARE.
|
|
35
|
+
```
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ble-bond"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Bonded Bluetooth LE sessions for devices that pair in a button window and answer one request at a time"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE", "THIRD_PARTY_NOTICES.md"]
|
|
12
|
+
requires-python = ">=3.13"
|
|
13
|
+
authors = [{ name = "83noit" }]
|
|
14
|
+
keywords = ["bluetooth", "ble", "bleak", "pairing", "bonding", "home-assistant", "esphome"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Framework :: AsyncIO",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
23
|
+
"Programming Language :: Python :: 3.15",
|
|
24
|
+
"Topic :: Home Automation",
|
|
25
|
+
"Typing :: Typed",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"bleak>=3.0.2",
|
|
29
|
+
"bleak-retry-connector>=4.7.1",
|
|
30
|
+
"dbus-fast>=4.0; sys_platform == 'linux'",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/83noit/ble-bond"
|
|
35
|
+
Repository = "https://github.com/83noit/ble-bond"
|
|
36
|
+
Issues = "https://github.com/83noit/ble-bond/issues"
|
|
37
|
+
Changelog = "https://github.com/83noit/ble-bond/blob/main/CHANGELOG.md"
|
|
38
|
+
|
|
39
|
+
[dependency-groups]
|
|
40
|
+
dev = [
|
|
41
|
+
"pytest>=9",
|
|
42
|
+
"pytest-asyncio>=1.4.1",
|
|
43
|
+
"pytest-cov>=7",
|
|
44
|
+
"ruff>=0.14",
|
|
45
|
+
"mypy>=1.19",
|
|
46
|
+
# bluez.py imports dbus-fast on Linux only; mypy and the BlueZ tests need it everywhere.
|
|
47
|
+
"dbus-fast>=4.0",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[tool.uv]
|
|
51
|
+
# Resolve only releases at least a week old, so a compromised upload has time to be yanked.
|
|
52
|
+
exclude-newer = "7 days"
|
|
53
|
+
|
|
54
|
+
[tool.hatch.build.targets.wheel]
|
|
55
|
+
packages = ["src/ble_bond"]
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.sdist]
|
|
58
|
+
include = [
|
|
59
|
+
"/src", "/tests", "/README.md", "/CHANGELOG.md", "/LICENSE", "/THIRD_PARTY_NOTICES.md",
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
[tool.ruff]
|
|
63
|
+
line-length = 100
|
|
64
|
+
src = ["src", "tests"]
|
|
65
|
+
|
|
66
|
+
[tool.ruff.lint]
|
|
67
|
+
select = [
|
|
68
|
+
"E", "W", "F", "I", "B", "UP", "N", "SIM", "RUF", "ASYNC", "PT", "T20", "D",
|
|
69
|
+
"ANN", "ARG", "C4", "DTZ", "ERA", "ICN", "ISC", "PIE", "RET", "RSE", "SLF", "TID", "TRY",
|
|
70
|
+
]
|
|
71
|
+
ignore = [
|
|
72
|
+
"D203", # one-blank-line-before-class (conflicts with D211)
|
|
73
|
+
"D213", # multi-line-summary-second-line (conflicts with D212)
|
|
74
|
+
"TRY003", # long messages in exceptions are fine here
|
|
75
|
+
"ISC001", # conflicts with the formatter
|
|
76
|
+
"D105", # magic methods need no docstring
|
|
77
|
+
"D107", # __init__ is documented by the class
|
|
78
|
+
"N818", # exception names read better without an Error suffix here
|
|
79
|
+
"RUF001", # × and – are used deliberately in notes and docstrings
|
|
80
|
+
"RUF002",
|
|
81
|
+
"RUF003",
|
|
82
|
+
"ASYNC109", # explicit timeout parameters are part of the link API
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
[tool.ruff.lint.per-file-ignores]
|
|
86
|
+
"tests/**" = ["D", "ANN", "SLF001", "PLR2004", "ARG001"]
|
|
87
|
+
|
|
88
|
+
[tool.ruff.lint.pydocstyle]
|
|
89
|
+
convention = "pep257"
|
|
90
|
+
|
|
91
|
+
[tool.ruff.lint.isort]
|
|
92
|
+
known-first-party = ["ble_bond"]
|
|
93
|
+
|
|
94
|
+
[tool.mypy]
|
|
95
|
+
python_version = "3.13"
|
|
96
|
+
strict = true
|
|
97
|
+
warn_unreachable = true
|
|
98
|
+
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
|
|
99
|
+
packages = ["ble_bond"]
|
|
100
|
+
mypy_path = "src"
|
|
101
|
+
|
|
102
|
+
[[tool.mypy.overrides]]
|
|
103
|
+
module = ["tests.*"]
|
|
104
|
+
disallow_untyped_defs = false
|
|
105
|
+
|
|
106
|
+
[tool.pytest]
|
|
107
|
+
minversion = "9.0"
|
|
108
|
+
strict = true
|
|
109
|
+
addopts = ["-ra", "-q"]
|
|
110
|
+
filterwarnings = ["error"]
|
|
111
|
+
log_level = "INFO"
|
|
112
|
+
testpaths = ["tests"]
|
|
113
|
+
asyncio_mode = "auto"
|
|
114
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
115
|
+
|
|
116
|
+
[tool.coverage.run]
|
|
117
|
+
source = ["ble_bond"]
|
|
118
|
+
branch = true
|
|
119
|
+
|
|
120
|
+
[tool.coverage.report]
|
|
121
|
+
show_missing = true
|
|
122
|
+
skip_covered = false
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""ble-bond: bonded Bluetooth LE sessions for devices that pair in a button window.
|
|
2
|
+
|
|
3
|
+
For devices that accept a new bond only for a few seconds after a button press, and then answer
|
|
4
|
+
one request at a time with no request id, usually through a Home Assistant Bluetooth proxy.
|
|
5
|
+
The device library brings its framing (an :class:`Assembler`) and its :class:`LinkPolicy`;
|
|
6
|
+
ble-bond handles pairing, which adapter or proxy each attempt used, the BlueZ pairing agent, and
|
|
7
|
+
matching replies to requests.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from ble_bond.bluez import bluez_device_path, bluez_pairing_agent, remove_bluez_bond
|
|
13
|
+
from ble_bond.exceptions import (
|
|
14
|
+
ConnectionLost,
|
|
15
|
+
LinkError,
|
|
16
|
+
PairingRequired,
|
|
17
|
+
PairingUnsupported,
|
|
18
|
+
RequestTimeout,
|
|
19
|
+
)
|
|
20
|
+
from ble_bond.link import Accept, Assembler, BondedLink, LinkPolicy, SubscribeRetry
|
|
21
|
+
|
|
22
|
+
__version__ = "1.0.0"
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"Accept",
|
|
26
|
+
"Assembler",
|
|
27
|
+
"BondedLink",
|
|
28
|
+
"ConnectionLost",
|
|
29
|
+
"LinkError",
|
|
30
|
+
"LinkPolicy",
|
|
31
|
+
"PairingRequired",
|
|
32
|
+
"PairingUnsupported",
|
|
33
|
+
"RequestTimeout",
|
|
34
|
+
"SubscribeRetry",
|
|
35
|
+
"__version__",
|
|
36
|
+
"bluez_device_path",
|
|
37
|
+
"bluez_pairing_agent",
|
|
38
|
+
"remove_bluez_bond",
|
|
39
|
+
]
|