alfen-modbus 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,47 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "description": "Renovate configuration for alfen-modbus",
4
+ "dependencyDashboard": false,
5
+ "extends": [
6
+ "config:recommended",
7
+ ":separateMajorReleases",
8
+ ":combinePatchMinorReleases",
9
+ "helpers:pinGitHubActionDigests"
10
+ ],
11
+ "rebaseWhen": "conflicted",
12
+ "ignorePaths": [
13
+ "**/node_modules/**"
14
+ ],
15
+ "github-actions": {
16
+ "enabled": true
17
+ },
18
+ "lockFileMaintenance": {
19
+ "enabled": true,
20
+ "schedule": [
21
+ "before 5am on monday"
22
+ ]
23
+ },
24
+ "packageRules": [
25
+ {
26
+ "matchManagers": [
27
+ "github-actions"
28
+ ],
29
+ "groupName": "GitHub Actions",
30
+ "minimumReleaseAge": "3 days"
31
+ },
32
+ {
33
+ "matchDepTypes": [
34
+ "dev",
35
+ "test"
36
+ ],
37
+ "groupName": "Dev & Test Dependencies",
38
+ "minimumReleaseAge": "3 days"
39
+ },
40
+ {
41
+ "matchPackageNames": [
42
+ "modbus-connection"
43
+ ],
44
+ "groupName": "Core Protocol Dependencies"
45
+ }
46
+ ]
47
+ }
@@ -0,0 +1,35 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ lint:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
17
+ - uses: astral-sh/setup-uv@2a39bcff78b189a5800d31cfcf0205c7a3e8381e # v10.4.1
18
+ - name: Install dependencies
19
+ run: uv sync
20
+ - name: Ruff format
21
+ run: uv run ruff format --check .
22
+ - name: Ruff lint
23
+ run: uv run ruff check .
24
+ - name: Mypy
25
+ run: uv run mypy
26
+
27
+ test:
28
+ runs-on: ubuntu-latest
29
+ steps:
30
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
31
+ - uses: astral-sh/setup-uv@2a39bcff78b189a5800d31cfcf0205c7a3e8381e # v10.4.1
32
+ - name: Install dependencies
33
+ run: uv sync
34
+ - name: Run tests
35
+ run: uv run pytest
@@ -0,0 +1,51 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+ inputs:
8
+ tag:
9
+ description: Existing release tag to build and publish (e.g. 4.0.1)
10
+ required: true
11
+ type: string
12
+
13
+ env:
14
+ RELEASE_TAG: ${{ inputs.tag || github.event.release.tag_name }}
15
+
16
+ jobs:
17
+ build:
18
+ runs-on: ubuntu-latest
19
+ permissions:
20
+ contents: read
21
+ steps:
22
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
23
+ with:
24
+ ref: ${{ env.RELEASE_TAG }}
25
+ - uses: astral-sh/setup-uv@2a39bcff78b189a5800d31cfcf0205c7a3e8381e # v10.4.1
26
+ - name: Set package version from release tag
27
+ run: |
28
+ VERSION="${RELEASE_TAG#v}"
29
+ sed -i "s/^version = \"0\\.0\\.0\"$/version = \"${VERSION}\"/" pyproject.toml
30
+ - name: Verify the version was substituted
31
+ run: |
32
+ VERSION="${RELEASE_TAG#v}"
33
+ grep -qx "version = \"${VERSION}\"" pyproject.toml
34
+ - run: uv build
35
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
36
+ with:
37
+ name: dist
38
+ path: dist/
39
+
40
+ publish:
41
+ needs: build
42
+ runs-on: ubuntu-latest
43
+ environment: pypi
44
+ permissions:
45
+ id-token: write
46
+ steps:
47
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
48
+ with:
49
+ name: dist
50
+ path: dist/
51
+ - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # release/v1
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ build/
5
+ dist/
6
+ .venv/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .mypy_cache/
10
+ .coverage
11
+ htmlcov/
@@ -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 2026 darkrain-nl
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.
@@ -0,0 +1,301 @@
1
+ Metadata-Version: 2.5
2
+ Name: alfen-modbus
3
+ Version: 0.1.0
4
+ Summary: Read and control Alfen EV charging stations over Modbus TCP as typed Python objects.
5
+ Project-URL: Homepage, https://github.com/darkrain-nl/alfen-modbus
6
+ Author: alfen-modbus contributors
7
+ License: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: alfen,charging-station,ev-charger,eve,home-assistant,modbus
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Home Automation
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.12
15
+ Requires-Dist: modbus-connection[tmodbus]>=4.12.7
16
+ Description-Content-Type: text/markdown
17
+
18
+ # alfen-modbus
19
+
20
+ Read and control Alfen EV charging stations over Modbus TCP, as typed Python
21
+ objects rather than register numbers.
22
+
23
+ The library maps Alfen's register set onto
24
+ [modbus-connection](https://github.com/home-assistant-libs/modbus-connection)'s device model:
25
+ you hand it a connection's `for_unit`, call `async_setup()` and `async_update()`,
26
+ and read sub-systems as attributes. It was written to back a Home Assistant
27
+ integration but works from any asyncio code. Fully typed (`mypy --strict`, ships
28
+ `py.typed`) and tested to 100% branch coverage.
29
+
30
+ > [!NOTE]
31
+ > Checked on one live station: an Eve Single (NG910) on firmware 7.4.6, with
32
+ > no Smart Charging Network license. The Eve Double's second socket and a
33
+ > licensed SCN block have not met real hardware yet.
34
+
35
+ ## Supported stations
36
+
37
+ **`AlfenCharger`** reads the NG9xx platform: the Eve Single, Eve Double and Eve
38
+ Single Pro-line. Station-wide registers sit on unit 200 (`STATION_UNIT`), each
39
+ socket's on unit 1 or 2. `async_setup()` reads the identity and settles what the
40
+ station has: the socket count from its status block, and whether it serves the
41
+ Smart Charging Network (SCN) block. A single-socket station never sees a socket 2
42
+ read, and a station refusing the SCN block never sees it polled. A station
43
+ without the SCN license refuses it, so `charger.scn` stays `None`.
44
+
45
+ **Own an Eve Double, or a station in a Smart Charging Network?** Those parts
46
+ of the register map are unchecked, so the most useful thing you can do is
47
+ [open an issue](https://github.com/darkrain-nl/alfen-modbus/issues) with the
48
+ output of `uv run script/query.py <address> --raw` (see [Checking a real
49
+ station](#checking-a-real-station)). It only reads, and its raw dump shows
50
+ whether the map holds.
51
+
52
+ ## Station setup
53
+
54
+ The station only answers once Modbus is switched on in the ACE Service Installer:
55
+
56
+ - **Active Load Balancing** must be licensed and enabled, with **Modbus TCP/IP**
57
+ as its protocol. Without it the station serves no Modbus at all.
58
+ - **Data Source** must be **Energy Management System** for writes. Under a
59
+ meter data source, such as *Meter + EMS Monitoring*, the station still serves
60
+ reads but refuses every write with an illegal function error.
61
+ - **ValidityTime** on the TCP/IP EMS page (default 60 s) is how long a written
62
+ max current holds before the station falls back to its safe current.
63
+ - The station applies changed settings after a restart.
64
+
65
+ Firmware 7.4.6 has no separate switches for reading or writing. With no
66
+ setpoint written, the station charges at its safe current.
67
+
68
+ The station accepts two Modbus TCP clients at once, on port 502 (`MODBUS_PORT`).
69
+
70
+ ## Usage
71
+
72
+ ```python
73
+ import asyncio
74
+
75
+ from modbus_connection.tmodbus import connect_tcp
76
+
77
+ from alfen_modbus import AlfenCharger
78
+
79
+
80
+ async def main() -> None:
81
+ connection = await connect_tcp("192.168.1.60")
82
+ charger = AlfenCharger(connection.for_unit)
83
+ try:
84
+ await charger.async_setup() # reads the identity, finds socket 2
85
+ print(charger.identity.serial_number, charger.identity.platform_type)
86
+ report = await charger.async_update(charger.components)
87
+ print(charger.socket_1 in report.updated)
88
+ status = charger.socket_1.status
89
+ print(status.mode_3_state, status.actual_max_current)
90
+ print(charger.socket_1.meter.real_power_sum)
91
+ await status.async_write_max_current(10.0)
92
+ finally:
93
+ await connection.close()
94
+
95
+
96
+ asyncio.run(main())
97
+ ```
98
+
99
+ `async_update()` polls the sub-systems you pass, so a caller that only needs
100
+ the sockets passes `charger.sockets` and skips the rest.
101
+ `charger.components` lists every sub-system the station has. Both raise until
102
+ `async_setup()` has run, since only setup knows about socket 2 and the SCN.
103
+
104
+ The returned `PollReport` is keyed by those same objects: `updated` holds the
105
+ ones that refreshed and `failed` maps the rest to their error. A lost connection
106
+ raises, and so does a timeout before anything has answered. When every polled
107
+ sub-system fails, `async_update()` raises `NothingAnsweredError`, a
108
+ `ModbusError` whose `failed` maps each one to its error, instead of returning a
109
+ report with nothing in `updated`.
110
+
111
+ ```python
112
+ report = await charger.async_update(charger.components)
113
+ for component, error in report.failed.items():
114
+ print(f"{component} kept its previous values: {error}")
115
+ ```
116
+
117
+ To check which station answers at an address before setting one up, as a
118
+ config flow does, `await StationIdentity.async_detect(unit)` reads the identity
119
+ over a unit on `STATION_UNIT` alone.
120
+
121
+ ### What it covers
122
+
123
+ | Object | Unit | Registers |
124
+ | :--- | :--- | :--- |
125
+ | `charger.identity` | 200 | Name, manufacturer, firmware, platform, serial (read once) |
126
+ | `charger.clock` | 200 | Station clock, UTC offset, uptime |
127
+ | `charger.status` | 200 | Active max current, board temperature, backoffice link, socket count |
128
+ | `charger.scn` | 200 | Smart Charging Network per-phase budget; `None` if refused |
129
+ | `charger.socket_1`, `charger.socket_2` | 1, 2 | Energy meter and charging state; `socket_2` is `None` on a single socket |
130
+
131
+ ### Missing values
132
+
133
+ A value the station reports as NaN decodes to `None`. Which values the meter
134
+ fills depends on the meter. An Eve Single on firmware 7.4.6 fills only
135
+ `current_l1` to `current_l3`, `voltage_l1_n` to `voltage_l3_n`, `frequency`,
136
+ `power_factor_sum`, `real_power_sum` and `real_energy_delivered_sum`. Older ABB
137
+ meters are reported to fill them all.
138
+
139
+ ### Writes
140
+
141
+ | Method | Effect |
142
+ | :--- | :--- |
143
+ | `SocketStatus.async_write_max_current(amps)` | The socket's max current |
144
+ | `SocketStatus.async_write_charging_phases(phases)` | Switch between 1 and 3 phases |
145
+ | `SmartChargingNetwork.async_write_max_current(phase, amps)` | One SCN phase's max current (`Phase.L1` to `Phase.L3`) |
146
+
147
+ Each max current must be 0 (pause) or at least `MIN_CHARGING_CURRENT` (6 A, the
148
+ IEC 61851 floor); anything in between raises `ValueError` before writing. The
149
+ library sets no upper bound: the station caps the applied current at its
150
+ installation limit, while `max_current` reads back the value as written. Don't
151
+ use `SocketStatus.actual_max_current` as a UI ceiling: it follows the setpoint,
152
+ so the slider would ratchet down. `status.active_max_current` changes with the
153
+ station's settings and Alfen does not document it, so it is no ceiling either.
154
+
155
+ ### Holding a setpoint
156
+
157
+ A written max current only lasts the validity time set in ACE Service
158
+ Installer (60 s by default); then the station falls back to its safe current.
159
+ No register reports the validity time itself, only how much of it is left. To
160
+ keep a setpoint in force, hold it instead of writing it:
161
+
162
+ ```python
163
+ await charger.socket_1.status.async_hold_max_current(16.0)
164
+ # ... every poll now resends it in time
165
+ charger.socket_1.status.release_max_current() # lapses to the safe current
166
+ ```
167
+
168
+ Each `async_update()` that polls a socket with a held setpoint decides from
169
+ what it just read:
170
+
171
+ - **Resend** when the time left is at most twice the gap since the previous
172
+ poll, so one more poll would still arrive before the setpoint lapses. A
173
+ reboot or lapse leaves 0 s, so it resends then too. Any poll interval works,
174
+ provided it is shorter than the validity time; with 10 s polls and the
175
+ default 60 s, that is one write about every 40 s.
176
+ - **Step back** when the station reports a different max current with time
177
+ still left: another Modbus client wrote it. The hold is dropped and the
178
+ socket listed in the report's `setpoint_taken_over`. A second client
179
+ writing the same value cannot be told apart, and does no harm.
180
+ - **Do nothing** otherwise.
181
+
182
+ Holding the value already held writes nothing, so an automation can set it as
183
+ often as it likes. A new value is written at once, with no rate limit: smooth
184
+ fast changes in the caller. A write updates the cached `max_current` straight
185
+ away, so a UI can show it without another poll. If a hold's write fails, the
186
+ hold stays and the next poll retries it. A failed resend is listed in the
187
+ report's `rewrite_failed`, apart from the reads in `failed`.
188
+
189
+ A hold lives in memory. After a restart nothing is resent, and the station
190
+ falls back to its safe current once the validity time runs out.
191
+
192
+ Only polled components are resent, so a caller holding an SCN phase must poll
193
+ `charger.scn` as well as the sockets. `held_max_current` is the value held, or
194
+ `None`. The SCN holds each phase on its own, with the same methods taking a
195
+ `Phase`: `async_hold_max_current(phase, amps)`, `held_max_current(phase)` and
196
+ `release_max_current(phase)`. Each phase has its own remaining time and is
197
+ written in its own request, so one phase taken over leaves the others held.
198
+
199
+ ## Public API
200
+
201
+ The public API is every name `alfen_modbus` exports in its `__all__`. Import
202
+ from there and nothing else: the submodules, and any name starting with an
203
+ underscore, are internal and can move in any release.
204
+
205
+ From 1.0 on, releases follow [semantic versioning](https://semver.org): a
206
+ change that breaks the public API needs a major version.
207
+
208
+ ## Checking a real station
209
+
210
+ `script/query.py` reads one station once and prints every value it serves,
211
+ which is the quickest way to see whether a station is reachable, has Modbus
212
+ switched on, and is detected with the sockets you expect. It writes nothing
213
+ unless given `--hold`.
214
+
215
+ ```bash
216
+ # every value, per component
217
+ uv run script/query.py 192.168.1.60
218
+ # every register read as well, undecoded, for an issue report
219
+ uv run script/query.py 192.168.1.60 --raw
220
+ # check addressing and word order; needs no working register map
221
+ uv run script/query.py 192.168.1.60 --probe
222
+ # any range, undecoded: unit 200, registers 1100 to 1105
223
+ uv run script/query.py 192.168.1.60 --registers 200:1100:6
224
+ # WRITES: hold 10 A on socket 1 for 3 minutes, then let it lapse
225
+ uv run script/query.py 192.168.1.60 --hold 10 --seconds 180
226
+ ```
227
+
228
+ A station that answers nothing at all may still have Active Load Balancing off,
229
+ or a changed setting not yet applied by a restart (see
230
+ [Station setup](#station-setup)). Components that failed are listed after
231
+ the values, with their error. `--raw` adds every register it read as
232
+ JSON, which is the most helpful thing to include in an issue about a wrong
233
+ value. `--registers UNIT:ADDR[:COUNT]` reads any range, up to 125 registers,
234
+ and still runs when setup fails.
235
+
236
+ `--hold AMPS` needs **Energy Management System** as the data source. It holds
237
+ the max current on `--socket` (1 by default) for `--seconds`, polling every
238
+ `--interval` (10 s), then releases it and keeps polling until the station falls
239
+ back to its safe current. Each line shows the setpoint, the time it has left,
240
+ the applied current and whether the station accounted for it; `renewed` marks a
241
+ resend.
242
+
243
+ ## Debug logging
244
+
245
+ The `alfen_modbus` logger says, at `DEBUG`, why a station is polled the way it
246
+ is and what happened to a held setpoint:
247
+
248
+ - what setup found: the platform, firmware, socket count, and whether the
249
+ station serves the Smart Charging Network block
250
+ - every resend of a held setpoint, and a resend that failed
251
+ - a hold dropped because another client wrote a different max current
252
+
253
+ Each line names the station by serial number. A hold left in force logs
254
+ nothing, so a quiet log at 10 s polls is normal.
255
+
256
+ `query.py --debug` prints this log along with tmodbus's, which shows every raw
257
+ Modbus frame sent and received.
258
+
259
+ ## Addressing and word order
260
+
261
+ Alfen's guide and the station disagree on two points, and the library follows
262
+ the station (firmware 7.4.6):
263
+
264
+ - **Addressing.** The guide says to subtract 1 from each register number; the
265
+ station serves them as listed (300 is address 300).
266
+ - **Word order.** The guide says 32-bit values send the low word first; the
267
+ station sends the high word first.
268
+
269
+ If another firmware reads wrong, `query.py --probe` checks both in one run,
270
+ without the library's map having to work: it reads known strings and numbers
271
+ both one register lower and as listed, and decodes each number in both word
272
+ orders. Addressing comes first, from the strings: under the wrong guess a string
273
+ loses its first two characters or starts with a junk word. A float whose low
274
+ word is zero, such as 16.0, can read right under both guesses, so only the
275
+ strings decide it. Under the right addressing, one word order gives plausible
276
+ numbers and the other absurd ones.
277
+
278
+ ## Register map source
279
+
280
+ Alfen *Modbus for ACE, Configuration Guide*, version 1.0 (May 2025), for ACE
281
+ Service Installer 3.4.10-130 and firmware 4.10. The guide gives no data types for
282
+ the station status block (1100 to 1105); those were settled from observed station
283
+ behaviour and checked on firmware 7.4.6. Alfen's copyright forbids
284
+ redistributing the guide, so it is not in this repository.
285
+
286
+ ## Development
287
+
288
+ ```bash
289
+ uv sync
290
+ uv run pytest
291
+ uv run mypy
292
+ uv run ruff check .
293
+ uv run ruff format --check .
294
+ ```
295
+
296
+ `pytest` fails below 100% branch coverage. See [RELEASING.md](RELEASING.md) for
297
+ publishing.
298
+
299
+ ## License
300
+
301
+ [Apache-2.0](LICENSE).