Skip to content

dimm kit: modbus client context manager - #3848

Open
LKuemmel wants to merge 2 commits into
openWB:masterfrom
LKuemmel:feature_dimm_kit
Open

dimm kit: modbus client context manager#3848
LKuemmel wants to merge 2 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.

Comment on lines 62 to 66
def write(analog_output: Optional[Dict[str, int]], digital_output: Optional[Dict[str, bool]]) -> None:
for i, value in digital_output.items():
client.write_single_coil(DigitalOutputMapping[i].value, 1 if value is True else 0,
with client:
for i, value in digital_output.items():
client.write_single_coil(DigitalOutputMapping[i].value, 1 if value is True else 0,
unit=config.configuration.modbus_id)
@LKuemmel
LKuemmel requested a review from benderl August 24, 2026 09:57
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.

2 participants