sok-ble 0.1.6__tar.gz → 0.1.9b2__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.
- sok_ble-0.1.9b2/.github/dependabot.yml +15 -0
- sok_ble-0.1.9b2/.github/workflows/prerelease.yml +105 -0
- sok_ble-0.1.9b2/.github/workflows/release.yml +62 -0
- sok_ble-0.1.9b2/.github/workflows/test.yml +48 -0
- sok_ble-0.1.9b2/.release-please-manifest.json +3 -0
- sok_ble-0.1.9b2/AGENTS.md +67 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/CHANGELOG.md +27 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/PKG-INFO +5 -3
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/README.md +4 -2
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/pyproject.toml +2 -5
- sok_ble-0.1.9b2/release-please-config.json +14 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/src/sok_ble/exceptions.py +0 -1
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/src/sok_ble/sok_bluetooth_device.py +31 -9
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/src/sok_ble/sok_parser.py +5 -4
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/tests/test_derived.py +0 -1
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/tests/test_exceptions.py +0 -1
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/tests/test_parser_full.py +4 -13
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/tests/test_parser_info.py +1 -3
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/uv.lock +200 -174
- sok_ble-0.1.6/.github/copilot-instructions.md +0 -22
- sok_ble-0.1.6/.github/workflows/ci.yml +0 -84
- sok_ble-0.1.6/AGENTS.md +0 -3
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/.github/FUNDING.yml +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/.gitignore +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/.python-version +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/LICENSE +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/prompts.md +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/requirements-dev.txt +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/spec.md +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/src/sok_ble/__init__.py +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/src/sok_ble/const.py +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/tests/.gitkeep +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/tests/__init__.py +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/tests/test_const.py +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/tests/test_device_full.py +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/tests/test_device_minimal.py +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/tests/test_integration_mock.py +0 -0
- {sok_ble-0.1.6 → sok_ble-0.1.9b2}/todo.md +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
|
|
3
|
+
updates:
|
|
4
|
+
- package-ecosystem: "uv"
|
|
5
|
+
directory: "/"
|
|
6
|
+
schedule:
|
|
7
|
+
interval: "weekly"
|
|
8
|
+
|
|
9
|
+
# Enable version updates for GitHub Actions
|
|
10
|
+
- package-ecosystem: "github-actions"
|
|
11
|
+
# Workflow files stored in the default location of `.github/workflows`
|
|
12
|
+
# You don't need to specify `/.github/workflows` for `directory`. You can use `directory: "/"`.
|
|
13
|
+
directory: "/"
|
|
14
|
+
schedule:
|
|
15
|
+
interval: "weekly"
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
name: Prerelease
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches: [main]
|
|
6
|
+
types: [opened]
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
inputs:
|
|
9
|
+
release_branch:
|
|
10
|
+
description: Branch to build from
|
|
11
|
+
required: false
|
|
12
|
+
default: release-please--branches--main
|
|
13
|
+
semantic_version:
|
|
14
|
+
description: Optional semantic version to publish (x.x.x)
|
|
15
|
+
required: false
|
|
16
|
+
prerelease:
|
|
17
|
+
description: Prerelease type (defaults to beta)
|
|
18
|
+
required: false
|
|
19
|
+
type: choice
|
|
20
|
+
options:
|
|
21
|
+
- beta
|
|
22
|
+
- alpha
|
|
23
|
+
beta_iteration:
|
|
24
|
+
description: Optional alpha/beta iteration identifier (defaults to run number)
|
|
25
|
+
required: false
|
|
26
|
+
|
|
27
|
+
permissions:
|
|
28
|
+
contents: write
|
|
29
|
+
id-token: write
|
|
30
|
+
|
|
31
|
+
jobs:
|
|
32
|
+
publish-beta:
|
|
33
|
+
if: |
|
|
34
|
+
github.event_name == 'workflow_dispatch' ||
|
|
35
|
+
(github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'release-please--'))
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
environment: release
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v6
|
|
40
|
+
with:
|
|
41
|
+
ref: ${{ github.event_name == 'workflow_dispatch' && (inputs.release_branch || 'release-please--main') || github.event.pull_request.head.ref }}
|
|
42
|
+
fetch-depth: 0
|
|
43
|
+
|
|
44
|
+
- name: Install uv
|
|
45
|
+
uses: astral-sh/setup-uv@v7
|
|
46
|
+
|
|
47
|
+
- name: Set up Python
|
|
48
|
+
run: uv python install
|
|
49
|
+
|
|
50
|
+
- name: Derive beta version
|
|
51
|
+
id: version
|
|
52
|
+
env:
|
|
53
|
+
BETA_ITERATION: ${{ github.event_name == 'workflow_dispatch' && inputs.beta_iteration || '' }}
|
|
54
|
+
SEMANTIC_VERSION: ${{ github.event_name == 'workflow_dispatch' && inputs.semantic_version || '' }}
|
|
55
|
+
PRERELEASE_ID: ${{ github.event_name == 'workflow_dispatch' && inputs.prerelease || '' }}
|
|
56
|
+
run: |
|
|
57
|
+
python - <<'PY'
|
|
58
|
+
from pathlib import Path
|
|
59
|
+
import os
|
|
60
|
+
import re
|
|
61
|
+
import sys
|
|
62
|
+
|
|
63
|
+
pyproject = Path("pyproject.toml")
|
|
64
|
+
content = pyproject.read_text(encoding="utf-8")
|
|
65
|
+
|
|
66
|
+
match = re.search(r'^version\s*=\s*"(?P<version>[^"]+)"', content, flags=re.MULTILINE)
|
|
67
|
+
if not match:
|
|
68
|
+
sys.exit("Version not found in pyproject.toml")
|
|
69
|
+
|
|
70
|
+
semver_input = os.environ.get("SEMANTIC_VERSION", "").strip()
|
|
71
|
+
prerelease_input = os.environ.get("PRERELEASE_ID", "").strip().lower()
|
|
72
|
+
prerelease_map = {"alpha": "a", "beta": "b", "a": "a", "b": "b"}
|
|
73
|
+
if prerelease_input and prerelease_input not in prerelease_map:
|
|
74
|
+
sys.exit("Invalid prerelease identifier. Use 'alpha' or 'beta'.")
|
|
75
|
+
|
|
76
|
+
if semver_input:
|
|
77
|
+
if not re.fullmatch(r"\d+\.\d+\.\d+", semver_input):
|
|
78
|
+
sys.exit("Invalid semantic version. Use x.x.x format.")
|
|
79
|
+
base_version = semver_input
|
|
80
|
+
else:
|
|
81
|
+
base_version = match.group("version")
|
|
82
|
+
|
|
83
|
+
prerelease = prerelease_map.get(prerelease_input, "b")
|
|
84
|
+
iteration = os.environ.get("BETA_ITERATION") or os.environ.get("GITHUB_RUN_NUMBER")
|
|
85
|
+
beta_version = f"{base_version}{prerelease}{iteration}"
|
|
86
|
+
|
|
87
|
+
new_content = re.sub(
|
|
88
|
+
r'^version\s*=\s*".*"',
|
|
89
|
+
f'version = "{beta_version}"',
|
|
90
|
+
content,
|
|
91
|
+
count=1,
|
|
92
|
+
flags=re.MULTILINE,
|
|
93
|
+
)
|
|
94
|
+
pyproject.write_text(new_content, encoding="utf-8")
|
|
95
|
+
|
|
96
|
+
print(f"Publishing beta version {beta_version}")
|
|
97
|
+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
|
|
98
|
+
output.write(f"beta_version={beta_version}\n")
|
|
99
|
+
PY
|
|
100
|
+
|
|
101
|
+
- name: Build package
|
|
102
|
+
run: uv build
|
|
103
|
+
|
|
104
|
+
- name: Publish beta to PyPI
|
|
105
|
+
run: uv publish
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
pull-requests: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
release-please:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
environment: release
|
|
16
|
+
outputs:
|
|
17
|
+
release_created: ${{ steps.release-please.outputs.release_created }}
|
|
18
|
+
tag_name: ${{ steps.release-please.outputs.tag_name }}
|
|
19
|
+
steps:
|
|
20
|
+
- uses: googleapis/release-please-action@v4
|
|
21
|
+
id: release-please
|
|
22
|
+
with:
|
|
23
|
+
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
|
|
24
|
+
config-file: release-please-config.json
|
|
25
|
+
|
|
26
|
+
test:
|
|
27
|
+
uses: ./.github/workflows/test.yml
|
|
28
|
+
|
|
29
|
+
release:
|
|
30
|
+
runs-on: ubuntu-latest
|
|
31
|
+
environment: release
|
|
32
|
+
if: ${{ needs.release-please.outputs.release_created == 'true' }}
|
|
33
|
+
needs:
|
|
34
|
+
- release-please
|
|
35
|
+
- test
|
|
36
|
+
permissions:
|
|
37
|
+
id-token: write
|
|
38
|
+
contents: write
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v6
|
|
41
|
+
with:
|
|
42
|
+
fetch-depth: 0
|
|
43
|
+
|
|
44
|
+
- name: Install uv
|
|
45
|
+
uses: astral-sh/setup-uv@v7
|
|
46
|
+
|
|
47
|
+
- name: Set up Python
|
|
48
|
+
run: uv python install
|
|
49
|
+
|
|
50
|
+
- name: Build package
|
|
51
|
+
run: uv build
|
|
52
|
+
|
|
53
|
+
- name: Upload package to PyPI
|
|
54
|
+
run: uv publish
|
|
55
|
+
|
|
56
|
+
- name: Upload Release Artifacts
|
|
57
|
+
env:
|
|
58
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
59
|
+
run: |
|
|
60
|
+
for file in dist/*; do
|
|
61
|
+
gh release upload ${{ needs.release-please.outputs.tag_name }} "$file"
|
|
62
|
+
done
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
workflow_call: # Makes this workflow reusable
|
|
9
|
+
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ${{ github.head_ref || github.run_id }}
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
test:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
environment: test
|
|
18
|
+
strategy:
|
|
19
|
+
fail-fast: false
|
|
20
|
+
matrix:
|
|
21
|
+
python-version:
|
|
22
|
+
- "3.11"
|
|
23
|
+
- "3.12"
|
|
24
|
+
- "3.13"
|
|
25
|
+
- "3.14"
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v6
|
|
29
|
+
|
|
30
|
+
- name: Install uv and set the python version
|
|
31
|
+
uses: astral-sh/setup-uv@v7
|
|
32
|
+
with:
|
|
33
|
+
python-version: ${{ matrix.python-version }}
|
|
34
|
+
|
|
35
|
+
- name: Set up Python
|
|
36
|
+
run: uv python install
|
|
37
|
+
|
|
38
|
+
- name: Install the project
|
|
39
|
+
run: uv sync --all-extras --dev
|
|
40
|
+
|
|
41
|
+
- name: Run tests
|
|
42
|
+
run: uv run pytest tests
|
|
43
|
+
|
|
44
|
+
- name: Lint with Ruff
|
|
45
|
+
run: uv run ruff check . --output-format=github
|
|
46
|
+
|
|
47
|
+
- name: Type check with ty
|
|
48
|
+
run: uv run ty check . --output-format=github
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Background
|
|
2
|
+
|
|
3
|
+
sok-ble is a library written in Python. Its purpose is to connect to SOK LiFePO4 batteries over Bluetooth low energy and send and receive modbus commands. sok-ble then parses the responses and returns usable data. The primary intent is for sok-ble to be utilized/wrapped/consumed by sok-ha, a custom integration for Home Assistant; however, sok-ble may be used by any 3rd party and must remain independent of Home Assistant.
|
|
4
|
+
|
|
5
|
+
# Documentation
|
|
6
|
+
|
|
7
|
+
- Use Markdown for all documentation
|
|
8
|
+
- Place documentation in the `docs/` directory
|
|
9
|
+
|
|
10
|
+
# Code Style
|
|
11
|
+
|
|
12
|
+
- Add comments to code when it may be unclear what the code does or how it functions.
|
|
13
|
+
- Comments should be full sentences and end with a period.
|
|
14
|
+
- Maintainable and understandable code is preferred over complex code. Simplicity is the ultimate complexity!
|
|
15
|
+
|
|
16
|
+
# Python
|
|
17
|
+
|
|
18
|
+
- Use uv to manage Python and all python packages
|
|
19
|
+
- Use 'uv add [package_name]' instead of 'uv pip install [package_name]'
|
|
20
|
+
|
|
21
|
+
# Testing
|
|
22
|
+
|
|
23
|
+
- Use pytest for Python testing
|
|
24
|
+
- Ensure all code is formatted and linted with Ruff.
|
|
25
|
+
|
|
26
|
+
# Files
|
|
27
|
+
|
|
28
|
+
- Do not create binary files, such as Lambda zip files.
|
|
29
|
+
- Do not modify CHANGELOG.md. This is handled by CI.
|
|
30
|
+
|
|
31
|
+
# Commits
|
|
32
|
+
|
|
33
|
+
- Use conventional commits for all changes
|
|
34
|
+
- Prefix all commit messages with fix:; feat:; build:; chore:; ci:; docs:; style:; refactor:; perf:; or test: as appropriate.
|
|
35
|
+
|
|
36
|
+
# Before Checking In Code
|
|
37
|
+
|
|
38
|
+
- Fix all code formatting and quality issues in the entire codebase.
|
|
39
|
+
- Ensure all new code is covered by appropriate unit tests.
|
|
40
|
+
|
|
41
|
+
## Python
|
|
42
|
+
|
|
43
|
+
Fix all Python formatting and linting issues.
|
|
44
|
+
|
|
45
|
+
### Steps:
|
|
46
|
+
|
|
47
|
+
1. **Format with ruff**: `uv run ruff format .`
|
|
48
|
+
2. **Lint with ruff**: `uv run ruff check . --output-format=github`
|
|
49
|
+
3. **Type check with ty**: `uv run ty check . --output-format=github`
|
|
50
|
+
4. **Run unit tests**: `uv run pytest tests`
|
|
51
|
+
|
|
52
|
+
## General Process:
|
|
53
|
+
|
|
54
|
+
1. Run automated formatters first.
|
|
55
|
+
2. Fix remaining linting issues manually.
|
|
56
|
+
3. Resolve type checking errors.
|
|
57
|
+
4. Verify all tests pass with no errors.
|
|
58
|
+
5. Review changes before committing.
|
|
59
|
+
|
|
60
|
+
## Common Issues:
|
|
61
|
+
|
|
62
|
+
- Import order conflicts between tools
|
|
63
|
+
- Line length violations
|
|
64
|
+
- Unused imports/variables
|
|
65
|
+
- Type annotation requirements
|
|
66
|
+
- Missing return types
|
|
67
|
+
- Inconsistent quotes/semicolons
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## [0.1.9](https://github.com/IAmTheMitchell/sok-ble/compare/v0.1.8...v0.1.9) (2026-02-05)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### Documentation
|
|
8
|
+
|
|
9
|
+
* update AI directives ([afb9309](https://github.com/IAmTheMitchell/sok-ble/commit/afb9309eaa061d9087fc49f74593b1358810307a))
|
|
10
|
+
|
|
11
|
+
## [0.1.8](https://github.com/IAmTheMitchell/sok-ble/compare/v0.1.7...v0.1.8) (2025-08-03)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* fix release ([9257795](https://github.com/IAmTheMitchell/sok-ble/commit/9257795edaa5937371fd3870ae7434a468bbdca2))
|
|
17
|
+
* fix release ([25395a2](https://github.com/IAmTheMitchell/sok-ble/commit/25395a22d35d62516b5ddb5d1be5e944e654cf15))
|
|
18
|
+
|
|
19
|
+
## [0.1.7](https://github.com/IAmTheMitchell/sok-ble/compare/v0.1.6...v0.1.7) (2025-08-03)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* fix bleak import ([e413bb7](https://github.com/IAmTheMitchell/sok-ble/commit/e413bb75ad3e10a73dba08881829e76dc8358d2c))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Documentation
|
|
28
|
+
|
|
29
|
+
* update CI badges ([a3f4f24](https://github.com/IAmTheMitchell/sok-ble/commit/a3f4f2478dc96a8861820adce5b40eeab1bb581d))
|
|
30
|
+
|
|
4
31
|
## v0.1.6 (2025-07-13)
|
|
5
32
|
|
|
6
33
|
### Bug Fixes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sok-ble
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.9b2
|
|
4
4
|
Summary: SOK BLE battery interface library
|
|
5
5
|
Project-URL: Homepage, https://github.com/IAmTheMitchell/sok-ble
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/IAmTheMitchell/sok-ble/issues
|
|
@@ -19,7 +19,8 @@ Description-Content-Type: text/markdown
|
|
|
19
19
|
|
|
20
20
|
# SOK BLE
|
|
21
21
|
|
|
22
|
-

|
|
23
|
+

|
|
23
24
|
|
|
24
25
|
Python library for interacting with SOK Bluetooth-enabled batteries.
|
|
25
26
|
|
|
@@ -42,5 +43,6 @@ asyncio.run(main())
|
|
|
42
43
|
```
|
|
43
44
|
|
|
44
45
|
## References
|
|
46
|
+
|
|
45
47
|
[@zuccaro's comment](https://github.com/Louisvdw/dbus-serialbattery/issues/350#issuecomment-1500658941)
|
|
46
|
-
[Bluetooth-Devices/inkbird-ble](https://github.com/Bluetooth-Devices/inkbird-ble)
|
|
48
|
+
[Bluetooth-Devices/inkbird-ble](https://github.com/Bluetooth-Devices/inkbird-ble)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# SOK BLE
|
|
2
2
|
|
|
3
|
-

|
|
4
|
+

|
|
4
5
|
|
|
5
6
|
Python library for interacting with SOK Bluetooth-enabled batteries.
|
|
6
7
|
|
|
@@ -23,5 +24,6 @@ asyncio.run(main())
|
|
|
23
24
|
```
|
|
24
25
|
|
|
25
26
|
## References
|
|
27
|
+
|
|
26
28
|
[@zuccaro's comment](https://github.com/Louisvdw/dbus-serialbattery/issues/350#issuecomment-1500658941)
|
|
27
|
-
[Bluetooth-Devices/inkbird-ble](https://github.com/Bluetooth-Devices/inkbird-ble)
|
|
29
|
+
[Bluetooth-Devices/inkbird-ble](https://github.com/Bluetooth-Devices/inkbird-ble)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sok-ble"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.9b2"
|
|
4
4
|
description = "SOK BLE battery interface library"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|
|
@@ -24,6 +24,7 @@ dev = [
|
|
|
24
24
|
"pytest>=7.0.1",
|
|
25
25
|
"pytest-asyncio>=1.0.0",
|
|
26
26
|
"ruff>=0.12.3",
|
|
27
|
+
"ty>=0.0.15",
|
|
27
28
|
]
|
|
28
29
|
|
|
29
30
|
[project.urls]
|
|
@@ -35,10 +36,6 @@ dev = [
|
|
|
35
36
|
requires = ["hatchling"]
|
|
36
37
|
build-backend = "hatchling.build"
|
|
37
38
|
|
|
38
|
-
[tool.semantic_release]
|
|
39
|
-
branch = "main"
|
|
40
|
-
version_toml = ["pyproject.toml:project.version"]
|
|
41
|
-
|
|
42
39
|
[tool.ruff]
|
|
43
40
|
line-length = 88
|
|
44
41
|
target-version = "py311"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"packages": {
|
|
3
|
+
".": {
|
|
4
|
+
"changelog-path": "CHANGELOG.md",
|
|
5
|
+
"release-type": "python",
|
|
6
|
+
"include-v-in-tag": true,
|
|
7
|
+
"bump-minor-pre-major": true,
|
|
8
|
+
"bump-patch-for-minor-pre-major": false,
|
|
9
|
+
"draft": false,
|
|
10
|
+
"prerelease": false
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
|
|
14
|
+
}
|
|
@@ -10,8 +10,9 @@ from contextlib import asynccontextmanager
|
|
|
10
10
|
from typing import AsyncIterator, Optional
|
|
11
11
|
|
|
12
12
|
import async_timeout
|
|
13
|
-
from bleak import
|
|
13
|
+
from bleak.backends.characteristic import BleakGATTCharacteristic
|
|
14
14
|
from bleak.backends.device import BLEDevice
|
|
15
|
+
from bleak.exc import BleakError
|
|
15
16
|
|
|
16
17
|
from sok_ble.const import UUID_RX, UUID_TX, _sok_command
|
|
17
18
|
from sok_ble.exceptions import BLEConnectionError
|
|
@@ -114,7 +115,7 @@ class SokBluetoothDevice:
|
|
|
114
115
|
|
|
115
116
|
queue: asyncio.Queue[bytes] = asyncio.Queue()
|
|
116
117
|
|
|
117
|
-
def handler(_:
|
|
118
|
+
def handler(_: BleakGATTCharacteristic, data: bytearray) -> None:
|
|
118
119
|
queue.put_nowait(bytes(data))
|
|
119
120
|
|
|
120
121
|
await client.start_notify(UUID_RX, handler)
|
|
@@ -136,6 +137,10 @@ class SokBluetoothDevice:
|
|
|
136
137
|
await asyncio.sleep(0.2)
|
|
137
138
|
continue
|
|
138
139
|
raise
|
|
140
|
+
raise BleakError(
|
|
141
|
+
f"Failed to receive response 0x{expected:04X} "
|
|
142
|
+
f"from {self._ble_device.address}"
|
|
143
|
+
)
|
|
139
144
|
|
|
140
145
|
async def async_update(self) -> None:
|
|
141
146
|
"""Poll the device for all telemetry and update attributes."""
|
|
@@ -180,13 +185,30 @@ class SokBluetoothDevice:
|
|
|
180
185
|
parsed = SokParser.parse_all(responses)
|
|
181
186
|
logger.debug("Parsed update: %s", parsed)
|
|
182
187
|
|
|
183
|
-
|
|
184
|
-
self.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
self.
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
voltage = parsed.get("voltage")
|
|
189
|
+
self.voltage = voltage if isinstance(voltage, (int, float)) else None
|
|
190
|
+
|
|
191
|
+
current = parsed.get("current")
|
|
192
|
+
self.current = current if isinstance(current, (int, float)) else None
|
|
193
|
+
|
|
194
|
+
soc = parsed.get("soc")
|
|
195
|
+
self.soc = soc if isinstance(soc, int) else None
|
|
196
|
+
|
|
197
|
+
temperature = parsed.get("temperature")
|
|
198
|
+
self.temperature = (
|
|
199
|
+
temperature if isinstance(temperature, (int, float)) else None
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
capacity = parsed.get("capacity")
|
|
203
|
+
self.capacity = capacity if isinstance(capacity, (int, float)) else None
|
|
204
|
+
|
|
205
|
+
num_cycles = parsed.get("num_cycles")
|
|
206
|
+
self.num_cycles = num_cycles if isinstance(num_cycles, int) else None
|
|
207
|
+
|
|
208
|
+
cell_voltages = parsed.get("cell_voltages")
|
|
209
|
+
self.cell_voltages = (
|
|
210
|
+
list(cell_voltages) if isinstance(cell_voltages, list) else None
|
|
211
|
+
)
|
|
190
212
|
|
|
191
213
|
self.num_samples += 1
|
|
192
214
|
|
|
@@ -14,19 +14,20 @@ logger = logging.getLogger(__name__)
|
|
|
14
14
|
|
|
15
15
|
# Endian helper functions copied from the reference addon
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
def get_le_short(data: Sequence[int] | bytes | bytearray, offset: int) -> int:
|
|
18
19
|
"""Read a little-endian signed short."""
|
|
19
|
-
return struct.unpack_from(
|
|
20
|
+
return struct.unpack_from("<h", bytes(data), offset)[0]
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
def get_le_ushort(data: Sequence[int] | bytes | bytearray, offset: int) -> int:
|
|
23
24
|
"""Read a little-endian unsigned short."""
|
|
24
|
-
return struct.unpack_from(
|
|
25
|
+
return struct.unpack_from("<H", bytes(data), offset)[0]
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
def get_le_int3(data: Sequence[int] | bytes | bytearray, offset: int) -> int:
|
|
28
29
|
"""Read a 3-byte little-endian signed integer."""
|
|
29
|
-
b0, b1, b2 = bytes(data)[offset:offset + 3]
|
|
30
|
+
b0, b1, b2 = bytes(data)[offset : offset + 3]
|
|
30
31
|
val = b0 | (b1 << 8) | (b2 << 16)
|
|
31
32
|
if val & 0x800000:
|
|
32
33
|
val -= 0x1000000
|
|
@@ -35,7 +36,7 @@ def get_le_int3(data: Sequence[int] | bytes | bytearray, offset: int) -> int:
|
|
|
35
36
|
|
|
36
37
|
def get_be_uint3(data: Sequence[int] | bytes | bytearray, offset: int) -> int:
|
|
37
38
|
"""Read a 3-byte big-endian unsigned integer."""
|
|
38
|
-
b0, b1, b2 = bytes(data)[offset:offset + 3]
|
|
39
|
+
b0, b1, b2 = bytes(data)[offset : offset + 3]
|
|
39
40
|
return (b0 << 16) | (b1 << 8) | b2
|
|
40
41
|
|
|
41
42
|
|
|
@@ -4,18 +4,10 @@ from sok_ble.sok_parser import SokParser
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def test_parse_all():
|
|
7
|
-
info_buf = bytes.fromhex(
|
|
8
|
-
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
"ccf2000000140000000000000000000000000000"
|
|
12
|
-
)
|
|
13
|
-
cap_buf = bytes.fromhex(
|
|
14
|
-
"ccf3000000003200000000000000000000000000"
|
|
15
|
-
)
|
|
16
|
-
cell_buf = bytes.fromhex(
|
|
17
|
-
"ccf401c50c0002c60c0003bf0c0004c00c000000"
|
|
18
|
-
)
|
|
7
|
+
info_buf = bytes.fromhex("ccf0000000102700000000000000320041000000")
|
|
8
|
+
temp_buf = bytes.fromhex("ccf2000000140000000000000000000000000000")
|
|
9
|
+
cap_buf = bytes.fromhex("ccf3000000003200000000000000000000000000")
|
|
10
|
+
cell_buf = bytes.fromhex("ccf401c50c0002c60c0003bf0c0004c00c000000")
|
|
19
11
|
|
|
20
12
|
responses = {
|
|
21
13
|
0xCCF0: info_buf,
|
|
@@ -34,4 +26,3 @@ def test_parse_all():
|
|
|
34
26
|
"num_cycles": 50,
|
|
35
27
|
"cell_voltages": [3.269, 3.27, 3.263, 3.264],
|
|
36
28
|
}
|
|
37
|
-
|
|
@@ -2,9 +2,7 @@ from sok_ble.sok_parser import SokParser
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
def test_parse_info_basic():
|
|
5
|
-
hex_data = bytes.fromhex(
|
|
6
|
-
"ccf0000000102700000000000000320041000000"
|
|
7
|
-
)
|
|
5
|
+
hex_data = bytes.fromhex("ccf0000000102700000000000000320041000000")
|
|
8
6
|
result = SokParser.parse_info(hex_data)
|
|
9
7
|
assert result == {
|
|
10
8
|
"current": 10.0,
|