grundfos-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.
- grundfos_modbus-0.1.0/.gitattributes +1 -0
- grundfos_modbus-0.1.0/.github/renovate.json +47 -0
- grundfos_modbus-0.1.0/.github/workflows/ci.yml +36 -0
- grundfos_modbus-0.1.0/.github/workflows/publish.yml +52 -0
- grundfos_modbus-0.1.0/.gitignore +10 -0
- grundfos_modbus-0.1.0/LICENSE +24 -0
- grundfos_modbus-0.1.0/PKG-INFO +135 -0
- grundfos_modbus-0.1.0/README.md +119 -0
- grundfos_modbus-0.1.0/RELEASING.md +26 -0
- grundfos_modbus-0.1.0/pyproject.toml +61 -0
- grundfos_modbus-0.1.0/script/query.py +95 -0
- grundfos_modbus-0.1.0/src/grundfos_modbus/__init__.py +36 -0
- grundfos_modbus-0.1.0/src/grundfos_modbus/_decode.py +44 -0
- grundfos_modbus-0.1.0/src/grundfos_modbus/cim.py +95 -0
- grundfos_modbus-0.1.0/src/grundfos_modbus/data.py +159 -0
- grundfos_modbus-0.1.0/src/grundfos_modbus/device.py +49 -0
- grundfos_modbus-0.1.0/src/grundfos_modbus/enums.py +195 -0
- grundfos_modbus-0.1.0/src/grundfos_modbus/py.typed +0 -0
- grundfos_modbus-0.1.0/src/grundfos_modbus/status.py +114 -0
- grundfos_modbus-0.1.0/tests/__init__.py +0 -0
- grundfos_modbus-0.1.0/tests/conftest.py +145 -0
- grundfos_modbus-0.1.0/tests/test_device.py +183 -0
- grundfos_modbus-0.1.0/uv.lock +456 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
3
|
+
"description": "Renovate configuration for grundfos-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,36 @@
|
|
|
1
|
+
# Written by Claude, guided by Chris.
|
|
2
|
+
name: CI
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
pull_request:
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
lint:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
18
|
+
- uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
|
|
19
|
+
- name: Install dependencies
|
|
20
|
+
run: uv sync
|
|
21
|
+
- name: Ruff format
|
|
22
|
+
run: uv run ruff format --check .
|
|
23
|
+
- name: Ruff lint
|
|
24
|
+
run: uv run ruff check .
|
|
25
|
+
- name: Mypy
|
|
26
|
+
run: uv run mypy
|
|
27
|
+
|
|
28
|
+
test:
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
32
|
+
- uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
|
|
33
|
+
- name: Install dependencies
|
|
34
|
+
run: uv sync
|
|
35
|
+
- name: Run tests
|
|
36
|
+
run: uv run pytest
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Written by Claude, guided by Chris.
|
|
2
|
+
name: Publish to PyPI
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
release:
|
|
6
|
+
types: [published]
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
inputs:
|
|
9
|
+
tag:
|
|
10
|
+
description: Existing release tag to build and publish (e.g. 4.0.1)
|
|
11
|
+
required: true
|
|
12
|
+
type: string
|
|
13
|
+
|
|
14
|
+
env:
|
|
15
|
+
RELEASE_TAG: ${{ inputs.tag || github.event.release.tag_name }}
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
build:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
permissions:
|
|
21
|
+
contents: read
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
24
|
+
with:
|
|
25
|
+
ref: ${{ env.RELEASE_TAG }}
|
|
26
|
+
- uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
|
|
27
|
+
- name: Set package version from release tag
|
|
28
|
+
run: |
|
|
29
|
+
VERSION="${RELEASE_TAG#v}"
|
|
30
|
+
sed -i "s/^version = \"0\\.0\\.0\"$/version = \"${VERSION}\"/" pyproject.toml
|
|
31
|
+
- name: Verify the version was substituted
|
|
32
|
+
run: |
|
|
33
|
+
VERSION="${RELEASE_TAG#v}"
|
|
34
|
+
grep -qx "version = \"${VERSION}\"" pyproject.toml
|
|
35
|
+
- run: uv build
|
|
36
|
+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
|
37
|
+
with:
|
|
38
|
+
name: dist
|
|
39
|
+
path: dist/
|
|
40
|
+
|
|
41
|
+
publish:
|
|
42
|
+
needs: build
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
environment: pypi
|
|
45
|
+
permissions:
|
|
46
|
+
id-token: write
|
|
47
|
+
steps:
|
|
48
|
+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
49
|
+
with:
|
|
50
|
+
name: dist
|
|
51
|
+
path: dist/
|
|
52
|
+
- uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: grundfos-modbus
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Read Grundfos MAGNA3 circulators and other E-pumps through a CIM 200/500 Modbus module.
|
|
5
|
+
Project-URL: Homepage, https://github.com/cwm12345/grundfos-modbus
|
|
6
|
+
Author: grundfos-modbus contributors
|
|
7
|
+
License: Unlicense
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: cim500,grundfos,hvac,magna3,modbus,pump
|
|
10
|
+
Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Home Automation
|
|
13
|
+
Requires-Python: >=3.12
|
|
14
|
+
Requires-Dist: modbus-connection[tmodbus]>=4.12.1
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
<!-- Written by Claude, guided by Chris. -->
|
|
18
|
+
|
|
19
|
+
# grundfos-modbus
|
|
20
|
+
|
|
21
|
+
Read Grundfos pumps through a CIM 200 / CIM 500 Modbus module, as typed Python
|
|
22
|
+
objects, on top of
|
|
23
|
+
[modbus-connection](https://github.com/home-assistant-libs/modbus-connection).
|
|
24
|
+
|
|
25
|
+
## Supported devices
|
|
26
|
+
|
|
27
|
+
The register map is Grundfos' "Modbus for Grundfos pumps" functional profile
|
|
28
|
+
(document 6012947), which covers MAGNA3 and MAGNA3-D circulators, E-pumps with
|
|
29
|
+
MGE motors (TPE, NBE, NKE, CRE and so on) and CUE drives, fitted with a CIM
|
|
30
|
+
200 (Modbus RTU) or CIM 500 (Modbus TCP) module.
|
|
31
|
+
|
|
32
|
+
It has been run against one **MAGNA3 40-80 F with a CIM 500** on Modbus TCP.
|
|
33
|
+
Other pumps in the profile should work but are untested.
|
|
34
|
+
|
|
35
|
+
## CIM 500 setup notes
|
|
36
|
+
|
|
37
|
+
- Set the module's rotary switch to **1 (Modbus TCP)**. It ships at 0
|
|
38
|
+
(PROFINET), where its IP fields are read-only. Changing the switch resets the
|
|
39
|
+
module's network settings to the factory address.
|
|
40
|
+
- The module has two addresses: the **web server** (factory 192.168.1.100,
|
|
41
|
+
login admin / Grundfos, which forces a new password) and a separate
|
|
42
|
+
**Modbus TCP** address, set on the "Real Time Ethernet Protocol" page once
|
|
43
|
+
the switch is at 1. Modbus is on port 502; the unit ID is ignored.
|
|
44
|
+
- The module is powered by the pump. If the pump's supply is switched (by a
|
|
45
|
+
zone relay, say), the module is unreachable whenever the pump is off.
|
|
46
|
+
|
|
47
|
+
## What it covers
|
|
48
|
+
|
|
49
|
+
| Component | Registers | What |
|
|
50
|
+
| :--- | :--- | :--- |
|
|
51
|
+
| `cim` | 00021-00037 | Module version, GENIbus link counters, the product's unit family/type (decoded to a name such as "MAGNA3"), product software version and date |
|
|
52
|
+
| `status` | 00201-00225 | Status bits (on, rotating, alarm, warning, at max speed...), process feedback, control and operating mode, alarm and warning codes, feedback sensor unit and range, frequency limits, setpoint range, flow-estimation state, PI gains, control source |
|
|
53
|
+
| `data` | 00301-00362 | Head, flow, relative performance, speed, frequency, setpoints, motor current, DC-link voltage, power, temperatures, specific energy, operating/powered hours, energy, starts, differential and remote pressures, flow limit, the heat meter and pumped volume |
|
|
54
|
+
|
|
55
|
+
Each component is one block read, three requests per update. The module
|
|
56
|
+
answers both function code 3 and 4 for these blocks; this library uses 3.
|
|
57
|
+
|
|
58
|
+
Decoding conventions:
|
|
59
|
+
|
|
60
|
+
- A register the pump doesn't supply reads 0xFFFF (0xFFFFFFFF for 32-bit
|
|
61
|
+
values) and decodes to `None`.
|
|
62
|
+
- Temperatures arrive in hundredths of a kelvin and decode to °C.
|
|
63
|
+
- Codes decode to `ControlMode`, `OperationMode`, `AlarmCode`,
|
|
64
|
+
`ControlSource`, `FlowEstimationState` and `FeedbackSensorUnit`; a code the
|
|
65
|
+
profile doesn't list stays a plain `int`. Status bits decode to the
|
|
66
|
+
`PumpStatus` flag.
|
|
67
|
+
- `data.has_heat_meter` is true only when heat power is available. Without a
|
|
68
|
+
second temperature sensor the heat energy counters read 0, not "not
|
|
69
|
+
available".
|
|
70
|
+
|
|
71
|
+
## Read-only
|
|
72
|
+
|
|
73
|
+
The profile has a control block (00101-00112: remote/local, on/off, control
|
|
74
|
+
mode, setpoint, flow limit). This library doesn't write it. Taking a pump
|
|
75
|
+
into remote control is a decision for whoever wires it up, not a default.
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
|
|
79
|
+
Not on PyPI yet. Install from GitHub:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
pip install git+https://github.com/cwm12345/grundfos-modbus
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
For Home Assistant, you don't need this directly: use the
|
|
86
|
+
[ha-grundfos](https://github.com/cwm12345/ha-grundfos) integration, which
|
|
87
|
+
includes a copy.
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import asyncio
|
|
93
|
+
|
|
94
|
+
from modbus_connection import ModbusTcpParams
|
|
95
|
+
from modbus_connection.tmodbus import ModbusConnection
|
|
96
|
+
from grundfos_modbus import GrundfosPump
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
async def main() -> None:
|
|
100
|
+
connection = ModbusConnection(ModbusTcpParams(host="192.168.1.50", port=502))
|
|
101
|
+
try:
|
|
102
|
+
pump = GrundfosPump(connection.for_unit(1))
|
|
103
|
+
await pump.async_update()
|
|
104
|
+
print(pump.cim.product, pump.status.control_mode)
|
|
105
|
+
print(
|
|
106
|
+
pump.data.volume_flow,
|
|
107
|
+
"m³/h at",
|
|
108
|
+
pump.data.head,
|
|
109
|
+
"bar,",
|
|
110
|
+
pump.data.power,
|
|
111
|
+
"W",
|
|
112
|
+
)
|
|
113
|
+
finally:
|
|
114
|
+
await connection.close()
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
asyncio.run(main())
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Or from the command line: `uv run script/query.py 192.168.1.50`.
|
|
121
|
+
|
|
122
|
+
## Development
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
uv sync
|
|
126
|
+
uv run pytest
|
|
127
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The tests run against modbus-connection's in-memory mock backend, seeded with
|
|
131
|
+
registers captured from a live MAGNA3. No hardware is needed.
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
[Unlicense](LICENSE): public domain.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<!-- Written by Claude, guided by Chris. -->
|
|
2
|
+
|
|
3
|
+
# grundfos-modbus
|
|
4
|
+
|
|
5
|
+
Read Grundfos pumps through a CIM 200 / CIM 500 Modbus module, as typed Python
|
|
6
|
+
objects, on top of
|
|
7
|
+
[modbus-connection](https://github.com/home-assistant-libs/modbus-connection).
|
|
8
|
+
|
|
9
|
+
## Supported devices
|
|
10
|
+
|
|
11
|
+
The register map is Grundfos' "Modbus for Grundfos pumps" functional profile
|
|
12
|
+
(document 6012947), which covers MAGNA3 and MAGNA3-D circulators, E-pumps with
|
|
13
|
+
MGE motors (TPE, NBE, NKE, CRE and so on) and CUE drives, fitted with a CIM
|
|
14
|
+
200 (Modbus RTU) or CIM 500 (Modbus TCP) module.
|
|
15
|
+
|
|
16
|
+
It has been run against one **MAGNA3 40-80 F with a CIM 500** on Modbus TCP.
|
|
17
|
+
Other pumps in the profile should work but are untested.
|
|
18
|
+
|
|
19
|
+
## CIM 500 setup notes
|
|
20
|
+
|
|
21
|
+
- Set the module's rotary switch to **1 (Modbus TCP)**. It ships at 0
|
|
22
|
+
(PROFINET), where its IP fields are read-only. Changing the switch resets the
|
|
23
|
+
module's network settings to the factory address.
|
|
24
|
+
- The module has two addresses: the **web server** (factory 192.168.1.100,
|
|
25
|
+
login admin / Grundfos, which forces a new password) and a separate
|
|
26
|
+
**Modbus TCP** address, set on the "Real Time Ethernet Protocol" page once
|
|
27
|
+
the switch is at 1. Modbus is on port 502; the unit ID is ignored.
|
|
28
|
+
- The module is powered by the pump. If the pump's supply is switched (by a
|
|
29
|
+
zone relay, say), the module is unreachable whenever the pump is off.
|
|
30
|
+
|
|
31
|
+
## What it covers
|
|
32
|
+
|
|
33
|
+
| Component | Registers | What |
|
|
34
|
+
| :--- | :--- | :--- |
|
|
35
|
+
| `cim` | 00021-00037 | Module version, GENIbus link counters, the product's unit family/type (decoded to a name such as "MAGNA3"), product software version and date |
|
|
36
|
+
| `status` | 00201-00225 | Status bits (on, rotating, alarm, warning, at max speed...), process feedback, control and operating mode, alarm and warning codes, feedback sensor unit and range, frequency limits, setpoint range, flow-estimation state, PI gains, control source |
|
|
37
|
+
| `data` | 00301-00362 | Head, flow, relative performance, speed, frequency, setpoints, motor current, DC-link voltage, power, temperatures, specific energy, operating/powered hours, energy, starts, differential and remote pressures, flow limit, the heat meter and pumped volume |
|
|
38
|
+
|
|
39
|
+
Each component is one block read, three requests per update. The module
|
|
40
|
+
answers both function code 3 and 4 for these blocks; this library uses 3.
|
|
41
|
+
|
|
42
|
+
Decoding conventions:
|
|
43
|
+
|
|
44
|
+
- A register the pump doesn't supply reads 0xFFFF (0xFFFFFFFF for 32-bit
|
|
45
|
+
values) and decodes to `None`.
|
|
46
|
+
- Temperatures arrive in hundredths of a kelvin and decode to °C.
|
|
47
|
+
- Codes decode to `ControlMode`, `OperationMode`, `AlarmCode`,
|
|
48
|
+
`ControlSource`, `FlowEstimationState` and `FeedbackSensorUnit`; a code the
|
|
49
|
+
profile doesn't list stays a plain `int`. Status bits decode to the
|
|
50
|
+
`PumpStatus` flag.
|
|
51
|
+
- `data.has_heat_meter` is true only when heat power is available. Without a
|
|
52
|
+
second temperature sensor the heat energy counters read 0, not "not
|
|
53
|
+
available".
|
|
54
|
+
|
|
55
|
+
## Read-only
|
|
56
|
+
|
|
57
|
+
The profile has a control block (00101-00112: remote/local, on/off, control
|
|
58
|
+
mode, setpoint, flow limit). This library doesn't write it. Taking a pump
|
|
59
|
+
into remote control is a decision for whoever wires it up, not a default.
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
Not on PyPI yet. Install from GitHub:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
pip install git+https://github.com/cwm12345/grundfos-modbus
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
For Home Assistant, you don't need this directly: use the
|
|
70
|
+
[ha-grundfos](https://github.com/cwm12345/ha-grundfos) integration, which
|
|
71
|
+
includes a copy.
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import asyncio
|
|
77
|
+
|
|
78
|
+
from modbus_connection import ModbusTcpParams
|
|
79
|
+
from modbus_connection.tmodbus import ModbusConnection
|
|
80
|
+
from grundfos_modbus import GrundfosPump
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
async def main() -> None:
|
|
84
|
+
connection = ModbusConnection(ModbusTcpParams(host="192.168.1.50", port=502))
|
|
85
|
+
try:
|
|
86
|
+
pump = GrundfosPump(connection.for_unit(1))
|
|
87
|
+
await pump.async_update()
|
|
88
|
+
print(pump.cim.product, pump.status.control_mode)
|
|
89
|
+
print(
|
|
90
|
+
pump.data.volume_flow,
|
|
91
|
+
"m³/h at",
|
|
92
|
+
pump.data.head,
|
|
93
|
+
"bar,",
|
|
94
|
+
pump.data.power,
|
|
95
|
+
"W",
|
|
96
|
+
)
|
|
97
|
+
finally:
|
|
98
|
+
await connection.close()
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
asyncio.run(main())
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Or from the command line: `uv run script/query.py 192.168.1.50`.
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
uv sync
|
|
110
|
+
uv run pytest
|
|
111
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The tests run against modbus-connection's in-memory mock backend, seeded with
|
|
115
|
+
registers captured from a live MAGNA3. No hardware is needed.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
[Unlicense](LICENSE): public domain.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!-- Written by Claude, guided by Chris. -->
|
|
2
|
+
|
|
3
|
+
# Releasing `grundfos-modbus`
|
|
4
|
+
|
|
5
|
+
This document describes how to release a new version of `grundfos-modbus` to PyPI.
|
|
6
|
+
|
|
7
|
+
## Tagging Convention
|
|
8
|
+
|
|
9
|
+
> [!IMPORTANT]
|
|
10
|
+
> **Release tags must be bare semantic versions without a leading `v`** (e.g. `0.1.5`, `1.0.0`).
|
|
11
|
+
> Do not use `v`-prefixed tags like `v0.1.5`.
|
|
12
|
+
|
|
13
|
+
Release tags are directly substituted into `pyproject.toml` during the release workflow to set the package version according to PEP 440.
|
|
14
|
+
|
|
15
|
+
## Release Process
|
|
16
|
+
|
|
17
|
+
1. **Verify CI**: Ensure that the `CI` workflow is green on the `main` branch.
|
|
18
|
+
2. **Draft a GitHub Release**:
|
|
19
|
+
- Go to GitHub Releases: **Draft a new release**.
|
|
20
|
+
- **Choose a tag**: Enter the new version number as a bare tag (e.g. `0.1.5`).
|
|
21
|
+
- **Target**: `main`.
|
|
22
|
+
- **Title**: Enter the version number (e.g. `0.1.5`).
|
|
23
|
+
- **Description**: Provide release notes / changelog.
|
|
24
|
+
3. **Publish the Release**:
|
|
25
|
+
- Click **Publish release**.
|
|
26
|
+
- The `.github/workflows/publish.yml` workflow will automatically trigger, build the wheel and source distribution, and publish the package to PyPI via Trusted Publishing.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Written by Claude, guided by Chris.
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = ["hatchling"]
|
|
4
|
+
build-backend = "hatchling.build"
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "grundfos-modbus"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
description = "Read Grundfos MAGNA3 circulators and other E-pumps through a CIM 200/500 Modbus module."
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
license = { text = "Unlicense" }
|
|
13
|
+
authors = [{ name = "grundfos-modbus contributors" }]
|
|
14
|
+
keywords = ["modbus", "grundfos", "magna3", "cim500", "pump", "hvac"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"License :: OSI Approved :: The Unlicense (Unlicense)",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Topic :: Home Automation",
|
|
19
|
+
]
|
|
20
|
+
# The caller injects a ModbusUnit; tmodbus is the backend this is exercised against.
|
|
21
|
+
dependencies = ["modbus-connection[tmodbus]>=4.12.1"]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://github.com/cwm12345/grundfos-modbus"
|
|
25
|
+
|
|
26
|
+
[dependency-groups]
|
|
27
|
+
dev = [
|
|
28
|
+
"mypy>=1.11",
|
|
29
|
+
"pytest>=8",
|
|
30
|
+
"pytest-asyncio>=0.24",
|
|
31
|
+
"ruff>=0.6",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[tool.hatch.build.targets.wheel]
|
|
35
|
+
packages = ["src/grundfos_modbus"]
|
|
36
|
+
|
|
37
|
+
[tool.pytest.ini_options]
|
|
38
|
+
asyncio_mode = "auto"
|
|
39
|
+
testpaths = ["tests"]
|
|
40
|
+
|
|
41
|
+
[tool.ruff]
|
|
42
|
+
target-version = "py312"
|
|
43
|
+
src = ["src"]
|
|
44
|
+
|
|
45
|
+
[tool.ruff.lint]
|
|
46
|
+
select = ["E", "F", "W", "I", "UP", "B", "D"]
|
|
47
|
+
# D401 wants imperative docstrings; this codebase names things, matching
|
|
48
|
+
# modbus-connection's own style. D107 is covered by the class docstring.
|
|
49
|
+
ignore = ["D107", "D401"]
|
|
50
|
+
|
|
51
|
+
[tool.ruff.lint.pydocstyle]
|
|
52
|
+
convention = "pep257"
|
|
53
|
+
|
|
54
|
+
[tool.ruff.lint.per-file-ignores]
|
|
55
|
+
# A test's name is its documentation; docstrings are for the ones that need a why.
|
|
56
|
+
"tests/*" = ["D100", "D103", "D104"]
|
|
57
|
+
|
|
58
|
+
[tool.mypy]
|
|
59
|
+
python_version = "3.12"
|
|
60
|
+
files = ["src", "tests", "script"]
|
|
61
|
+
strict = true
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# Written by Claude, guided by Chris.
|
|
3
|
+
|
|
4
|
+
"""Query a Grundfos pump through a CIM Modbus module and print every value."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import asyncio
|
|
10
|
+
import json
|
|
11
|
+
import logging
|
|
12
|
+
|
|
13
|
+
from modbus_connection import ModbusError
|
|
14
|
+
from modbus_connection.cli_helper import (
|
|
15
|
+
CountingUnit,
|
|
16
|
+
add_connection_args,
|
|
17
|
+
connect_from_args,
|
|
18
|
+
print_component,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
from grundfos_modbus import COMPONENTS, GrundfosPump
|
|
22
|
+
|
|
23
|
+
# A CIM 500 answers Modbus TCP; a CIM 200 is Modbus RTU on RS-485, directly or
|
|
24
|
+
# through a serial server. Both framers are named on purpose: offered a single
|
|
25
|
+
# framer, cli_helper defaults every transport to it.
|
|
26
|
+
CONNECTIONS = (("tcp", "socket"), ("serial", "rtu"))
|
|
27
|
+
|
|
28
|
+
EXAMPLES = """examples:
|
|
29
|
+
uv run script/query.py 192.168.1.50
|
|
30
|
+
uv run script/query.py /dev/ttyUSB0 --transport serial --baudrate 19200 --raw
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
async def main() -> int:
|
|
35
|
+
"""Read one pump and print it."""
|
|
36
|
+
logging.getLogger().addHandler(logging.NullHandler())
|
|
37
|
+
|
|
38
|
+
parser = argparse.ArgumentParser(
|
|
39
|
+
description=__doc__,
|
|
40
|
+
epilog=EXAMPLES,
|
|
41
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
42
|
+
)
|
|
43
|
+
add_connection_args(parser, connections=CONNECTIONS)
|
|
44
|
+
parser.add_argument(
|
|
45
|
+
"--unit", type=int, default=1, help="Modbus unit id (ignored by a CIM 500)"
|
|
46
|
+
)
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"--raw", action="store_true", help="also dump every register read, as JSON"
|
|
49
|
+
)
|
|
50
|
+
args = parser.parse_args()
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
connection = await connect_from_args(args)
|
|
54
|
+
except ModbusError as err:
|
|
55
|
+
print(f"Could not connect to {args.target}: {str(err) or type(err).__name__}")
|
|
56
|
+
return 1
|
|
57
|
+
|
|
58
|
+
counting = CountingUnit(connection.for_unit(args.unit))
|
|
59
|
+
pump = GrundfosPump(counting)
|
|
60
|
+
try:
|
|
61
|
+
report = await pump.async_update()
|
|
62
|
+
reads = counting.reads
|
|
63
|
+
raw = await pump.async_read_raw() if args.raw else None
|
|
64
|
+
except ModbusError as err:
|
|
65
|
+
print(f"Could not read the pump: {str(err) or type(err).__name__}")
|
|
66
|
+
return 1
|
|
67
|
+
finally:
|
|
68
|
+
await connection.close()
|
|
69
|
+
|
|
70
|
+
for name in COMPONENTS:
|
|
71
|
+
print()
|
|
72
|
+
print_component(getattr(pump, name), title=name)
|
|
73
|
+
|
|
74
|
+
c, s, d = pump.cim, pump.status, pump.data
|
|
75
|
+
print("\nDecoded")
|
|
76
|
+
print(f" product {c.product} (CIM {c.version})")
|
|
77
|
+
print(f" status {s.flags!r}")
|
|
78
|
+
print(f" control mode {s.control_mode!r}")
|
|
79
|
+
print(f" operation mode {s.operation_mode!r}")
|
|
80
|
+
print(f" alarm / warning {s.alarm!r} / {s.warning!r}")
|
|
81
|
+
print(f" flow / head {d.volume_flow} m³/h / {d.head} bar")
|
|
82
|
+
print(f" power / speed {d.power} W / {d.speed} rpm")
|
|
83
|
+
print(f" liquid {d.liquid_temperature} °C")
|
|
84
|
+
if report.failed:
|
|
85
|
+
print("\nFailed to read:")
|
|
86
|
+
for name, error in report.failed.items():
|
|
87
|
+
print(f" {name}: {str(error) or type(error).__name__}")
|
|
88
|
+
if raw is not None:
|
|
89
|
+
print("\nRaw registers")
|
|
90
|
+
print(json.dumps(raw, indent=2))
|
|
91
|
+
print(f"\n{reads} Modbus reads")
|
|
92
|
+
return 0
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
raise SystemExit(asyncio.run(main()))
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Written by Claude, guided by Chris.
|
|
2
|
+
"""Read Grundfos pumps through a CIM Modbus module, as typed objects."""
|
|
3
|
+
|
|
4
|
+
from .cim import PRODUCTS, Cim
|
|
5
|
+
from .data import Data
|
|
6
|
+
from .device import COMPONENTS, GrundfosPump
|
|
7
|
+
from .enums import (
|
|
8
|
+
NOT_AVAILABLE,
|
|
9
|
+
NOT_AVAILABLE_32,
|
|
10
|
+
AlarmCode,
|
|
11
|
+
ControlMode,
|
|
12
|
+
ControlSource,
|
|
13
|
+
FeedbackSensorUnit,
|
|
14
|
+
FlowEstimationState,
|
|
15
|
+
OperationMode,
|
|
16
|
+
PumpStatus,
|
|
17
|
+
)
|
|
18
|
+
from .status import Status
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"COMPONENTS",
|
|
22
|
+
"NOT_AVAILABLE",
|
|
23
|
+
"NOT_AVAILABLE_32",
|
|
24
|
+
"PRODUCTS",
|
|
25
|
+
"AlarmCode",
|
|
26
|
+
"Cim",
|
|
27
|
+
"ControlMode",
|
|
28
|
+
"ControlSource",
|
|
29
|
+
"Data",
|
|
30
|
+
"FeedbackSensorUnit",
|
|
31
|
+
"FlowEstimationState",
|
|
32
|
+
"GrundfosPump",
|
|
33
|
+
"OperationMode",
|
|
34
|
+
"PumpStatus",
|
|
35
|
+
"Status",
|
|
36
|
+
]
|