kaco-serial 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions: {}
9
+
10
+ jobs:
11
+ check:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ python-version: ["3.13", "3.14"]
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: astral-sh/setup-uv@v5
20
+ with:
21
+ enable-cache: true
22
+ - run: uv sync --frozen --python ${{ matrix.python-version }}
23
+ - name: Lint
24
+ run: uv run ruff check .
25
+ - name: Format
26
+ run: uv run ruff format --check .
27
+ - name: Types
28
+ run: uv run mypy src/ tests/
29
+ - name: Tests
30
+ run: uv run pytest
@@ -0,0 +1,55 @@
1
+ name: Release Please
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch:
7
+ inputs:
8
+ tag:
9
+ description: "Tag to publish to PyPI. Leave empty to run release-please only."
10
+ required: false
11
+ type: string
12
+
13
+ permissions: {}
14
+
15
+ concurrency:
16
+ group: release
17
+ cancel-in-progress: false
18
+
19
+ jobs:
20
+ release-please:
21
+ runs-on: ubuntu-latest
22
+ timeout-minutes: 10
23
+ permissions:
24
+ contents: write
25
+ pull-requests: write
26
+ outputs:
27
+ release_created: ${{ steps.release.outputs.release_created }}
28
+ tag_name: ${{ steps.release.outputs.tag_name }}
29
+ steps:
30
+ - uses: googleapis/release-please-action@v4
31
+ id: release
32
+ with:
33
+ config-file: release-please-config.json
34
+ manifest-file: .release-please-manifest.json
35
+
36
+ publish:
37
+ needs: release-please
38
+ if: needs.release-please.outputs.release_created == 'true' || inputs.tag != ''
39
+ runs-on: ubuntu-latest
40
+ timeout-minutes: 15
41
+ permissions:
42
+ # Trusted publishing matches on this workflow's filename, so this file
43
+ # must stay release.yml — it is what the PyPI publisher is registered
44
+ # against.
45
+ id-token: write
46
+ steps:
47
+ - uses: actions/checkout@v4
48
+ with:
49
+ ref: ${{ inputs.tag || needs.release-please.outputs.tag_name }}
50
+ - uses: astral-sh/setup-uv@v5
51
+ - run: uv build
52
+ - uses: pypa/gh-action-pypi-publish@release/v1
53
+ with:
54
+ verbose: true
55
+ skip-existing: true
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ dist/
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+ .idea/
8
+
9
+ # Raw captures from a live installation — contain yield, uptime and serials
10
+ private/
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.1.0"
3
+ }
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-08-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * accept third-party captures as test fixtures ([e7c9ea8](https://github.com/g4bri3lDev/kaco-rs485/commit/e7c9ea8aceb3eff0bbfd2ed3df35b0fe90713785))
9
+ * bus discovery instead of hardcoded addresses ([95ac5d1](https://github.com/g4bri3lDev/kaco-rs485/commit/95ac5d1f288641ee3101313662decac1c4b5bdc4))
10
+ * fold in findings from the vendor firmware analysis ([e1c782a](https://github.com/g4bri3lDev/kaco-rs485/commit/e1c782ac9091267a160641327a5b214e4cc12140))
11
+ * KACO xi RS485 library with URL-addressed transport ([ab6e9f5](https://github.com/g4bri3lDev/kaco-rs485/commit/ab6e9f5d3fa6c7705e93b349c19390742a1ca27f))
12
+ * status code table with the two field-observed codes ([7c5efe4](https://github.com/g4bri3lDev/kaco-rs485/commit/7c5efe4d106f66f96eb2cd1b5dffcdb1563b736b))
13
+
14
+
15
+ ### Bug fixes
16
+
17
+ * an empty listen is not evidence of a fault ([b7a5112](https://github.com/g4bri3lDev/kaco-rs485/commit/b7a51124939e692e06d10df4ddad2cf04afa543e))
18
+ * connection loss must not kill a long-running poll ([54ff92f](https://github.com/g4bri3lDev/kaco-rs485/commit/54ff92f9769a53942e26ea993bc23a390eb89bcc))
19
+ * narrow two types the checker could not follow ([7706eef](https://github.com/g4bri3lDev/kaco-rs485/commit/7706eef5b993a86e433719fe09e430d675a279de))
20
+ * pace scan and sweep, they were polling back to back ([eb6bc7f](https://github.com/g4bri3lDev/kaco-rs485/commit/eb6bc7f50e579f16e9f021d51a7d5c28f871cb48))
21
+ * remove installation-specific assumptions; instrument timings ([1296848](https://github.com/g4bri3lDev/kaco-rs485/commit/129684876d49d9700edc5dca1177095b248b5bff))
22
+
23
+
24
+ ### Performance
25
+
26
+ * only pay the bus-settle gap after an address replies ([d2b008e](https://github.com/g4bri3lDev/kaco-rs485/commit/d2b008ee81765e976a2ee5f2472d368d140fc239))
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.5
2
+ Name: kaco-serial
3
+ Version: 0.1.0
4
+ Summary: Read KACO Powador xi-series inverters over RS485, locally or via an ESPHome serial proxy.
5
+ Project-URL: Homepage, https://github.com/g4bri3lDev/kaco-rs485
6
+ Author-email: g4bri3lDev <admin@g4bri3l.de>
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: esphome,home-assistant,kaco,powador,rs485,solar
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Home Automation
12
+ Requires-Python: >=3.13
13
+ Requires-Dist: serialx<2,>=1.8.2
14
+ Provides-Extra: cli
15
+ Requires-Dist: serialx[esphome]<2,>=1.8.2; extra == 'cli'
16
+ Description-Content-Type: text/markdown
17
+
18
+ # kaco-rs485
19
+
20
+ Read KACO Powador **xi-series** inverters (6400xi, 8000xi, and relatives) over
21
+ RS485 — from a local adapter, or across the network through an
22
+ [ESPHome serial proxy](https://esphome.io/components/serial_proxy/).
23
+
24
+ Companion to [`kaco-modbus`](https://github.com/g4bri3lDev/kaco-modbus), which
25
+ covers the newer blueplanet units over SunSpec Modbus TCP. Different protocol,
26
+ different hardware generation, same fleet.
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ uv add kaco-serial # library
32
+ uv add 'kaco-serial[cli]' # + the diagnostic CLI and ESPHome transport
33
+ ```
34
+
35
+ ## The bus is addressed by URL
36
+
37
+ There is one transport, and it takes an opaque URL. serialx resolves the
38
+ scheme, so nothing in this library knows or cares how the bytes get there:
39
+
40
+ | URL | Where |
41
+ |---|---|
42
+ | `/dev/tty.usbserial-0001` | local RS485 adapter |
43
+ | `esphome://host:6053/?port_name=RS-485` | ESPHome proxy, standalone |
44
+ | `esphome-hass://esphome/<entry_id>?port_name=RS-485` | ESPHome proxy, inside Home Assistant |
45
+ | `socket://host:port` | any ser2net-style bridge |
46
+
47
+ The `esphome-hass` scheme is registered by Home Assistant and resolves the
48
+ ESPHome integration's already-authenticated client — which is why the Home
49
+ Assistant integration built on this library stores no host and no API key.
50
+
51
+ ## Library
52
+
53
+ ```python
54
+ from kaco_rs485 import AsyncBus, KacoRs485Client
55
+ from kaco_rs485.discovery import scan
56
+
57
+ async with AsyncBus("esphome://proxy.local:6053/?port_name=RS-485") as bus:
58
+ found = await scan(bus)
59
+ client = KacoRs485Client(bus, [d.address for d in found.supported])
60
+ states = await client.poll_cycle()
61
+ for address, state in states.items():
62
+ print(address, state.measured.ac_power_w)
63
+ ```
64
+
65
+ `KacoRs485Client` owns the pacing. Don't drive `AsyncBus` from two tasks at
66
+ once — RS485 is a shared medium and interleaved requests garble each other.
67
+
68
+ ## Bringing up a bus
69
+
70
+ Four CLI modes, in the order you actually need them:
71
+
72
+ ```bash
73
+ # 1. Is anything there, and are A/B the right way round?
74
+ # Transmits nothing — safe while another master is still connected.
75
+ kaco-rs485 --url <url> listen --seconds 30
76
+
77
+ # 2. Which addresses are occupied, and what is at them?
78
+ # Probes all 32 addresses; a silent one costs ~2.5s.
79
+ kaco-rs485 --url <url> scan
80
+
81
+ # 3. Everything one address can tell you.
82
+ kaco-rs485 --url <url> sweep --addresses 2 -v
83
+
84
+ # 4. Does it keep working? Scans first if you omit --addresses.
85
+ kaco-rs485 --url <url> poll
86
+ ```
87
+
88
+ When nothing answers, the CLI prints a diagnostic checklist rather than just a
89
+ timeout. **Only one master may drive an RS485 bus** — power down any other
90
+ polling device before blaming the wiring.
91
+
92
+ ## Protocol notes
93
+
94
+ The parsers were validated against bytes captured from a live installation,
95
+ and they deliberately tolerate several places where real hardware diverges
96
+ from the KACO specification:
97
+
98
+ - Command `3` replies on xi units **omit** the `*<adr>3 ` header the spec
99
+ shows. Both shapes are accepted.
100
+ - Command `3` total yield is in **kWh** on xi units, **Wh** on the blueplanet.
101
+ `total_yield_raw` is exposed unscaled; the caller decides.
102
+ - Command `s` (serial number) is **unsupported** on xi units — they return
103
+ nothing. Use command `9` for identification.
104
+ - The command `0` checksum byte may be **any** value 0-255, including CR and
105
+ LF. This is why framing is length-gated instead of scanning for a
106
+ terminator, and why readline-style parsing cannot work here.
107
+ - xi units pause **>250 ms mid-frame**, between the checksum byte and the
108
+ trailing type string. Frames legitimately end anywhere from 58 to 65 bytes;
109
+ the type string is decorative.
110
+ - Replies start **1-2 seconds** after the request.
111
+ - Status codes **4 (feeding in)** and **6 (standby)** are observed in the
112
+ field but absent from the specification's table.
113
+
114
+ `tests/reference/` holds real frames from a live bus. The framing tests replay
115
+ them split at every possible byte boundary, because through a network proxy the
116
+ arrival chunking is arbitrary.
117
+
118
+ ## Contributing a capture
119
+
120
+ This library is developed against Powador **6400xi** and **8000xi** units. Other
121
+ KACO hardware very likely works, or would with a small change, but that cannot
122
+ be confirmed without bytes from someone who owns it. A capture from your
123
+ installation is the single most useful contribution.
124
+
125
+ ```bash
126
+ kaco-rs485 --url <url> --log-dir captures sweep
127
+ ```
128
+
129
+ Open a pull request adding the resulting `.json` to `tests/reference/`. It is
130
+ picked up automatically — every parser and framing test will run against it, so
131
+ a file that breaks nothing is evidence your hardware is supported, and a file
132
+ that breaks something is a bug report with a reproduction attached.
133
+
134
+ Especially wanted:
135
+
136
+ - **Other xi-series units** (2500xi, 3600xi, 4200xi, 5000xi…). Expected to use
137
+ the same series-"00" frames; confirmation is cheap and valuable.
138
+ - **Series "000xi"** park inverters. These answer with command byte `4` instead
139
+ of `0` and need a parser that does not exist yet.
140
+ - **blueplanet / TL / TR units**, which speak CRC16 Generic Protocol
141
+ (command byte `n`). A whole second protocol; captures are the prerequisite
142
+ for deciding whether to implement it here.
143
+
144
+ **Before you open the PR, look at what is in the file.** A capture contains
145
+ your total yield, operating hours, and — if command `s` answered — the
146
+ inverter's serial number. None of it is dangerous, but total yield and uptime
147
+ do describe the size and age of your installation, so it is your call. Deleting
148
+ the `8`/`9`/`s` entries and keeping only `0` and `3` still makes a useful
149
+ fixture.
@@ -0,0 +1,132 @@
1
+ # kaco-rs485
2
+
3
+ Read KACO Powador **xi-series** inverters (6400xi, 8000xi, and relatives) over
4
+ RS485 — from a local adapter, or across the network through an
5
+ [ESPHome serial proxy](https://esphome.io/components/serial_proxy/).
6
+
7
+ Companion to [`kaco-modbus`](https://github.com/g4bri3lDev/kaco-modbus), which
8
+ covers the newer blueplanet units over SunSpec Modbus TCP. Different protocol,
9
+ different hardware generation, same fleet.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ uv add kaco-serial # library
15
+ uv add 'kaco-serial[cli]' # + the diagnostic CLI and ESPHome transport
16
+ ```
17
+
18
+ ## The bus is addressed by URL
19
+
20
+ There is one transport, and it takes an opaque URL. serialx resolves the
21
+ scheme, so nothing in this library knows or cares how the bytes get there:
22
+
23
+ | URL | Where |
24
+ |---|---|
25
+ | `/dev/tty.usbserial-0001` | local RS485 adapter |
26
+ | `esphome://host:6053/?port_name=RS-485` | ESPHome proxy, standalone |
27
+ | `esphome-hass://esphome/<entry_id>?port_name=RS-485` | ESPHome proxy, inside Home Assistant |
28
+ | `socket://host:port` | any ser2net-style bridge |
29
+
30
+ The `esphome-hass` scheme is registered by Home Assistant and resolves the
31
+ ESPHome integration's already-authenticated client — which is why the Home
32
+ Assistant integration built on this library stores no host and no API key.
33
+
34
+ ## Library
35
+
36
+ ```python
37
+ from kaco_rs485 import AsyncBus, KacoRs485Client
38
+ from kaco_rs485.discovery import scan
39
+
40
+ async with AsyncBus("esphome://proxy.local:6053/?port_name=RS-485") as bus:
41
+ found = await scan(bus)
42
+ client = KacoRs485Client(bus, [d.address for d in found.supported])
43
+ states = await client.poll_cycle()
44
+ for address, state in states.items():
45
+ print(address, state.measured.ac_power_w)
46
+ ```
47
+
48
+ `KacoRs485Client` owns the pacing. Don't drive `AsyncBus` from two tasks at
49
+ once — RS485 is a shared medium and interleaved requests garble each other.
50
+
51
+ ## Bringing up a bus
52
+
53
+ Four CLI modes, in the order you actually need them:
54
+
55
+ ```bash
56
+ # 1. Is anything there, and are A/B the right way round?
57
+ # Transmits nothing — safe while another master is still connected.
58
+ kaco-rs485 --url <url> listen --seconds 30
59
+
60
+ # 2. Which addresses are occupied, and what is at them?
61
+ # Probes all 32 addresses; a silent one costs ~2.5s.
62
+ kaco-rs485 --url <url> scan
63
+
64
+ # 3. Everything one address can tell you.
65
+ kaco-rs485 --url <url> sweep --addresses 2 -v
66
+
67
+ # 4. Does it keep working? Scans first if you omit --addresses.
68
+ kaco-rs485 --url <url> poll
69
+ ```
70
+
71
+ When nothing answers, the CLI prints a diagnostic checklist rather than just a
72
+ timeout. **Only one master may drive an RS485 bus** — power down any other
73
+ polling device before blaming the wiring.
74
+
75
+ ## Protocol notes
76
+
77
+ The parsers were validated against bytes captured from a live installation,
78
+ and they deliberately tolerate several places where real hardware diverges
79
+ from the KACO specification:
80
+
81
+ - Command `3` replies on xi units **omit** the `*<adr>3 ` header the spec
82
+ shows. Both shapes are accepted.
83
+ - Command `3` total yield is in **kWh** on xi units, **Wh** on the blueplanet.
84
+ `total_yield_raw` is exposed unscaled; the caller decides.
85
+ - Command `s` (serial number) is **unsupported** on xi units — they return
86
+ nothing. Use command `9` for identification.
87
+ - The command `0` checksum byte may be **any** value 0-255, including CR and
88
+ LF. This is why framing is length-gated instead of scanning for a
89
+ terminator, and why readline-style parsing cannot work here.
90
+ - xi units pause **>250 ms mid-frame**, between the checksum byte and the
91
+ trailing type string. Frames legitimately end anywhere from 58 to 65 bytes;
92
+ the type string is decorative.
93
+ - Replies start **1-2 seconds** after the request.
94
+ - Status codes **4 (feeding in)** and **6 (standby)** are observed in the
95
+ field but absent from the specification's table.
96
+
97
+ `tests/reference/` holds real frames from a live bus. The framing tests replay
98
+ them split at every possible byte boundary, because through a network proxy the
99
+ arrival chunking is arbitrary.
100
+
101
+ ## Contributing a capture
102
+
103
+ This library is developed against Powador **6400xi** and **8000xi** units. Other
104
+ KACO hardware very likely works, or would with a small change, but that cannot
105
+ be confirmed without bytes from someone who owns it. A capture from your
106
+ installation is the single most useful contribution.
107
+
108
+ ```bash
109
+ kaco-rs485 --url <url> --log-dir captures sweep
110
+ ```
111
+
112
+ Open a pull request adding the resulting `.json` to `tests/reference/`. It is
113
+ picked up automatically — every parser and framing test will run against it, so
114
+ a file that breaks nothing is evidence your hardware is supported, and a file
115
+ that breaks something is a bug report with a reproduction attached.
116
+
117
+ Especially wanted:
118
+
119
+ - **Other xi-series units** (2500xi, 3600xi, 4200xi, 5000xi…). Expected to use
120
+ the same series-"00" frames; confirmation is cheap and valuable.
121
+ - **Series "000xi"** park inverters. These answer with command byte `4` instead
122
+ of `0` and need a parser that does not exist yet.
123
+ - **blueplanet / TL / TR units**, which speak CRC16 Generic Protocol
124
+ (command byte `n`). A whole second protocol; captures are the prerequisite
125
+ for deciding whether to implement it here.
126
+
127
+ **Before you open the PR, look at what is in the file.** A capture contains
128
+ your total yield, operating hours, and — if command `s` answered — the
129
+ inverter's serial number. None of it is dangerous, but total yield and uptime
130
+ do describe the size and age of your installation, so it is your call. Deleting
131
+ the `8`/`9`/`s` entries and keeping only `0` and `3` still makes a useful
132
+ fixture.
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "kaco-serial"
7
+ dynamic = ["version"]
8
+ description = "Read KACO Powador xi-series inverters over RS485, locally or via an ESPHome serial proxy."
9
+ readme = "README.md"
10
+ requires-python = ">=3.13"
11
+ license = "Apache-2.0"
12
+ authors = [{ name = "g4bri3lDev", email = "admin@g4bri3l.de" }]
13
+ keywords = ["rs485", "kaco", "powador", "solar", "home-assistant", "esphome"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Topic :: Home Automation",
17
+ ]
18
+ # serialx replaces pyserial and gives us every transport for free: local
19
+ # devices, socket://, and ESPHome serial proxies. Core pins 1.8.2.
20
+ dependencies = ["serialx>=1.8.2,<2"]
21
+
22
+ [project.optional-dependencies]
23
+ # Only the standalone CLI needs this — inside Home Assistant, the `esphome`
24
+ # integration already provides aioesphomeapi and registers the URI handler.
25
+ cli = ["serialx[esphome]>=1.8.2,<2"]
26
+
27
+ [project.scripts]
28
+ kaco-rs485 = "kaco_rs485.cli:main"
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/g4bri3lDev/kaco-rs485"
32
+
33
+ [dependency-groups]
34
+ dev = [
35
+ "pytest>=8",
36
+ "pytest-asyncio>=0.24",
37
+ "mypy>=1.14",
38
+ "ruff>=0.8",
39
+ ]
40
+
41
+ [tool.hatch.version]
42
+ path = "src/kaco_rs485/__init__.py"
43
+
44
+ [tool.hatch.build.targets.wheel]
45
+ packages = ["src/kaco_rs485"]
46
+
47
+ [tool.pytest.ini_options]
48
+ asyncio_mode = "auto"
49
+ testpaths = ["tests"]
50
+
51
+ [tool.ruff]
52
+ line-length = 100