Skip to content

dimm kit: modbus client context manager, type hints - #3848

Merged
LKuemmel merged 9 commits into
openWB:masterfrom
LKuemmel:feature_dimm_kit
Aug 26, 2026
Merged

LKuemmel merged 9 commits into
openWB:masterfrom
LKuemmel:feature_dimm_kit

Conversation

@LKuemmel

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@LKuemmel
LKuemmel requested a review from benderl August 24, 2026 09:57
Comment on lines +75 to +80
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

@LKuemmel LKuemmel changed the title dimm kit: modbus client context manager dimm kit: modbus client context manager, type hints Aug 26, 2026
@LKuemmel
LKuemmel requested a balanced review from Copilot August 26, 2026 12:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IndexError for 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)

Comment thread packages/modules/common/modbus.py Resolved
@LKuemmel
LKuemmel requested a review from benderl August 26, 2026 12:39
@LKuemmel
LKuemmel merged commit 365ca5b into openWB:master Aug 26, 2026
1 check passed
@LKuemmel
LKuemmel deleted the feature_dimm_kit branch August 26, 2026 12:42
Brett-S-OWB pushed a commit that referenced this pull request Sep 2, 2026
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants