Repository navigation
fix(sungrow): stop polling SH hybrid registers on SG string inverters - #17
Conversation
SG string inverters answer the 5xxx PV registers but none of the SH hybrid block. The driver read 13019 and its neighbours on every model, so on an SG12RT 12 of 19 Modbus reads failed. Since the host started counting a poll as failed when any single read fails, the whole device went offline instead of reporting the PV it does have. Probe each model-specific register once, then skip the addresses this inverter does not answer, and emit the battery and meter streams only when the registers behind them responded. Battery commands are refused once a poll has proved the model has no battery block. Same pattern as the Pixii fix in #16. Signed-off-by: Fredrik Ahlgren <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d6c5faafaf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ok and registers ~= nil and registers[1] ~= nil then | ||
| return registers | ||
| end | ||
| absent_registers[address] = true |
There was a problem hiding this comment.
Retry transient failures before declaring registers absent
When a supported register has a one-off Modbus timeout, this unconditional cache marks it unsupported for the lifetime of the VM. A transient failure at 13000 therefore makes all subsequent battery discharge samples use status = 0 and report discharge as positive, while a transient failure at 13019 or the 56xx registers permanently removes battery or meter telemetry and rejects battery commands until restart; only definitive unsupported-address responses should be cached, while communication failures must remain retryable. The mirrored FTW target has the same logic.
AGENTS.md reference: AGENTS.md:L22-L24
Useful? React with 👍 / 👎.
…ilures The first version of this fix learned the register map by failing reads. That had two faults. It still spent one failed poll per absent register before settling, and any single timeout wrote a register off for the rest of the session, so a glitching bus could silence the battery on a healthy SH hybrid. Read the device type code at 4999 instead. 0x0D and 0x0E are the SH hybrid families; any other clean code is a string inverter, and the hybrid block is then never read at all. The same register already backs driver_fingerprint in the FTW baseline, so this is the identity the fleet already trusts. Probing remains only as a fallback for an unreadable type code, and now takes three consecutive failures before it writes a register off. Signed-off-by: Fredrik Ahlgren <[email protected]>
#17 changed drivers/lua/sungrow.lua, so the manifest hash this branch wrote no longer described the file. This is the guard working: make check caught it rather than letting main carry a manifest that lied. Signed-off-by: Fredrik Ahlgren <[email protected]>
…hes (#18) * feat: make the repository state the truth about the drivers it publishes Manifest sha256 and size_bytes were maintained by hand and had drifted: 60 of 62 manifests described bytes their driver no longer had, and 22 claimed nothing at all. validate_manifest.py only checked that the size was a non-negative number, so nothing caught it. index.yaml was the only file telling the truth, because it derives both from the source. Derive them everywhere instead. tools/sync_manifests.py rewrites both fields from the Lua file, make check runs it and fails on any diff. Two gaps followed from the same place. There was no quick way to raise a version without forgetting one of the two files that state it, and no way to recover an older driver: index.yaml names only the current version, while spec/driver-package-v1.md already promises rollback to a previously verified package. - make bump-driver ID=<id> LEVEL=patch moves the manifest and the DRIVER table together, then refreshes the generated catalog. - driver-history.json records every published version with its source hash, size, first commit and date. The record is append-only: a published version describes bytes already running on hardware, so make check fails if an entry is rewritten or dropped. Signed-off-by: Fredrik Ahlgren <[email protected]> * chore: record sungrow 1.2.1 and resync its manifest after #17 #17 changed drivers/lua/sungrow.lua, so the manifest hash this branch wrote no longer described the file. This is the guard working: make check caught it rather than letting main carry a manifest that lied. Signed-off-by: Fredrik Ahlgren <[email protected]> --------- Signed-off-by: Fredrik Ahlgren <[email protected]>
Summary
SG string inverters answer the 5xxx PV registers but none of the SH hybrid
block. The driver read
13019and its neighbours on every model. Since thehost started counting a poll as failed when any single read fails, an SG12RT
failed 12 of its 19 Modbus reads and the whole device went offline instead of
reporting the PV it does have.
The catalog already said what the driver ignored: SG-RT is "PV + meter only
(no battery)".
Each model-specific register is now read through
optional_read, which probesan address once and then stops reading it. The battery and meter streams are
emitted only when the registers behind them responded, so a string inverter no
longer reports a battery DER it does not have. Battery commands are refused
once a poll has proved the model has no battery block, so we never write EMS
registers an SG does not implement.
Same pattern as the Pixii fix in #16.
The probe is lazy rather than in
driver_init, unlike Pixii. This drivernotes that Modbus is connected only by the first poll, so probing in init
would risk marking registers absent for the whole session because of a startup
gap. The cost is one failed poll after a restart on an affected model.
Reported in Discord by an SG12RT owner:
driver_poll: 12 of 19 modbus reads failedon bundledsungrow-shx1.1.0.Driver evidence
sungrowsungrow-shx1.1.0, so this fix reaches that site only after it moves to the managed driverSafety
The control change only narrows what the driver will write: a battery command
is refused on a model with no battery block. No new write path is added.
Package or promotion evidence
com.sourceful.driver.sungrowunchanged at 1.3.2; the shipped observe-only target is byte-locked to the FTW baseline and is not touched hereftw-core. The staged v2 control adapter moves 1.3.1 to 1.3.3 and stays disabledmake package-driver ID=sungrow TARGET=ftw-corebuilds the unchanged 1.3.2 observe candidaterequired:requiredfalseChecks
Signed-off-by.make test-driver ID=sungrowmake package-driver ID=sungrow TARGET=ftw-coremake check— 2606 passed, 0 failedNew harness tests:
sungrow-sg-stringandsungrow-ftw-v2-sg-string. Bothpoll three times with the hybrid block failing, and assert PV and meter keep
flowing, no battery stream is emitted, and no absent register is read twice.
The pre-existing
goodweharness failure onmainis unrelated and unchanged.🤖 Generated with Claude Code