Repository navigation
dimm kit: modbus client context manager, type hints - #3848
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the dimm kit IO module to use the Modbus TCP client as a context manager, ensuring Modbus connections are opened/closed in a controlled scope during reads/writes.
Changes:
- Wrap Modbus read operations in
with client:to leverage__enter__/__exit__lifecycle handling. - Wrap Modbus write operations (including initializer output setup) in
with client:for consistent connection handling. - Add small inter-call delays (
time.sleep(0.1)) around IO operations (notably during initializer output writes).
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| with client: | ||
| for output, value in config.output["digital"].items(): | ||
| time.sleep(0.1) | ||
| client.write_single_coil(DigitalOutputMapping[output].value, | ||
| value, | ||
| unit=config.configuration.modbus_id) |
There was a problem hiding this comment.
Wäre es nicht sinnvoller, hier auch write() aufzurufen? Der Code ist identisch, abgesehen davon, dass hier noch ein sleep zwischen den Aufrufen gibt, was aber anscheinend nicht notwendig ist, siehe write().
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Suppressed comments (1)
packages/modules/io_devices/dimm_kit/api.py:78
- The configured digital-output mapping is not validated as non-empty, contiguous, or enum-ordered. This now raises
IndexErrorfor an empty mapping and can write values to the wrong coils for sparse/out-of-order persisted configurations; the previous per-key loop handled all of these valid dictionary shapes.
client.write_coils(DigitalOutputMapping[list(config.output["digital"].keys())[0]].value,
list(config.output["digital"].values()),
unit=config.configuration.modbus_id)
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
…nto feature_dimm_kit
* dimm kit: modbus client dimm kit * review * type hints * review * fix * don't reinit io device if io action is reconfigured * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <[email protected]> * review --------- Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Ticket #66006528
ersetzt https://github.com/openWB/core/tree/feature_dimm_kit_base_release für den PR