aiobmsble 0.3.0__tar.gz → 0.4__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.
- {aiobmsble-0.3.0/aiobmsble.egg-info → aiobmsble-0.4}/PKG-INFO +50 -9
- aiobmsble-0.4/README.md +131 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/__main__.py +1 -1
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/basebms.py +2 -2
- aiobmsble-0.4/aiobmsble/test_data/__init__.py +95 -0
- aiobmsble-0.4/aiobmsble/test_data/abc_bms.json +34 -0
- aiobmsble-0.4/aiobmsble/test_data/ant_bms.json +18 -0
- aiobmsble-0.4/aiobmsble/test_data/ant_leg_bms.json +19 -0
- aiobmsble-0.4/aiobmsble/test_data/braunpwr_bms.json +34 -0
- aiobmsble-0.4/aiobmsble/test_data/cbtpwr_bms.json +90 -0
- aiobmsble-0.4/aiobmsble/test_data/cbtpwr_vb_bms.json +20 -0
- aiobmsble-0.4/aiobmsble/test_data/daly_bms.json +100 -0
- aiobmsble-0.4/aiobmsble/test_data/dpwrcore_bms.json +18 -0
- aiobmsble-0.4/aiobmsble/test_data/ecoworthy_bms.json +100 -0
- aiobmsble-0.4/aiobmsble/test_data/ective_bms.json +104 -0
- aiobmsble-0.4/aiobmsble/test_data/ej_bms.json +107 -0
- aiobmsble-0.4/aiobmsble/test_data/felicity_bms.json +24 -0
- aiobmsble-0.4/aiobmsble/test_data/ignore.json +48 -0
- aiobmsble-0.4/aiobmsble/test_data/jbd_bms.json +440 -0
- aiobmsble-0.4/aiobmsble/test_data/jikong_bms.json +54 -0
- aiobmsble-0.4/aiobmsble/test_data/neey_bms.json +65 -0
- aiobmsble-0.4/aiobmsble/test_data/ogt_bms.json +16 -0
- aiobmsble-0.4/aiobmsble/test_data/pro_bms.json +15 -0
- aiobmsble-0.4/aiobmsble/test_data/redodo_bms.json +151 -0
- aiobmsble-0.4/aiobmsble/test_data/renogy_bms.json +19 -0
- aiobmsble-0.4/aiobmsble/test_data/renogy_pro_bms.json +16 -0
- aiobmsble-0.4/aiobmsble/test_data/roypow_bms.json +54 -0
- aiobmsble-0.4/aiobmsble/test_data/seplos_bms.json +96 -0
- aiobmsble-0.4/aiobmsble/test_data/seplos_v2_bms.json +41 -0
- aiobmsble-0.4/aiobmsble/test_data/tdt_bms.json +14 -0
- aiobmsble-0.4/aiobmsble/test_data/tianpwr_bms.json +13 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4/aiobmsble.egg-info}/PKG-INFO +50 -9
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble.egg-info/SOURCES.txt +28 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble.egg-info/requires.txt +1 -1
- {aiobmsble-0.3.0 → aiobmsble-0.4}/pyproject.toml +6 -6
- {aiobmsble-0.3.0 → aiobmsble-0.4}/tests/test_fuzzing.py +1 -1
- {aiobmsble-0.3.0 → aiobmsble-0.4}/tests/test_main.py +1 -1
- {aiobmsble-0.3.0 → aiobmsble-0.4}/tests/test_plugins.py +5 -7
- aiobmsble-0.4/tests/test_test_data.py +42 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/tests/test_utils.py +7 -7
- aiobmsble-0.3.0/README.md +0 -90
- {aiobmsble-0.3.0 → aiobmsble-0.4}/LICENSE +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/MANIFEST.in +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/__init__.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/__init__.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/abc_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/ant_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/ant_leg_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/braunpwr_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/cbtpwr_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/cbtpwr_vb_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/daly_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/dpwrcore_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/dummy_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/ecoworthy_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/ective_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/ej_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/felicity_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/jbd_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/jikong_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/neey_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/ogt_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/pro_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/redodo_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/renogy_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/renogy_pro_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/roypow_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/seplos_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/seplos_v2_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/tdt_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/bms/tianpwr_bms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble/utils.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble.egg-info/dependency_links.txt +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble.egg-info/entry_points.txt +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/aiobmsble.egg-info/top_level.txt +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/setup.cfg +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/tests/test_basebms.py +0 -0
- {aiobmsble-0.3.0 → aiobmsble-0.4}/tests/test_examples.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: aiobmsble
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4
|
4
4
|
Summary: Asynchronous Python library to query battery management systems via Bluetooth Low Energy.
|
5
5
|
Author: Patrick Loschmidt
|
6
6
|
Maintainer: Patrick Loschmidt
|
@@ -12,7 +12,7 @@ Project-URL: Bug Reports, https://github.com/patman15/aiobmsble/issues
|
|
12
12
|
Keywords: BMS,BLE,battery,bluetooth
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
14
14
|
Classifier: Operating System :: OS Independent
|
15
|
-
Classifier: Development Status ::
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
16
16
|
Classifier: Intended Audience :: Developers
|
17
17
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
18
18
|
Requires-Python: >=3.12
|
@@ -27,26 +27,42 @@ Requires-Dist: pytest-cov; extra == "dev"
|
|
27
27
|
Requires-Dist: pytest-xdist; extra == "dev"
|
28
28
|
Requires-Dist: hypothesis; extra == "dev"
|
29
29
|
Requires-Dist: mypy; extra == "dev"
|
30
|
-
Requires-Dist: ruff
|
30
|
+
Requires-Dist: ruff<0.14.0,>=0.12.1; extra == "dev"
|
31
31
|
Dynamic: license-file
|
32
32
|
|
33
|
+
[![GitHub Release][releases-shield]](https://pypi.org/p/aiobmsble/)
|
33
34
|
[![License][license-shield]](LICENSE)
|
34
35
|
|
35
36
|
# Aiobmsble
|
36
37
|
Requires Python 3 and uses [asyncio](https://pypi.org/project/asyncio/) and [bleak](https://pypi.org/project/bleak/)
|
37
|
-
> [!IMPORTANT]
|
38
|
-
> At the moment the library is under development and there might be missing functionality compared to the [BMS_BLE-HA integration](https://github.com/patman15/BMS_BLE-HA/)!
|
39
|
-
> Please do not (yet) report missing BMS support or bugs here. Instead please raise an issue at the integration till the library reached at least development status *beta*.
|
40
38
|
|
41
39
|
## Asynchronous Library to Query Battery Management Systems via Bluetooth LE
|
42
|
-
This library is intended to query data from battery management systems that use Bluetooth LE. It is developed to support [BMS_BLE-HA integration](https://github.com/patman15/BMS_BLE-HA/) that was written to make BMS data available to Home Assistant
|
40
|
+
This library is intended to query data from battery management systems that use Bluetooth LE. This library can be used stand-alone in any Python environment (with necessary dependencies installed). It is developed to support [BMS_BLE-HA integration](https://github.com/patman15/BMS_BLE-HA/) that was written to make BMS data available to Home Assistant, but can be hopefully usefull for other use-cases as well.
|
41
|
+
|
42
|
+
* [Features](#features)
|
43
|
+
* [Usage](#usage)
|
44
|
+
* [Installation](#installation)
|
45
|
+
* [Troubleshooting](#troubleshooting)
|
46
|
+
|
47
|
+
## Features
|
48
|
+
- Support for autodetecting compatible BLE BMSs
|
49
|
+
- Automatic detection of compatible BLE write mode
|
50
|
+
- Asynchronous operation using [asyncio](https://pypi.org/project/asyncio/)
|
51
|
+
- Any number of batteries in parallel
|
52
|
+
- 100% test coverage plus fuzz tests for BLE data
|
53
|
+
|
54
|
+
### Supported Devices
|
55
|
+
The [list of supported devices](https://github.com/patman15/BMS_BLE-HA/blob/feature-aiobmsble/README.md#supported-devices) is maintained in the repository of the related [Home Assistant integration](https://github.com/patman15/BMS_BLE-HA).
|
43
56
|
|
44
57
|
## Usage
|
45
58
|
In order to identify all devices that are reachable and supported by the library, simply run
|
46
59
|
```bash
|
47
60
|
aiobmsble
|
48
61
|
```
|
49
|
-
from the command line after [installation](#installation).
|
62
|
+
from the command line after [installation](#installation).
|
63
|
+
|
64
|
+
### From your Python code
|
65
|
+
In case you need a reference to include the code into your library, please see [\_\_main\_\_.py](/aiobmsble/__main__.py).
|
50
66
|
|
51
67
|
### From a Script
|
52
68
|
This example can also be found as an [example](/examples/minimal.py) in the respective [folder](/main/examples).
|
@@ -97,6 +113,20 @@ if __name__ == "__main__":
|
|
97
113
|
asyncio.run(main(NAME)) # pragma: no cover
|
98
114
|
```
|
99
115
|
|
116
|
+
### Testing
|
117
|
+
For integrations tests (using pytest) the library provides advertisement data that can be used to verify detection of BMSs. To use it, include the following line into your `conftest.py`:
|
118
|
+
```python
|
119
|
+
pytest_plugins: list[str] = ["aiobmsble.test_data"]
|
120
|
+
```
|
121
|
+
|
122
|
+
For your tests you can then use
|
123
|
+
```python
|
124
|
+
def test_advertisements(bms_advertisements) -> None:
|
125
|
+
"""Run some tests with the advertisements"""
|
126
|
+
for advertisement, bms_type, _comments in bms_advertisements:
|
127
|
+
...
|
128
|
+
```
|
129
|
+
|
100
130
|
## Installation
|
101
131
|
Install python and pip if you have not already, then run:
|
102
132
|
```bash
|
@@ -119,4 +149,15 @@ pip3 install -e .[dev]
|
|
119
149
|
```
|
120
150
|
This gives you the latest library code from the main branch.
|
121
151
|
|
122
|
-
|
152
|
+
## Troubleshooting
|
153
|
+
In case you have problems with the library, please enable debug logging. You can also run `aiobmsble -v` from the command line in order to query all known BMS that are reachable.
|
154
|
+
|
155
|
+
### In case you have troubles you'd like to have help with
|
156
|
+
|
157
|
+
- please record a debug log using `aiobmsble -v -l debug.log`,
|
158
|
+
- [open an issue](https://github.com/patman15/aiobmsble/issues/new?assignees=&labels=question&projects=&template=support.yml) with a good description of what your question/issue is and attach the log, or
|
159
|
+
- [open a bug](https://github.com/patman15/aiobmsble/issues/new?assignees=&labels=Bug&projects=&template=bug.yml) if you think the behaviour you see is misbehaviour of the library, including a good description of what happened, your expectations,
|
160
|
+
- and put the `debug.log` **as attachement** to the issue.
|
161
|
+
|
162
|
+
[license-shield]: https://img.shields.io/github/license/patman15/aiobmsble?style=for-the-badge&cacheSeconds=86400
|
163
|
+
[releases-shield]: https://img.shields.io/pypi/v/aiobmsble?style=for-the-badge
|
aiobmsble-0.4/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
[![GitHub Release][releases-shield]](https://pypi.org/p/aiobmsble/)
|
2
|
+
[![License][license-shield]](LICENSE)
|
3
|
+
|
4
|
+
# Aiobmsble
|
5
|
+
Requires Python 3 and uses [asyncio](https://pypi.org/project/asyncio/) and [bleak](https://pypi.org/project/bleak/)
|
6
|
+
|
7
|
+
## Asynchronous Library to Query Battery Management Systems via Bluetooth LE
|
8
|
+
This library is intended to query data from battery management systems that use Bluetooth LE. This library can be used stand-alone in any Python environment (with necessary dependencies installed). It is developed to support [BMS_BLE-HA integration](https://github.com/patman15/BMS_BLE-HA/) that was written to make BMS data available to Home Assistant, but can be hopefully usefull for other use-cases as well.
|
9
|
+
|
10
|
+
* [Features](#features)
|
11
|
+
* [Usage](#usage)
|
12
|
+
* [Installation](#installation)
|
13
|
+
* [Troubleshooting](#troubleshooting)
|
14
|
+
|
15
|
+
## Features
|
16
|
+
- Support for autodetecting compatible BLE BMSs
|
17
|
+
- Automatic detection of compatible BLE write mode
|
18
|
+
- Asynchronous operation using [asyncio](https://pypi.org/project/asyncio/)
|
19
|
+
- Any number of batteries in parallel
|
20
|
+
- 100% test coverage plus fuzz tests for BLE data
|
21
|
+
|
22
|
+
### Supported Devices
|
23
|
+
The [list of supported devices](https://github.com/patman15/BMS_BLE-HA/blob/feature-aiobmsble/README.md#supported-devices) is maintained in the repository of the related [Home Assistant integration](https://github.com/patman15/BMS_BLE-HA).
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
In order to identify all devices that are reachable and supported by the library, simply run
|
27
|
+
```bash
|
28
|
+
aiobmsble
|
29
|
+
```
|
30
|
+
from the command line after [installation](#installation).
|
31
|
+
|
32
|
+
### From your Python code
|
33
|
+
In case you need a reference to include the code into your library, please see [\_\_main\_\_.py](/aiobmsble/__main__.py).
|
34
|
+
|
35
|
+
### From a Script
|
36
|
+
This example can also be found as an [example](/examples/minimal.py) in the respective [folder](/main/examples).
|
37
|
+
```python
|
38
|
+
"""Example of using the aiobmsble library to find a BLE device by name and print its sensor data.
|
39
|
+
|
40
|
+
Project: aiobmsble, https://pypi.org/p/aiobmsble/
|
41
|
+
License: Apache-2.0, http://www.apache.org/licenses/
|
42
|
+
"""
|
43
|
+
|
44
|
+
import asyncio
|
45
|
+
import logging
|
46
|
+
from typing import Final
|
47
|
+
|
48
|
+
from bleak import BleakScanner
|
49
|
+
from bleak.backends.device import BLEDevice
|
50
|
+
from bleak.exc import BleakError
|
51
|
+
|
52
|
+
from aiobmsble import BMSsample
|
53
|
+
from aiobmsble.bms.dummy_bms import BMS # TODO: use the right BMS class for your device
|
54
|
+
|
55
|
+
NAME: Final[str] = "BT Device Name" # TODO: replace with the name of your BLE device
|
56
|
+
|
57
|
+
# Configure logging
|
58
|
+
logging.basicConfig(level=logging.INFO)
|
59
|
+
logger: logging.Logger = logging.getLogger(__name__)
|
60
|
+
|
61
|
+
|
62
|
+
async def main(dev_name) -> None:
|
63
|
+
"""Find a BLE device by name and update its sensor data."""
|
64
|
+
|
65
|
+
device: BLEDevice | None = await BleakScanner.find_device_by_name(dev_name)
|
66
|
+
if device is None:
|
67
|
+
logger.error("Device '%s' not found.", dev_name)
|
68
|
+
return
|
69
|
+
|
70
|
+
logger.info("Found device: %s (%s)", device.name, device.address)
|
71
|
+
try:
|
72
|
+
async with BMS(ble_device=device) as bms:
|
73
|
+
logger.info("Updating BMS data...")
|
74
|
+
data: BMSsample = await bms.async_update()
|
75
|
+
logger.info("BMS data: %s", repr(data).replace(", ", ",\n\t"))
|
76
|
+
except BleakError as ex:
|
77
|
+
logger.error("Failed to update BMS: %s", type(ex).__name__)
|
78
|
+
|
79
|
+
|
80
|
+
if __name__ == "__main__":
|
81
|
+
asyncio.run(main(NAME)) # pragma: no cover
|
82
|
+
```
|
83
|
+
|
84
|
+
### Testing
|
85
|
+
For integrations tests (using pytest) the library provides advertisement data that can be used to verify detection of BMSs. To use it, include the following line into your `conftest.py`:
|
86
|
+
```python
|
87
|
+
pytest_plugins: list[str] = ["aiobmsble.test_data"]
|
88
|
+
```
|
89
|
+
|
90
|
+
For your tests you can then use
|
91
|
+
```python
|
92
|
+
def test_advertisements(bms_advertisements) -> None:
|
93
|
+
"""Run some tests with the advertisements"""
|
94
|
+
for advertisement, bms_type, _comments in bms_advertisements:
|
95
|
+
...
|
96
|
+
```
|
97
|
+
|
98
|
+
## Installation
|
99
|
+
Install python and pip if you have not already, then run:
|
100
|
+
```bash
|
101
|
+
pip3 install pip --upgrade
|
102
|
+
pip3 install wheel
|
103
|
+
```
|
104
|
+
|
105
|
+
### For Production:
|
106
|
+
|
107
|
+
```bash
|
108
|
+
pip3 install aiobmsble
|
109
|
+
```
|
110
|
+
This will install the latest library release and all of it's python dependencies.
|
111
|
+
|
112
|
+
### For Development:
|
113
|
+
```bash
|
114
|
+
git clone https://github.com/patman15/aiobmsble.git
|
115
|
+
cd aiobmsble
|
116
|
+
pip3 install -e .[dev]
|
117
|
+
```
|
118
|
+
This gives you the latest library code from the main branch.
|
119
|
+
|
120
|
+
## Troubleshooting
|
121
|
+
In case you have problems with the library, please enable debug logging. You can also run `aiobmsble -v` from the command line in order to query all known BMS that are reachable.
|
122
|
+
|
123
|
+
### In case you have troubles you'd like to have help with
|
124
|
+
|
125
|
+
- please record a debug log using `aiobmsble -v -l debug.log`,
|
126
|
+
- [open an issue](https://github.com/patman15/aiobmsble/issues/new?assignees=&labels=question&projects=&template=support.yml) with a good description of what your question/issue is and attach the log, or
|
127
|
+
- [open a bug](https://github.com/patman15/aiobmsble/issues/new?assignees=&labels=Bug&projects=&template=bug.yml) if you think the behaviour you see is misbehaviour of the library, including a good description of what happened, your expectations,
|
128
|
+
- and put the `debug.log` **as attachement** to the issue.
|
129
|
+
|
130
|
+
[license-shield]: https://img.shields.io/github/license/patman15/aiobmsble?style=for-the-badge&cacheSeconds=86400
|
131
|
+
[releases-shield]: https://img.shields.io/pypi/v/aiobmsble?style=for-the-badge
|
@@ -31,7 +31,7 @@ async def scan_devices() -> dict[str, tuple[BLEDevice, AdvertisementData]]:
|
|
31
31
|
scan_result: dict[str, tuple[BLEDevice, AdvertisementData]] = (
|
32
32
|
await BleakScanner.discover(return_adv=True)
|
33
33
|
)
|
34
|
-
logger.
|
34
|
+
logger.debug(scan_result)
|
35
35
|
logger.info("%i BT devices in range.", len(scan_result))
|
36
36
|
return scan_result
|
37
37
|
|
@@ -379,8 +379,8 @@ class BaseBMS(ABC):
|
|
379
379
|
if reset:
|
380
380
|
self._inv_wr_mode = None # reset write mode
|
381
381
|
await self._client.disconnect()
|
382
|
-
except BleakError:
|
383
|
-
self._log.
|
382
|
+
except (BleakError, TimeoutError) as exc:
|
383
|
+
self._log.error("disconnect failed! (%s)", type(exc).__name__)
|
384
384
|
|
385
385
|
async def _wait_event(self) -> None:
|
386
386
|
"""Wait for data event and clear it."""
|
@@ -0,0 +1,95 @@
|
|
1
|
+
"""Test advertisements for aiobmsble package."""
|
2
|
+
|
3
|
+
from importlib import resources
|
4
|
+
import json
|
5
|
+
from typing import Any
|
6
|
+
|
7
|
+
from bleak.backends.scanner import AdvertisementData
|
8
|
+
import pytest
|
9
|
+
|
10
|
+
from tests.bluetooth import generate_advertisement_data
|
11
|
+
|
12
|
+
type BmsAdvList = list[tuple[AdvertisementData, str, list[str]]]
|
13
|
+
|
14
|
+
|
15
|
+
def _json_dict_to_advdata(json_dict: dict[str, Any]) -> AdvertisementData:
|
16
|
+
"""Generate an AdvertisementData instance from a JSON dictionary."""
|
17
|
+
|
18
|
+
if "manufacturer_data" in json_dict:
|
19
|
+
json_dict["manufacturer_data"] = {
|
20
|
+
int(k): bytes.fromhex(v) for k, v in json_dict["manufacturer_data"].items()
|
21
|
+
}
|
22
|
+
if "service_data" in json_dict:
|
23
|
+
json_dict["service_data"] = {
|
24
|
+
k: bytes.fromhex(v) for k, v in json_dict["service_data"].items()
|
25
|
+
}
|
26
|
+
if "platform_data" in json_dict:
|
27
|
+
json_dict["platform_data"] = tuple(json_dict.get("platform_data", []))
|
28
|
+
|
29
|
+
return generate_advertisement_data(**json_dict)
|
30
|
+
|
31
|
+
|
32
|
+
@pytest.fixture
|
33
|
+
def bms_advertisements() -> BmsAdvList:
|
34
|
+
"""Provide all available BMS advertisements from test data directory.
|
35
|
+
|
36
|
+
Load all *_bms.json files from the packaged test data directory.
|
37
|
+
"""
|
38
|
+
all_data: BmsAdvList = []
|
39
|
+
|
40
|
+
for resource in resources.files(__package__).iterdir():
|
41
|
+
if resource.name.endswith("_bms.json"):
|
42
|
+
with resource.open("r", encoding="UTF-8") as f:
|
43
|
+
raw_data: Any = json.load(f)
|
44
|
+
assert isinstance(raw_data, list)
|
45
|
+
|
46
|
+
for entry in raw_data:
|
47
|
+
assert isinstance(entry, dict)
|
48
|
+
assert {"advertisement", "type"}.issubset(set(entry.keys()))
|
49
|
+
adv: AdvertisementData = _json_dict_to_advdata(
|
50
|
+
entry["advertisement"]
|
51
|
+
)
|
52
|
+
bms_type: str = entry["type"]
|
53
|
+
comments: list[str] = entry["_comments"]
|
54
|
+
|
55
|
+
assert isinstance(adv, AdvertisementData)
|
56
|
+
assert isinstance(bms_type, str)
|
57
|
+
assert isinstance(comments, list)
|
58
|
+
assert all(isinstance(c, str) for c in comments)
|
59
|
+
assert resource.name == f"{bms_type}.json"
|
60
|
+
|
61
|
+
all_data.append((adv, bms_type, comments))
|
62
|
+
return all_data
|
63
|
+
|
64
|
+
|
65
|
+
@pytest.fixture
|
66
|
+
def ignore_advertisements() -> BmsAdvList:
|
67
|
+
"""Provide a list of advertisements that shall not be identified as a valid BMS.
|
68
|
+
|
69
|
+
Load ignore.json files from the packaged test data directory.
|
70
|
+
"""
|
71
|
+
data: BmsAdvList = []
|
72
|
+
|
73
|
+
with (
|
74
|
+
resources.files(__package__)
|
75
|
+
.joinpath("ignore.json")
|
76
|
+
.open("r", encoding="UTF-8") as f
|
77
|
+
):
|
78
|
+
raw_data: Any = json.load(f)
|
79
|
+
assert isinstance(raw_data, list)
|
80
|
+
|
81
|
+
for entry in raw_data:
|
82
|
+
assert isinstance(entry, dict)
|
83
|
+
assert {"advertisement", "reason"}.issubset(set(entry.keys()))
|
84
|
+
adv: AdvertisementData = _json_dict_to_advdata(entry["advertisement"])
|
85
|
+
reason: str = entry["reason"]
|
86
|
+
comments: list[str] = entry["_comments"]
|
87
|
+
|
88
|
+
assert isinstance(adv, AdvertisementData)
|
89
|
+
assert isinstance(reason, str)
|
90
|
+
assert isinstance(comments, list)
|
91
|
+
assert all(isinstance(c, str) for c in comments)
|
92
|
+
|
93
|
+
data.append((adv, reason, comments))
|
94
|
+
|
95
|
+
return data
|
@@ -0,0 +1,34 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"advertisement": {
|
4
|
+
"local_name": "SOK-24V1127",
|
5
|
+
"service_uuids": [
|
6
|
+
"0000fff0-0000-1000-8000-00805f9b34fb"
|
7
|
+
],
|
8
|
+
"rssi": -94
|
9
|
+
},
|
10
|
+
"type": "abc_bms",
|
11
|
+
"_comments": [
|
12
|
+
"source pcap (https://github.com/patman15/BMS_BLE-HA/issues/168)"
|
13
|
+
]
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"advertisement": {
|
17
|
+
"local_name": "SOK-AA02120",
|
18
|
+
"service_uuids": [
|
19
|
+
"00001800-0000-1000-8000-00805f9b34fb",
|
20
|
+
"00001801-0000-1000-8000-00805f9b34fb",
|
21
|
+
"0000180a-0000-1000-8000-00805f9b34fb",
|
22
|
+
"0000180f-0000-1000-8000-00805f9b34fb",
|
23
|
+
"0000ffe0-0000-1000-8000-00805f9b34fb",
|
24
|
+
"0000fff0-0000-1000-8000-00805f9b34fb",
|
25
|
+
"f000ffc0-0451-4000-b000-000000000000"
|
26
|
+
],
|
27
|
+
"rssi": -62
|
28
|
+
},
|
29
|
+
"type": "abc_bms",
|
30
|
+
"_comments": [
|
31
|
+
"source log (https://github.com/patman15/BMS_BLE-HA/issues/394)"
|
32
|
+
]
|
33
|
+
}
|
34
|
+
]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"advertisement": {
|
4
|
+
"local_name": "ANT-BLE24C-001",
|
5
|
+
"manufacturer_data": {
|
6
|
+
"8979": "88a0aabbcc900001"
|
7
|
+
},
|
8
|
+
"service_uuids": [
|
9
|
+
"0000ffe0-0000-1000-8000-00805f9b34fb"
|
10
|
+
],
|
11
|
+
"rssi": -70
|
12
|
+
},
|
13
|
+
"type": "ant_bms",
|
14
|
+
"_comments": [
|
15
|
+
"source advmon (https://github.com/patman15/BMS_BLE-HA/issues/366)"
|
16
|
+
]
|
17
|
+
}
|
18
|
+
]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"advertisement": {
|
4
|
+
"local_name": "ANT-BLE16S",
|
5
|
+
"manufacturer_data": {
|
6
|
+
"1623": "88a0aabbcca12345"
|
7
|
+
},
|
8
|
+
"service_uuids": [
|
9
|
+
"0000ffe0-0000-1000-8000-00805f9b34fb",
|
10
|
+
"0000fee7-0000-1000-8000-00805f9b34fb"
|
11
|
+
],
|
12
|
+
"rssi": -31
|
13
|
+
},
|
14
|
+
"type": "ant_leg_bms",
|
15
|
+
"_comments": [
|
16
|
+
"source HA Bluetooth"
|
17
|
+
]
|
18
|
+
}
|
19
|
+
]
|
@@ -0,0 +1,34 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"advertisement": {
|
4
|
+
"local_name": "HSKS-25A-118",
|
5
|
+
"manufacturer_data": {
|
6
|
+
"123": "02ffff7b"
|
7
|
+
},
|
8
|
+
"service_uuids": [
|
9
|
+
"0000ff00-0000-1000-8000-00805f9b34fb"
|
10
|
+
],
|
11
|
+
"rssi": -70
|
12
|
+
},
|
13
|
+
"type": "braunpwr_bms",
|
14
|
+
"_comments": [
|
15
|
+
"source pcap (https://github.com/patman15/BMS_BLE-HA/issues/303)"
|
16
|
+
]
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"advertisement": {
|
20
|
+
"local_name": "BL-25F-170-118",
|
21
|
+
"manufacturer_data": {
|
22
|
+
"123": "02ffff7d"
|
23
|
+
},
|
24
|
+
"service_uuids": [
|
25
|
+
"0000ff00-0000-1000-8000-00805f9b34fb"
|
26
|
+
],
|
27
|
+
"rssi": -76
|
28
|
+
},
|
29
|
+
"type": "braunpwr_bms",
|
30
|
+
"_comments": [
|
31
|
+
"source LOG (https://github.com/patman15/BMS_BLE-HA/issues/303)"
|
32
|
+
]
|
33
|
+
}
|
34
|
+
]
|
@@ -0,0 +1,90 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"advertisement": {
|
4
|
+
"local_name": "170R000121",
|
5
|
+
"manufacturer_data": {
|
6
|
+
"21330": "2134ba03ec110cb4010500010000"
|
7
|
+
},
|
8
|
+
"service_uuids": [
|
9
|
+
"00001800-0000-1000-8000-00805f9b34fb",
|
10
|
+
"00001801-0000-1000-8000-00805f9b34fb",
|
11
|
+
"0000180a-0000-1000-8000-00805f9b34fb",
|
12
|
+
"0000fd00-0000-1000-8000-00805f9b34fb",
|
13
|
+
"0000ff90-0000-1000-8000-00805f9b34fb",
|
14
|
+
"0000ffb0-0000-1000-8000-00805f9b34fb",
|
15
|
+
"0000ffc0-0000-1000-8000-00805f9b34fb",
|
16
|
+
"0000ffd0-0000-1000-8000-00805f9b34fb",
|
17
|
+
"0000ffe0-0000-1000-8000-00805f9b34fb",
|
18
|
+
"0000ffe5-0000-1000-8000-00805f9b34fb",
|
19
|
+
"0000fff0-0000-1000-8000-00805f9b34fb"
|
20
|
+
],
|
21
|
+
"tx_power": 0,
|
22
|
+
"rssi": -75
|
23
|
+
},
|
24
|
+
"type": "cbtpwr_bms",
|
25
|
+
"_comments": [
|
26
|
+
"source LOG, https://github.com/patman15/BMS_BLE-HA/issues/59"
|
27
|
+
]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"advertisement": {
|
31
|
+
"local_name": "170R000086",
|
32
|
+
"manufacturer_data": {
|
33
|
+
"21330": "2134ba03ec110cf8010500010000"
|
34
|
+
},
|
35
|
+
"service_uuids": [
|
36
|
+
"00001800-0000-1000-8000-00805f9b34fb",
|
37
|
+
"00001801-0000-1000-8000-00805f9b34fb",
|
38
|
+
"0000180a-0000-1000-8000-00805f9b34fb",
|
39
|
+
"0000fd00-0000-1000-8000-00805f9b34fb",
|
40
|
+
"0000ff90-0000-1000-8000-00805f9b34fb",
|
41
|
+
"0000ffb0-0000-1000-8000-00805f9b34fb",
|
42
|
+
"0000ffc0-0000-1000-8000-00805f9b34fb",
|
43
|
+
"0000ffd0-0000-1000-8000-00805f9b34fb",
|
44
|
+
"0000ffe0-0000-1000-8000-00805f9b34fb",
|
45
|
+
"0000ffe5-0000-1000-8000-00805f9b34fb",
|
46
|
+
"0000fff0-0000-1000-8000-00805f9b34fb"
|
47
|
+
],
|
48
|
+
"tx_power": 0,
|
49
|
+
"rssi": -73
|
50
|
+
},
|
51
|
+
"type": "cbtpwr_bms",
|
52
|
+
"_comments": [
|
53
|
+
"source LOG"
|
54
|
+
]
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"advertisement": {
|
58
|
+
"local_name": "140R000288",
|
59
|
+
"manufacturer_data": {
|
60
|
+
"0": "ffffffff6400ff000000000000000000"
|
61
|
+
},
|
62
|
+
"service_uuids": [
|
63
|
+
"0000fff0-0000-1000-8000-00805f9b34fb"
|
64
|
+
],
|
65
|
+
"rssi": -82
|
66
|
+
},
|
67
|
+
"type": "cbtpwr_bms",
|
68
|
+
"_comments": [
|
69
|
+
"source BT monitor (https://github.com/patman15/BMS_BLE-HA/issues/176)"
|
70
|
+
]
|
71
|
+
},
|
72
|
+
{
|
73
|
+
"advertisement": {
|
74
|
+
"local_name": "100R0002E3",
|
75
|
+
"manufacturer_data": {
|
76
|
+
"21330": "2134ba03ec110909010500010000"
|
77
|
+
},
|
78
|
+
"service_uuids": [
|
79
|
+
"000003c1-0000-1000-8000-00805f9b34fb"
|
80
|
+
],
|
81
|
+
"tx_power": 0,
|
82
|
+
"rssi": -76
|
83
|
+
},
|
84
|
+
"type": "cbtpwr_bms",
|
85
|
+
"_comments": [
|
86
|
+
"source advmon (https://github.com/patman15/BMS_BLE-HA/issues/197)",
|
87
|
+
"Creabest"
|
88
|
+
]
|
89
|
+
}
|
90
|
+
]
|
@@ -0,0 +1,20 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"advertisement": {
|
4
|
+
"local_name": "VB024000390",
|
5
|
+
"manufacturer_data": {
|
6
|
+
"16963": "545e0211f82e0ca88942"
|
7
|
+
},
|
8
|
+
"service_uuids": [
|
9
|
+
"0000fff0-0000-1000-8000-00805f9b34fb",
|
10
|
+
"0000ffb0-0000-1000-8000-00805f9b34fb"
|
11
|
+
],
|
12
|
+
"rssi": -73
|
13
|
+
},
|
14
|
+
"type": "cbtpwr_vb_bms",
|
15
|
+
"_comments": [
|
16
|
+
"source advmon (https://github.com/patman15/BMS_BLE-HA/issues/240)",
|
17
|
+
"Creabest"
|
18
|
+
]
|
19
|
+
}
|
20
|
+
]
|
@@ -0,0 +1,100 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"advertisement": {
|
4
|
+
"local_name": "DL-46640102XXXX",
|
5
|
+
"manufacturer_data": {
|
6
|
+
"25670": "010209ac"
|
7
|
+
},
|
8
|
+
"service_uuids": [
|
9
|
+
"0000fff0-0000-1000-8000-00805f9b34fb"
|
10
|
+
],
|
11
|
+
"rssi": -58
|
12
|
+
},
|
13
|
+
"type": "daly_bms",
|
14
|
+
"_comments": [
|
15
|
+
"source LOG (https://github.com/patman15/BMS_BLE-HA/issues/89)"
|
16
|
+
]
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"advertisement": {
|
20
|
+
"local_name": "DL-401710015C9B",
|
21
|
+
"manufacturer_data": {
|
22
|
+
"770": "16401710015c9b444c"
|
23
|
+
},
|
24
|
+
"rssi": -36
|
25
|
+
},
|
26
|
+
"type": "daly_bms",
|
27
|
+
"_comments": [
|
28
|
+
"source LOG, proxy (https://github.com/patman15/BMS_BLE-HA/issues/160)"
|
29
|
+
]
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"advertisement": {
|
33
|
+
"local_name": "JHB-501812XXXXXX",
|
34
|
+
"manufacturer_data": {
|
35
|
+
"260": "0150181201a3b34a4842"
|
36
|
+
},
|
37
|
+
"rssi": -46
|
38
|
+
},
|
39
|
+
"type": "daly_bms",
|
40
|
+
"_comments": [
|
41
|
+
"source BTctl (https://github.com/patman15/BMS_BLE-HA/issues/145)"
|
42
|
+
]
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"advertisement": {
|
46
|
+
"local_name": "Randomname",
|
47
|
+
"manufacturer_data": {
|
48
|
+
"260": "0150181201a4944a4842"
|
49
|
+
},
|
50
|
+
"rssi": -36
|
51
|
+
},
|
52
|
+
"type": "daly_bms",
|
53
|
+
"_comments": [
|
54
|
+
"source LOG (https://github.com/patman15/BMS_BLE-HA/issues/160#issuecomment-2629318416)",
|
55
|
+
"JHB-50181201A494"
|
56
|
+
]
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"advertisement": {
|
60
|
+
"local_name": "BT270-2",
|
61
|
+
"manufacturer_data": {
|
62
|
+
"770": "16401712011197444c"
|
63
|
+
},
|
64
|
+
"rssi": -60
|
65
|
+
},
|
66
|
+
"type": "daly_bms",
|
67
|
+
"_comments": [
|
68
|
+
"source BTctl (https://github.com/patman15/BMS_BLE-HA/issues/174#issuecomment-2637936795)"
|
69
|
+
]
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"advertisement": {
|
73
|
+
"local_name": "DL-40160901534C",
|
74
|
+
"manufacturer_data": {
|
75
|
+
"258": "04"
|
76
|
+
},
|
77
|
+
"rssi": -87
|
78
|
+
},
|
79
|
+
"type": "daly_bms",
|
80
|
+
"_comments": [
|
81
|
+
"source advmon (https://github.com/patman15/BMS_BLE-HA/issues/204)",
|
82
|
+
"16S LiFePo 250A BMS"
|
83
|
+
]
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"advertisement": {
|
87
|
+
"local_name": "DL-FB4C2E0000000",
|
88
|
+
"manufacturer_data": {
|
89
|
+
"771": "00b4c2e0000000444c00"
|
90
|
+
},
|
91
|
+
"rssi": -81
|
92
|
+
},
|
93
|
+
"type": "daly_bms",
|
94
|
+
"_comments": [
|
95
|
+
"proxy LOG (https://github.com/patman15/BMS_BLE-HA/issues/85)",
|
96
|
+
"Bulltron battery",
|
97
|
+
"MAC address (Bouffalo Lab)"
|
98
|
+
]
|
99
|
+
}
|
100
|
+
]
|