okokscale 0.0.1__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.
- okokscale-0.0.1/.github/FUNDING.yml +14 -0
- okokscale-0.0.1/.github/dependabot.yml +15 -0
- okokscale-0.0.1/.github/workflows/check-format.yml +20 -0
- okokscale-0.0.1/.github/workflows/pypi-publish.yml +29 -0
- okokscale-0.0.1/.github/workflows/stale.yaml +44 -0
- okokscale-0.0.1/.gitignore +1 -0
- okokscale-0.0.1/LICENSE +201 -0
- okokscale-0.0.1/PKG-INFO +93 -0
- okokscale-0.0.1/README.md +75 -0
- okokscale-0.0.1/okokscale/__init__.py +3 -0
- okokscale-0.0.1/okokscale/_version.py +24 -0
- okokscale-0.0.1/okokscale/parser.py +455 -0
- okokscale-0.0.1/okokscale/py.typed +0 -0
- okokscale-0.0.1/pyproject.toml +54 -0
- okokscale-0.0.1/requirements.txt +2 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# These are supported funding model platforms
|
|
2
|
+
|
|
3
|
+
github: [rrooggiieerr]
|
|
4
|
+
patreon: seekingtheedge
|
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
|
6
|
+
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
+
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
|
12
|
+
polar: # Replace with a single Polar username
|
|
13
|
+
buy_me_a_coffee: rrooggiieerr
|
|
14
|
+
custom: ['https://paypal.me/seekingtheedge']
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: "pip" # See documentation for possible values
|
|
9
|
+
directory: "/" # Location of package manifests
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "weekly"
|
|
12
|
+
- package-ecosystem: "github-actions"
|
|
13
|
+
directory: "/"
|
|
14
|
+
schedule:
|
|
15
|
+
interval: "weekly"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: Check Python code format
|
|
2
|
+
|
|
3
|
+
on: [push]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
linter_name:
|
|
7
|
+
name: runner / isort & black formatter
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v7
|
|
11
|
+
- name: Check files using the isort import sorter
|
|
12
|
+
uses: isort/isort-action@v1
|
|
13
|
+
with:
|
|
14
|
+
configuration: "--profile black --check-only"
|
|
15
|
+
requirements-files: "requirements.txt"
|
|
16
|
+
- name: Check files using the black formatter
|
|
17
|
+
uses: psf/black@stable
|
|
18
|
+
with:
|
|
19
|
+
options: "--check"
|
|
20
|
+
src: "."
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
deploy:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
id-token: write # required for OIDC
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v7
|
|
16
|
+
- name: Set up Python
|
|
17
|
+
uses: actions/setup-python@v6
|
|
18
|
+
with:
|
|
19
|
+
python-version: '3.x'
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: |
|
|
22
|
+
python -m pip install --upgrade pip
|
|
23
|
+
pip install build
|
|
24
|
+
- name: Build package
|
|
25
|
+
run: python -m build
|
|
26
|
+
- name: Publish package
|
|
27
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
28
|
+
with:
|
|
29
|
+
print-hash: true
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Stale
|
|
3
|
+
|
|
4
|
+
# yamllint disable-line rule:truthy
|
|
5
|
+
on:
|
|
6
|
+
schedule:
|
|
7
|
+
- cron: "0 8 * * *"
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
stale:
|
|
12
|
+
name: 🧹 Clean up stale issues and PRs
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
actions: write
|
|
16
|
+
issues: write
|
|
17
|
+
pull-requests: write
|
|
18
|
+
steps:
|
|
19
|
+
- name: 🚀 Run stale
|
|
20
|
+
uses: actions/stale@v10.3.0
|
|
21
|
+
with:
|
|
22
|
+
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
23
|
+
days-before-stale: 30
|
|
24
|
+
days-before-close: 7
|
|
25
|
+
remove-stale-when-updated: true
|
|
26
|
+
stale-issue-label: "stale"
|
|
27
|
+
exempt-issue-labels: "no-stale,help-wanted"
|
|
28
|
+
stale-issue-message: >
|
|
29
|
+
There hasn't been any activity on this issue recently, so we
|
|
30
|
+
clean up some of the older and inactive issues.
|
|
31
|
+
|
|
32
|
+
Please make sure to update to the latest version and
|
|
33
|
+
check if that solves the issue. Let us know if that works for you
|
|
34
|
+
by leaving a comment 👍
|
|
35
|
+
|
|
36
|
+
This issue has now been marked as stale and will be closed if no
|
|
37
|
+
further activity occurs. Thanks!
|
|
38
|
+
stale-pr-label: "stale"
|
|
39
|
+
exempt-pr-labels: "no-stale"
|
|
40
|
+
stale-pr-message: >
|
|
41
|
+
There hasn't been any activity on this pull request recently. This
|
|
42
|
+
pull request has been automatically marked as stale because of that
|
|
43
|
+
and will be closed if no further activity occurs within 7 days.
|
|
44
|
+
Thank you for your contributions.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*/_version.py
|
okokscale-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
okokscale-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: okokscale
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Library for parsing OKOK scale BLE advertisements.
|
|
5
|
+
Project-URL: Homepage, https://github.com/rrooggiieerr/okokscale.py
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/rrooggiieerr/okokscale.py/issues
|
|
7
|
+
Author-email: Rogier van Staveren <rogier@batoid.com>
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Requires-Dist: bleak>=3.0.2
|
|
16
|
+
Requires-Dist: bluetooth-sensor-state-data==1.9.0
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# Python library for parsing OKOK scale BLE advertisements.
|
|
20
|
+
|
|
21
|
+
![Python][python-shield]
|
|
22
|
+
[![GitHub Release][releases-shield]][releases]
|
|
23
|
+
[![Licence][license-shield]][license]
|
|
24
|
+
[![Maintainer][maintainer-shield]][maintainer]
|
|
25
|
+
[![GitHub Sponsors][github-shield]][github]
|
|
26
|
+
[![PayPal][paypal-shield]][paypal]
|
|
27
|
+
[![BuyMeCoffee][buymecoffee-shield]][buymecoffee]
|
|
28
|
+
[![Patreon][patreon-shield]][patreon]
|
|
29
|
+
|
|
30
|
+
## Introduction
|
|
31
|
+
|
|
32
|
+
A Python library for parsing the BLE advertisements of OKOK scales which can be used with the
|
|
33
|
+
*OKOK international* app and identify themselves on Bluetooth as *Chipsea-BLE*.
|
|
34
|
+
|
|
35
|
+
## Supported scales
|
|
36
|
+
|
|
37
|
+
The following scale is known to work:
|
|
38
|
+
|
|
39
|
+
* Tristar WG-2440
|
|
40
|
+
|
|
41
|
+
Please let me know if your scale works with this library so I can improve the overview of supported
|
|
42
|
+
scales.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
To install the Python OKOK scale library use the Package Installer for Python PIP:
|
|
47
|
+
|
|
48
|
+
`pip3 install okokscale`
|
|
49
|
+
|
|
50
|
+
## Contribution and appreciation
|
|
51
|
+
|
|
52
|
+
Do you enjoy using this Python library? You can contribute or show your appreciation, in the
|
|
53
|
+
following ways.
|
|
54
|
+
|
|
55
|
+
### Contribute your scale brand and model
|
|
56
|
+
|
|
57
|
+
Is your scale supported by this Python library but not listed under *Supported scales*? Let me know
|
|
58
|
+
your scale brand and model so I can improve the overview of supported scales.
|
|
59
|
+
|
|
60
|
+
### Star this GitHub page
|
|
61
|
+
Help other OKOK scale users find this Python library by starring this GitHub page. Click ⭐ Star on
|
|
62
|
+
the top right of the GitHub page.
|
|
63
|
+
|
|
64
|
+
### Support my work
|
|
65
|
+
|
|
66
|
+
Please consider supporting my work through one of the following platforms. Your contribution is
|
|
67
|
+
greatly appreciated and keeps me motivated:
|
|
68
|
+
|
|
69
|
+
[![GitHub Sponsors][github-shield]][github]
|
|
70
|
+
[![PayPal][paypal-shield]][paypal]
|
|
71
|
+
[![BuyMeCoffee][buymecoffee-shield]][buymecoffee]
|
|
72
|
+
[![Patreon][patreon-shield]][patreon]
|
|
73
|
+
|
|
74
|
+
### Hire me
|
|
75
|
+
|
|
76
|
+
If you're in need for a freelance Python developer for your project please contact me, you can find
|
|
77
|
+
my email address on [my GitHub profile](https://github.com/rrooggiieerr).
|
|
78
|
+
|
|
79
|
+
[python-shield]: https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54
|
|
80
|
+
[releases]: https://github.com/rrooggiieerr/okokscale.py/releases
|
|
81
|
+
[releases-shield]: https://img.shields.io/github/v/release/rrooggiieerr/okokscale.py?style=for-the-badge
|
|
82
|
+
[license]: ./LICENSE
|
|
83
|
+
[license-shield]: https://img.shields.io/github/license/rrooggiieerr/okokscale.py?style=for-the-badge
|
|
84
|
+
[maintainer]: https://github.com/rrooggiieerr
|
|
85
|
+
[maintainer-shield]: https://img.shields.io/badge/MAINTAINER-%40rrooggiieerr-41BDF5?style=for-the-badge
|
|
86
|
+
[paypal]: https://paypal.me/seekingtheedge
|
|
87
|
+
[paypal-shield]: https://img.shields.io/badge/PayPal-00457C?style=for-the-badge&logo=paypal&logoColor=white
|
|
88
|
+
[buymecoffee]: https://www.buymeacoffee.com/rrooggiieerr
|
|
89
|
+
[buymecoffee-shield]: https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black
|
|
90
|
+
[github]: https://github.com/sponsors/rrooggiieerr
|
|
91
|
+
[github-shield]: https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=ea4aaa
|
|
92
|
+
[patreon]: https://www.patreon.com/seekingtheedge/creators
|
|
93
|
+
[patreon-shield]: https://img.shields.io/badge/Patreon-F96854?style=for-the-badge&logo=patreon&logoColor=white
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Python library for parsing OKOK scale BLE advertisements.
|
|
2
|
+
|
|
3
|
+
![Python][python-shield]
|
|
4
|
+
[![GitHub Release][releases-shield]][releases]
|
|
5
|
+
[![Licence][license-shield]][license]
|
|
6
|
+
[![Maintainer][maintainer-shield]][maintainer]
|
|
7
|
+
[![GitHub Sponsors][github-shield]][github]
|
|
8
|
+
[![PayPal][paypal-shield]][paypal]
|
|
9
|
+
[![BuyMeCoffee][buymecoffee-shield]][buymecoffee]
|
|
10
|
+
[![Patreon][patreon-shield]][patreon]
|
|
11
|
+
|
|
12
|
+
## Introduction
|
|
13
|
+
|
|
14
|
+
A Python library for parsing the BLE advertisements of OKOK scales which can be used with the
|
|
15
|
+
*OKOK international* app and identify themselves on Bluetooth as *Chipsea-BLE*.
|
|
16
|
+
|
|
17
|
+
## Supported scales
|
|
18
|
+
|
|
19
|
+
The following scale is known to work:
|
|
20
|
+
|
|
21
|
+
* Tristar WG-2440
|
|
22
|
+
|
|
23
|
+
Please let me know if your scale works with this library so I can improve the overview of supported
|
|
24
|
+
scales.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
To install the Python OKOK scale library use the Package Installer for Python PIP:
|
|
29
|
+
|
|
30
|
+
`pip3 install okokscale`
|
|
31
|
+
|
|
32
|
+
## Contribution and appreciation
|
|
33
|
+
|
|
34
|
+
Do you enjoy using this Python library? You can contribute or show your appreciation, in the
|
|
35
|
+
following ways.
|
|
36
|
+
|
|
37
|
+
### Contribute your scale brand and model
|
|
38
|
+
|
|
39
|
+
Is your scale supported by this Python library but not listed under *Supported scales*? Let me know
|
|
40
|
+
your scale brand and model so I can improve the overview of supported scales.
|
|
41
|
+
|
|
42
|
+
### Star this GitHub page
|
|
43
|
+
Help other OKOK scale users find this Python library by starring this GitHub page. Click ⭐ Star on
|
|
44
|
+
the top right of the GitHub page.
|
|
45
|
+
|
|
46
|
+
### Support my work
|
|
47
|
+
|
|
48
|
+
Please consider supporting my work through one of the following platforms. Your contribution is
|
|
49
|
+
greatly appreciated and keeps me motivated:
|
|
50
|
+
|
|
51
|
+
[![GitHub Sponsors][github-shield]][github]
|
|
52
|
+
[![PayPal][paypal-shield]][paypal]
|
|
53
|
+
[![BuyMeCoffee][buymecoffee-shield]][buymecoffee]
|
|
54
|
+
[![Patreon][patreon-shield]][patreon]
|
|
55
|
+
|
|
56
|
+
### Hire me
|
|
57
|
+
|
|
58
|
+
If you're in need for a freelance Python developer for your project please contact me, you can find
|
|
59
|
+
my email address on [my GitHub profile](https://github.com/rrooggiieerr).
|
|
60
|
+
|
|
61
|
+
[python-shield]: https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54
|
|
62
|
+
[releases]: https://github.com/rrooggiieerr/okokscale.py/releases
|
|
63
|
+
[releases-shield]: https://img.shields.io/github/v/release/rrooggiieerr/okokscale.py?style=for-the-badge
|
|
64
|
+
[license]: ./LICENSE
|
|
65
|
+
[license-shield]: https://img.shields.io/github/license/rrooggiieerr/okokscale.py?style=for-the-badge
|
|
66
|
+
[maintainer]: https://github.com/rrooggiieerr
|
|
67
|
+
[maintainer-shield]: https://img.shields.io/badge/MAINTAINER-%40rrooggiieerr-41BDF5?style=for-the-badge
|
|
68
|
+
[paypal]: https://paypal.me/seekingtheedge
|
|
69
|
+
[paypal-shield]: https://img.shields.io/badge/PayPal-00457C?style=for-the-badge&logo=paypal&logoColor=white
|
|
70
|
+
[buymecoffee]: https://www.buymeacoffee.com/rrooggiieerr
|
|
71
|
+
[buymecoffee-shield]: https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black
|
|
72
|
+
[github]: https://github.com/sponsors/rrooggiieerr
|
|
73
|
+
[github-shield]: https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=ea4aaa
|
|
74
|
+
[patreon]: https://www.patreon.com/seekingtheedge/creators
|
|
75
|
+
[patreon-shield]: https://img.shields.io/badge/Patreon-F96854?style=for-the-badge&logo=patreon&logoColor=white
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '0.0.1'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 0, 1)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Parser for OKOK scale BLE advertisements.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
from bleak import AdvertisementData, BleakClient, BLEDevice
|
|
8
|
+
from bleak_retry_connector import BleakClientWithServiceCache, establish_connection
|
|
9
|
+
from bluetooth_data_tools import human_readable_name
|
|
10
|
+
from bluetooth_sensor_state_data import BluetoothData
|
|
11
|
+
from home_assistant_bluetooth import BluetoothServiceInfo
|
|
12
|
+
from sensor_state_data import SensorDeviceClass, SensorLibrary, SensorUpdate, Units
|
|
13
|
+
|
|
14
|
+
UPDATE_INTERVAL_SECONDS = 60 * 60 * 24 # 1 day
|
|
15
|
+
|
|
16
|
+
_LOGGER = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# "00002a29-0000-1000-8000-00805f9b34fb" #(Handle: 11): Manufacturer Name String
|
|
20
|
+
CHARACTERISTIC_MODEL_NUMBER = (
|
|
21
|
+
"00002a24-0000-1000-8000-00805f9b34fb" # (Handle: 13): Model Number String
|
|
22
|
+
)
|
|
23
|
+
# "00002a25-0000-1000-8000-00805f9b34fb" #(Handle: 15): Serial Number String
|
|
24
|
+
# "00002a26-0000-1000-8000-00805f9b34fb" #(Handle: 17): Firmware Revision String
|
|
25
|
+
# "00002a27-0000-1000-8000-00805f9b34fb" #(Handle: 19): Hardware Revision String
|
|
26
|
+
# "0000fff1-0000-1000-8000-00805f9b34fb" #(Handle: 22): Vendor specific
|
|
27
|
+
# "0000fff2-0000-1000-8000-00805f9b34fb" #(Handle: 25): Vendor specific
|
|
28
|
+
CHARACTERISTIC_BODY_COMPOSITION = (
|
|
29
|
+
"00002a9c-0000-1000-8000-00805f9b34fb" # (Handle: 28): Body Composition Measurement
|
|
30
|
+
)
|
|
31
|
+
# "0000fa9c-0000-1000-8000-00805f9b34fb" #(Handle: 31): Vendor specific
|
|
32
|
+
CHARACTERISTIC_BATTERY_LEVEL = (
|
|
33
|
+
"00002a19-0000-1000-8000-00805f9b34fb" # (Handle: 35): Battery Level
|
|
34
|
+
)
|
|
35
|
+
# "00002a08-0000-1000-8000-00805f9b34fb" #(Handle: 39): Date Time
|
|
36
|
+
# "0000faa1-0000-1000-8000-00805f9b34fb" #(Handle: 43): Vendor specific
|
|
37
|
+
# "0000faa2-0000-1000-8000-00805f9b34fb" #(Handle: 45): Vendor specific
|
|
38
|
+
|
|
39
|
+
MANUFACTURER_DATA_ID_V10 = 0x10FF # 16-bit little endian "header" 0xff 0x10
|
|
40
|
+
MANUFACTURER_DATA_ID_V11 = 0x11CA # 16-bit little endian "header" 0xca 0x11
|
|
41
|
+
MANUFACTURER_DATA_ID_V20 = 0x20CA # 16-bit little endian "header" 0xca 0x20
|
|
42
|
+
MANUFACTURER_DATA_ID_V26 = 0x26C0 # 16-bit little endian "header" 0xc0 0x26
|
|
43
|
+
MANUFACTURER_DATA_ID_VC0 = 0xC0 # 8-bit little endian "header" 0xc0
|
|
44
|
+
MANUFACTURER_DATA_ID_VF0 = 0xF0FF # 16-bit little endian "header" 0xff 0xf0
|
|
45
|
+
|
|
46
|
+
IDX_V10_WEIGHT_MSB = 3
|
|
47
|
+
IDX_V10_WEIGHT_LSB = 2
|
|
48
|
+
|
|
49
|
+
IDX_V11_FINAL = 1
|
|
50
|
+
IDX_V11_WEIGHT_MSB = 3
|
|
51
|
+
IDX_V11_WEIGHT_LSB = 4
|
|
52
|
+
IDX_V11_BODY_PROPERTIES = 9
|
|
53
|
+
IDX_V11_CHECKSUM = 16
|
|
54
|
+
|
|
55
|
+
IDX_V20_FINAL = 6
|
|
56
|
+
IDX_V20_WEIGHT_MSB = 8
|
|
57
|
+
IDX_V20_WEIGHT_LSB = 9
|
|
58
|
+
IDX_V20_IMPEDANCE_MSB = 10
|
|
59
|
+
IDX_V20_IMPEDANCE_LSB = 11
|
|
60
|
+
IDX_V20_CHECKSUM = 12
|
|
61
|
+
|
|
62
|
+
IDX_V26_WEIGHT_MSB = 3
|
|
63
|
+
IDX_V26_WEIGHT_LSB = 2
|
|
64
|
+
|
|
65
|
+
IDX_VC0_FINAL = 6
|
|
66
|
+
IDX_VC0_WEIGHT_MSB = 0
|
|
67
|
+
IDX_VC0_WEIGHT_LSB = 1
|
|
68
|
+
IDX_VC0_BODY_PROPERTIES = 6
|
|
69
|
+
|
|
70
|
+
IDX_VF0_WEIGHT_MSB = 3
|
|
71
|
+
IDX_VF0_WEIGHT_LSB = 2
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class OKOKScaleBluetoothDeviceData(BluetoothData):
|
|
75
|
+
"""Data for OKOK Scale sensors."""
|
|
76
|
+
|
|
77
|
+
name = None
|
|
78
|
+
|
|
79
|
+
_device = None
|
|
80
|
+
_client = None
|
|
81
|
+
_expected_disconnect = False
|
|
82
|
+
|
|
83
|
+
supports_impedance = False
|
|
84
|
+
|
|
85
|
+
def _start_update(self, service_info: BluetoothServiceInfo) -> None:
|
|
86
|
+
"""Update from BLE advertisement data."""
|
|
87
|
+
if _LOGGER.isEnabledFor(logging.DEBUG):
|
|
88
|
+
self.log_service_info(service_info)
|
|
89
|
+
|
|
90
|
+
manufacturer_data_key_lsbs = [
|
|
91
|
+
key & 0xFF for key in service_info.manufacturer_data
|
|
92
|
+
]
|
|
93
|
+
if not (
|
|
94
|
+
MANUFACTURER_DATA_ID_V10 in service_info.manufacturer_data
|
|
95
|
+
or MANUFACTURER_DATA_ID_V11 in service_info.manufacturer_data
|
|
96
|
+
or MANUFACTURER_DATA_ID_V20 in service_info.manufacturer_data
|
|
97
|
+
or MANUFACTURER_DATA_ID_V26 in service_info.manufacturer_data
|
|
98
|
+
or MANUFACTURER_DATA_ID_VF0 in service_info.manufacturer_data
|
|
99
|
+
or MANUFACTURER_DATA_ID_VC0 in manufacturer_data_key_lsbs
|
|
100
|
+
):
|
|
101
|
+
_LOGGER.info(
|
|
102
|
+
"Manufacturer data not found for %s; ids=%s",
|
|
103
|
+
service_info.address,
|
|
104
|
+
list(service_info.manufacturer_data.keys()),
|
|
105
|
+
)
|
|
106
|
+
return
|
|
107
|
+
|
|
108
|
+
self.set_device_manufacturer("OKOK")
|
|
109
|
+
self.set_device_type("OKOK Scale")
|
|
110
|
+
self.name = human_readable_name(
|
|
111
|
+
"OKOK Scale", service_info.name, service_info.address
|
|
112
|
+
)
|
|
113
|
+
self.set_device_name(self.name)
|
|
114
|
+
self.set_title(self.name)
|
|
115
|
+
|
|
116
|
+
self.process_manufacturer_data(service_info.manufacturer_data)
|
|
117
|
+
|
|
118
|
+
self.update_signal_strength(service_info.rssi)
|
|
119
|
+
|
|
120
|
+
def poll_needed(
|
|
121
|
+
self, service_info: BluetoothServiceInfo, last_poll: float | None
|
|
122
|
+
) -> bool:
|
|
123
|
+
"""
|
|
124
|
+
This is called every time we get a service_info for a device. It means the
|
|
125
|
+
device is working and online.
|
|
126
|
+
"""
|
|
127
|
+
if last_poll is None or self.supports_impedance:
|
|
128
|
+
return True
|
|
129
|
+
return last_poll > UPDATE_INTERVAL_SECONDS
|
|
130
|
+
|
|
131
|
+
async def connect(self, ble_device: BLEDevice):
|
|
132
|
+
if self._client and self._client.is_connected:
|
|
133
|
+
_LOGGER.debug("Already connected to %s", self.name)
|
|
134
|
+
return self._client
|
|
135
|
+
|
|
136
|
+
# Connecting with the scale
|
|
137
|
+
self._device = ble_device
|
|
138
|
+
_LOGGER.info("Connecting to %s", self.name)
|
|
139
|
+
client: BleakClient = await establish_connection(
|
|
140
|
+
BleakClientWithServiceCache,
|
|
141
|
+
ble_device,
|
|
142
|
+
self.name,
|
|
143
|
+
self._disconnected,
|
|
144
|
+
use_services_cache=True,
|
|
145
|
+
ble_device_callback=lambda: self._device,
|
|
146
|
+
)
|
|
147
|
+
self._client = client
|
|
148
|
+
|
|
149
|
+
return client
|
|
150
|
+
|
|
151
|
+
async def disconnect(self):
|
|
152
|
+
if self._client and self._client.is_connected:
|
|
153
|
+
self._expected_disconnect = True
|
|
154
|
+
await self._client.disconnect()
|
|
155
|
+
|
|
156
|
+
def _disconnected(self, client: BleakClientWithServiceCache) -> None:
|
|
157
|
+
"""Disconnected callback."""
|
|
158
|
+
if self._expected_disconnect:
|
|
159
|
+
_LOGGER.debug("%s: Disconnected from device", self.get_device_name())
|
|
160
|
+
return
|
|
161
|
+
|
|
162
|
+
_LOGGER.warning("%s: Device unexpectedly disconnected", self.get_device_name())
|
|
163
|
+
|
|
164
|
+
async def async_poll(
|
|
165
|
+
self, ble_device: BLEDevice, advertisement_data: AdvertisementData
|
|
166
|
+
) -> SensorUpdate:
|
|
167
|
+
"""
|
|
168
|
+
Poll the device to retrieve any values we can't get from passive listening.
|
|
169
|
+
"""
|
|
170
|
+
try:
|
|
171
|
+
client = await self.connect(ble_device)
|
|
172
|
+
if _LOGGER.isEnabledFor(logging.DEBUG):
|
|
173
|
+
await self.log_client(client)
|
|
174
|
+
|
|
175
|
+
body_composition_char = client.services.get_characteristic(
|
|
176
|
+
CHARACTERISTIC_BODY_COMPOSITION
|
|
177
|
+
)
|
|
178
|
+
if body_composition_char:
|
|
179
|
+
self.supports_impedance = True
|
|
180
|
+
|
|
181
|
+
body_composition_payload = await client.read_gatt_char(
|
|
182
|
+
body_composition_char
|
|
183
|
+
)
|
|
184
|
+
_LOGGER.debug(
|
|
185
|
+
"Body Composition Payload: 0x%s", body_composition_payload.hex()
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
control_bytes = (
|
|
189
|
+
body_composition_payload[1] << 8
|
|
190
|
+
) + body_composition_payload[0]
|
|
191
|
+
partial = (control_bytes & 1024) > 0
|
|
192
|
+
in_pounds = (control_bytes & 256) > 0
|
|
193
|
+
finished = (control_bytes & 128) > 0
|
|
194
|
+
in_jin = (control_bytes & 64) > 0
|
|
195
|
+
weight_stabilized = (control_bytes & 32) > 0
|
|
196
|
+
impedance_stabilized = (control_bytes & 2) > 0
|
|
197
|
+
|
|
198
|
+
weight = (
|
|
199
|
+
(body_composition_payload[12] << 8) + body_composition_payload[11]
|
|
200
|
+
) / 10
|
|
201
|
+
_LOGGER.debug("Weight: %.2f kg", weight)
|
|
202
|
+
|
|
203
|
+
impedance = (
|
|
204
|
+
body_composition_payload[10] << 8
|
|
205
|
+
) + body_composition_payload[9]
|
|
206
|
+
_LOGGER.debug("Impedance: %d Ω", impedance)
|
|
207
|
+
|
|
208
|
+
self.update_predefined_sensor(
|
|
209
|
+
SensorLibrary.MASS__MASS_KILOGRAMS, weight
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
self.update_predefined_sensor(SensorLibrary.IMPEDANCE__OHM, impedance)
|
|
213
|
+
|
|
214
|
+
# Battery percentage always returns 0 on my device
|
|
215
|
+
battery_char = client.services.get_characteristic(
|
|
216
|
+
CHARACTERISTIC_BATTERY_LEVEL
|
|
217
|
+
)
|
|
218
|
+
if battery_char:
|
|
219
|
+
battery_payload = await client.read_gatt_char(battery_char)
|
|
220
|
+
|
|
221
|
+
self.update_predefined_sensor(
|
|
222
|
+
SensorLibrary.BATTERY__PERCENTAGE,
|
|
223
|
+
battery_payload[0],
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
if _LOGGER.isEnabledFor(logging.DEBUG):
|
|
227
|
+
self.log_manufacturer_data(advertisement_data.manufacturer_data)
|
|
228
|
+
self.process_manufacturer_data(advertisement_data.manufacturer_data)
|
|
229
|
+
finally:
|
|
230
|
+
await self.disconnect()
|
|
231
|
+
|
|
232
|
+
return self._finish_update()
|
|
233
|
+
|
|
234
|
+
def process_manufacturer_data(self, manufacturer_data):
|
|
235
|
+
if MANUFACTURER_DATA_ID_V10 in manufacturer_data:
|
|
236
|
+
return
|
|
237
|
+
if MANUFACTURER_DATA_ID_V26 in manufacturer_data:
|
|
238
|
+
return
|
|
239
|
+
|
|
240
|
+
if MANUFACTURER_DATA_ID_V11 in manufacturer_data:
|
|
241
|
+
self._process_manufacturer_data_v11(manufacturer_data)
|
|
242
|
+
elif MANUFACTURER_DATA_ID_V20 in manufacturer_data:
|
|
243
|
+
self._process_manufacturer_data_v20(manufacturer_data)
|
|
244
|
+
elif MANUFACTURER_DATA_ID_VF0 in manufacturer_data:
|
|
245
|
+
self._process_manufacturer_data_vf0(manufacturer_data)
|
|
246
|
+
else:
|
|
247
|
+
self._process_manufacturer_data_vc0(manufacturer_data)
|
|
248
|
+
|
|
249
|
+
def _process_manufacturer_data_v11(self, manufacturer_data):
|
|
250
|
+
data = manufacturer_data[MANUFACTURER_DATA_ID_V11]
|
|
251
|
+
if data is None or len(data) != IDX_V11_CHECKSUM + 6 + 1:
|
|
252
|
+
_LOGGER.error(
|
|
253
|
+
"Data length error, got %d, expected %d",
|
|
254
|
+
len(data),
|
|
255
|
+
IDX_V11_CHECKSUM + 6 + 1,
|
|
256
|
+
)
|
|
257
|
+
return
|
|
258
|
+
|
|
259
|
+
if (data[IDX_V11_FINAL] & 1) == 0:
|
|
260
|
+
_LOGGER.debug("Data is not final")
|
|
261
|
+
return
|
|
262
|
+
|
|
263
|
+
checksum = (
|
|
264
|
+
0xCA ^ 0x11
|
|
265
|
+
) # Version and magic fields are part of the checksum, but not in array
|
|
266
|
+
for i in range(0, IDX_V11_CHECKSUM - 1):
|
|
267
|
+
checksum ^= data[i]
|
|
268
|
+
if data[IDX_V11_CHECKSUM] != checksum:
|
|
269
|
+
_LOGGER.error(
|
|
270
|
+
"Checksum error, got %s, expected %s",
|
|
271
|
+
hex(data[IDX_V11_CHECKSUM] & 0xFF),
|
|
272
|
+
hex(checksum & 0xFF),
|
|
273
|
+
)
|
|
274
|
+
return
|
|
275
|
+
|
|
276
|
+
# Reading the weight
|
|
277
|
+
divider = 10.0
|
|
278
|
+
weight = data[IDX_V11_WEIGHT_MSB] & 0xFF
|
|
279
|
+
weight = weight << 8 | (data[IDX_V11_WEIGHT_LSB] & 0xFF)
|
|
280
|
+
|
|
281
|
+
match (data[IDX_V11_BODY_PROPERTIES] >> 1) & 3:
|
|
282
|
+
case 0:
|
|
283
|
+
divider = 10.0
|
|
284
|
+
case 1:
|
|
285
|
+
divider = 1.0
|
|
286
|
+
case 2:
|
|
287
|
+
divider = 100.0
|
|
288
|
+
case _:
|
|
289
|
+
_LOGGER.warning("Invalid weight scale received, assuming 1 decimal")
|
|
290
|
+
divider = 10.0
|
|
291
|
+
|
|
292
|
+
base_description = None
|
|
293
|
+
match (data[IDX_V11_BODY_PROPERTIES] >> 3) & 3:
|
|
294
|
+
case 0: # kg
|
|
295
|
+
weight = weight / divider
|
|
296
|
+
base_description = SensorLibrary.MASS__MASS_KILOGRAMS
|
|
297
|
+
case 1: # Jin
|
|
298
|
+
divider *= 2.0
|
|
299
|
+
weight = weight / divider
|
|
300
|
+
base_description = SensorLibrary.MASS__MASS_KILOGRAMS
|
|
301
|
+
case 2: # lb
|
|
302
|
+
weight = weight / divider
|
|
303
|
+
base_description = SensorLibrary.MASS__MASS_POUNDS
|
|
304
|
+
case 3: # st & lb
|
|
305
|
+
stones = weight >> 8
|
|
306
|
+
pounds = (weight & 0xFF) / divider
|
|
307
|
+
weight = pounds + (stones * 14)
|
|
308
|
+
base_description = SensorLibrary.MASS__MASS_POUNDS
|
|
309
|
+
_LOGGER.debug(
|
|
310
|
+
"Weight: %.2f %s", weight, base_description.native_unit_of_measurement
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
self.update_predefined_sensor(base_description, weight)
|
|
314
|
+
|
|
315
|
+
def _process_manufacturer_data_v20(self, manufacturer_data):
|
|
316
|
+
data = manufacturer_data[MANUFACTURER_DATA_ID_V20]
|
|
317
|
+
if data is None or len(data) != 19:
|
|
318
|
+
_LOGGER.error("Data length error, got %d, expected 19", len(data))
|
|
319
|
+
return
|
|
320
|
+
|
|
321
|
+
if (data[IDX_V20_FINAL] & 1) == 0:
|
|
322
|
+
_LOGGER.debug("Data is not final")
|
|
323
|
+
return
|
|
324
|
+
|
|
325
|
+
checksum = 0x20 # Version field is part of the checksum, but not in array
|
|
326
|
+
for i in range(0, IDX_V20_CHECKSUM - 1):
|
|
327
|
+
checksum ^= data[i]
|
|
328
|
+
if data[IDX_V20_CHECKSUM] != checksum:
|
|
329
|
+
_LOGGER.error(
|
|
330
|
+
"Checksum error, got 0x%s, expected 0x%s",
|
|
331
|
+
hex(data[IDX_V20_CHECKSUM] & 0xFF),
|
|
332
|
+
hex(checksum & 0xFF),
|
|
333
|
+
)
|
|
334
|
+
return
|
|
335
|
+
|
|
336
|
+
# Reading the weight
|
|
337
|
+
divider = 10.0
|
|
338
|
+
if (data[IDX_V20_FINAL] & 4) == 4:
|
|
339
|
+
divider = 100.0
|
|
340
|
+
weight = ((data[IDX_V20_WEIGHT_MSB] << 8) + data[IDX_V20_WEIGHT_LSB]) / divider
|
|
341
|
+
_LOGGER.debug("Weight: %.2f kg", weight)
|
|
342
|
+
|
|
343
|
+
# Reading the impedance
|
|
344
|
+
impedance = (
|
|
345
|
+
(data[IDX_V20_IMPEDANCE_MSB] << 8) + data[IDX_V20_IMPEDANCE_LSB]
|
|
346
|
+
) / 10.0
|
|
347
|
+
_LOGGER.debug("Impedance: %.1f Ω", impedance)
|
|
348
|
+
|
|
349
|
+
self.update_predefined_sensor(SensorLibrary.MASS__MASS_KILOGRAMS, weight)
|
|
350
|
+
|
|
351
|
+
self.update_predefined_sensor(SensorLibrary.IMPEDANCE__OHM, impedance)
|
|
352
|
+
|
|
353
|
+
def _process_manufacturer_data_vc0(self, manufacturer_data):
|
|
354
|
+
data = None
|
|
355
|
+
final = False
|
|
356
|
+
for key, _data in manufacturer_data.items():
|
|
357
|
+
# Run through the whole list of values so we get the final reading
|
|
358
|
+
if (key & 0xFF) != MANUFACTURER_DATA_ID_VC0:
|
|
359
|
+
continue
|
|
360
|
+
if len(_data) != 13:
|
|
361
|
+
continue
|
|
362
|
+
if _data[IDX_VC0_WEIGHT_MSB] == 0 and _data[IDX_VC0_WEIGHT_LSB] == 0:
|
|
363
|
+
continue
|
|
364
|
+
|
|
365
|
+
if (_data[IDX_VC0_FINAL] & 1) == 1:
|
|
366
|
+
data = _data
|
|
367
|
+
final = True
|
|
368
|
+
elif not final:
|
|
369
|
+
data = _data
|
|
370
|
+
|
|
371
|
+
if data is None:
|
|
372
|
+
return
|
|
373
|
+
|
|
374
|
+
if not final:
|
|
375
|
+
_LOGGER.debug("Data is not final")
|
|
376
|
+
# return
|
|
377
|
+
|
|
378
|
+
msb = data[IDX_VC0_WEIGHT_MSB]
|
|
379
|
+
lsb = data[IDX_VC0_WEIGHT_LSB]
|
|
380
|
+
base_description = None
|
|
381
|
+
match data[IDX_VC0_BODY_PROPERTIES] >> 3 & 0x3:
|
|
382
|
+
case 0: # kg
|
|
383
|
+
weight = (msb << 8 | lsb) / 100.0
|
|
384
|
+
base_description = SensorLibrary.MASS__MASS_KILOGRAMS
|
|
385
|
+
case 2: # lb
|
|
386
|
+
weight = (msb << 8 | lsb) / 10.0
|
|
387
|
+
base_description = SensorLibrary.MASS__MASS_POUNDS
|
|
388
|
+
case 3: # st:lb
|
|
389
|
+
weight = msb * 14 + lsb / 10.0
|
|
390
|
+
base_description = SensorLibrary.MASS__MASS_POUNDS
|
|
391
|
+
_LOGGER.debug(
|
|
392
|
+
"Weight: %.2f %s", weight, base_description.native_unit_of_measurement
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
self.update_predefined_sensor(base_description, weight)
|
|
396
|
+
|
|
397
|
+
def _process_manufacturer_data_vf0(self, manufacturer_data):
|
|
398
|
+
data = manufacturer_data[MANUFACTURER_DATA_ID_VF0]
|
|
399
|
+
if len(data) != 18:
|
|
400
|
+
_LOGGER.error("Data length error, got %d, expected 18", len(data))
|
|
401
|
+
return
|
|
402
|
+
|
|
403
|
+
# Reading the weight
|
|
404
|
+
# ToDo use unpack
|
|
405
|
+
weight = ((data[IDX_VF0_WEIGHT_MSB] << 8) + data[IDX_VF0_WEIGHT_LSB]) / 10.0
|
|
406
|
+
_LOGGER.debug("Weight: %.1f kg", weight)
|
|
407
|
+
|
|
408
|
+
self.update_predefined_sensor(SensorLibrary.MASS__MASS_KILOGRAMS, weight)
|
|
409
|
+
|
|
410
|
+
def log_service_info(self, service_info: BluetoothServiceInfo):
|
|
411
|
+
_LOGGER.debug("Device Name: %s", service_info.name)
|
|
412
|
+
_LOGGER.debug("Device Address: %s", service_info.address)
|
|
413
|
+
_LOGGER.debug("Device RSSI: %s", service_info.rssi)
|
|
414
|
+
|
|
415
|
+
self.log_manufacturer_data(service_info.manufacturer_data)
|
|
416
|
+
|
|
417
|
+
service_data = service_info.service_data
|
|
418
|
+
for service_id in service_data:
|
|
419
|
+
try:
|
|
420
|
+
data = service_data[service_id]
|
|
421
|
+
_LOGGER.debug("Service Data %s: %s", service_id, data.decode())
|
|
422
|
+
_LOGGER.debug("Service Data %s: 0x%s", service_id, data.hex())
|
|
423
|
+
except UnicodeDecodeError:
|
|
424
|
+
_LOGGER.debug("Service Data %s: 0x%s", service_id, data.hex())
|
|
425
|
+
except Exception:
|
|
426
|
+
pass
|
|
427
|
+
|
|
428
|
+
_LOGGER.debug("Service UUIDs: %s", service_info.service_uuids)
|
|
429
|
+
|
|
430
|
+
def log_manufacturer_data(self, manufacturer_data):
|
|
431
|
+
for manufacturer_id in manufacturer_data:
|
|
432
|
+
data = manufacturer_data[manufacturer_id]
|
|
433
|
+
_LOGGER.debug("Manufacturer Identifier: %s", hex(manufacturer_id))
|
|
434
|
+
_LOGGER.debug("Manufacturer Data Length: %s", len(data))
|
|
435
|
+
try:
|
|
436
|
+
_LOGGER.debug("Manufacturer Data: %s", data.decode())
|
|
437
|
+
_LOGGER.debug("Manufacturer Data: 0x%s", data.hex())
|
|
438
|
+
except UnicodeDecodeError:
|
|
439
|
+
_LOGGER.debug("Manufacturer Data: 0x%s", data.hex())
|
|
440
|
+
except Exception:
|
|
441
|
+
pass
|
|
442
|
+
|
|
443
|
+
async def log_client(self, client):
|
|
444
|
+
# Log characteristics for debugging
|
|
445
|
+
for i in client.services.characteristics:
|
|
446
|
+
try:
|
|
447
|
+
characteristic = client.services.characteristics[i]
|
|
448
|
+
gatt_char = client.services.get_characteristic(characteristic.uuid)
|
|
449
|
+
payload = await client.read_gatt_char(gatt_char)
|
|
450
|
+
_LOGGER.debug("client.services %s: %s", gatt_char, payload.decode())
|
|
451
|
+
_LOGGER.debug("client.services %s: 0x%s", gatt_char, payload.hex())
|
|
452
|
+
except UnicodeDecodeError:
|
|
453
|
+
_LOGGER.debug("client.services %s: 0x%s", gatt_char, payload.hex())
|
|
454
|
+
except Exception:
|
|
455
|
+
pass
|
|
File without changes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.29", "hatch-vcs"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[tool.hatch.build.hooks.vcs]
|
|
6
|
+
version-file = "okokscale/_version.py"
|
|
7
|
+
|
|
8
|
+
[tool.hatch.version]
|
|
9
|
+
source = "vcs"
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "okokscale"
|
|
13
|
+
dynamic = ["version"]
|
|
14
|
+
license = {text = "Apache-2.0"}
|
|
15
|
+
authors = [
|
|
16
|
+
{ name="Rogier van Staveren", email="rogier@batoid.com" }
|
|
17
|
+
]
|
|
18
|
+
description = "Library for parsing OKOK scale BLE advertisements."
|
|
19
|
+
readme = "README.md"
|
|
20
|
+
requires-python = ">=3.11"
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"License :: OSI Approved :: Apache Software License",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"bleak>=3.0.2",
|
|
29
|
+
"bluetooth_sensor_state_data==1.9.0"
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
"Homepage" = "https://github.com/rrooggiieerr/okokscale.py"
|
|
34
|
+
"Bug Tracker" = "https://github.com/rrooggiieerr/okokscale.py/issues"
|
|
35
|
+
|
|
36
|
+
[tool.isort]
|
|
37
|
+
# https://github.com/PyCQA/isort/wiki/isort-Settings
|
|
38
|
+
profile = "black"
|
|
39
|
+
skip = "*/_version.py"
|
|
40
|
+
|
|
41
|
+
[tool.black]
|
|
42
|
+
exclude = "rfcontrol/_version.py"
|
|
43
|
+
|
|
44
|
+
[tool.pylint]
|
|
45
|
+
ignore = "_version.py"
|
|
46
|
+
recursive = "y"
|
|
47
|
+
|
|
48
|
+
[tool.mypy]
|
|
49
|
+
python_version = "3.11"
|
|
50
|
+
mypy_path = "rfcontrol"
|
|
51
|
+
|
|
52
|
+
[[tool.mypy.overrides]]
|
|
53
|
+
module = ["*._version"]
|
|
54
|
+
ignore_missing_imports = true
|