Repository navigation
Modbus: verbleibende ungesperrte Delegate-Zugriffe schliessen - #3947
Merged
LKuemmel merged 2 commits intoSep 16, 2026
Merged
Conversation
…iessen Follow-up zu openWB#3895 - Copilot-Review deckte auf, dass die neue Verbindungs- sperre in ModbusClient nur die eigenen Wrapper-Methoden schuetzt, waehrend drei Stellen direkt an self._delegate/.delegate vorbeigreifen und die Sperre damit umgehen: - sungrow_sh/bat.py: unnoetiger Roh-Zugriff fuer ein Bitfeld, das per ModbusDataType.UINT_16 identisch dekodiert werden kann - jetzt ueber den normalen, gesperrten Lesepfad. - marstek/venus_c_e/bat.py und openwb_series2_satellit/chargepoint_module.py (Phasenumschaltung) brauchten echtes FC06 (Write Single Register), das write_register() (FC16) nicht abbildet - dafuer gab es bisher keinen gesperrten Zugriffspfad. Neue Methode write_single_register_raw() schliesst diese Luecke.
3 tasks done
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
is_socket_open() still accesses the delegate without acquiring the shared lock.
Pull request overview
This follow-up secures remaining Modbus delegate accesses, adds locked FC06 writes, and expands retry coverage.
Changes:
- Routes Sungrow reads through the locked wrapper.
- Adds locked single-register writes for Marstek and phase switching.
- Broadens retry handling and adds regression tests.
File summaries
| File | Summary |
|---|---|
packages/modules/devices/sungrow/sungrow_sh/bat.py |
Uses the locked register-read path. |
packages/modules/devices/marstek/venus_c_e/bat.py |
Uses locked FC06 writes. |
packages/modules/common/modbus.py |
Adds locking and raw single-register writes. |
packages/modules/common/modbus_test.py |
Tests serialization and FC06 behavior. |
packages/modules/common/hardware_check.py |
Retries broader exception types. |
packages/modules/common/hardware_check_test.py |
Tests retry behavior. |
packages/modules/chargepoints/openwb_series2_satellit/chargepoint_module.py |
Uses locked phase-switch writes. |
Review details
Suppressed comments (1)
packages/modules/common/modbus.py:107
is_socket_open()still calls_delegate.is_socket_open()without acquiring_lock(line 97). The internal calls here are protected by the surroundingRLock, but the public method remains an unlocked delegate access, so a concurrent socket check can race withconnect()orclose()and violate the serialization this change introduces. Guardis_socket_open()with the same lock; theRLockkeeps these nested calls safe.
with self._lock:
if self.is_socket_open() is False:
self.connect()
- Files reviewed: 7/7 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up zu #3895 (siehe Review-Kommentar von Copilot).
Problem
Die neue Verbindungssperre in
ModbusClientschuetzt nur Aufrufe ueber die eigenen Wrapper-Methoden. Drei Stellen greifen direkt aufself._delegate/.delegatezu und umgehen die Sperre damit vollstaendig:sungrow_sh/bat.py:83- liest ein rohes Register fuer ein Bitfeldmarstek/venus_c_e/bat.py:38- braucht FC06,write_register()nutzt intern FC16openwb_series2_satellit/chargepoint_module.py(Phasenumschaltung) - selbes FC06-Problem, genau auf der Verbindung, fuer die die Sperre urspruenglich gedacht warFix
ModbusDataType.UINT_16liefert denselben Rohwert fuers Bitmasking)ModbusClient.write_single_register_raw()fuer echtes FC06, gesperrt - Marstek und die Phasenumschaltung nutzen sie jetzt statt des rohen Delegates