Repository navigation
fix(sungrow): refuse a battery command on an inverter with no battery - #39
Merged
Merged
Conversation
driver_command accepted a battery setpoint on a model this driver had
already classified as a string inverter. That is not a no-op. Measured
against the harness mock, one command wrote three registers and returned
success:
RETURN true
WROTE 13049=2 forced EMS mode
WROTE 13050=0xAA force charge
WROTE 13051=1000 setpoint
An SG string inverter does not implement the 13xxx block, so these are
unexpected writes to live hardware. The read-back that would have caught
the mismatch fails on such a device, and set_battery_power treats a
failed read-back as transient and assumes the writes are good. So the
host recorded an applied setpoint, renewed the lease on that answer, and
the planner went on dispatching a battery that is not there.
The guard shipped once already, in #17 as part of 1.2.1. Promoting FTW's
drivers in #27 replaced this file wholesale and removed it; #29 restored
only the read half at 1.4.0. It survived in the FTW v2 target, whose own
test stayed green throughout. This is the third time that shape of
regression reaches a catalog driver after Pixii's 40288 and SolarEdge
legacy's 40123, and the third time a package target's green test hid it.
It now refuses with code no_battery -- the same code
packages/v1/sungrow/targets/ftw.lua already returns, so the two control
paths refuse in one vocabulary -- writes nothing, and logs the reason the
way curtail already does when rated power is missing. Curtail itself is
untouched: an SG inverter has no battery, but it does have PV.
drivers/tests/lua_harness/ caught this and gated nothing, because CI runs
pytest and not the Lua harness. The guard now lives in
drivers/tests/test_sungrow_model_family.py. It pins the refusal, the code
and the logged reason, and pins the two ways refusing could go too far: a
hybrid must still take a battery command, and a string inverter must
still take a curtail. Verified against the unfixed driver -- the two
refusal tests fail, the two over-refusal guards pass.
Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Both sides added an entry at the top of the same Unreleased "Fixed" block: sungrow 1.5.1 here, sigenergy 1.1.1 from #38. Kept both. Signed-off-by: Fredrik Ahlgren <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2eb73924cd
ℹ️ 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".
frahlg
added a commit
that referenced
this pull request
Jul 28, 2026
#37 taught the boundary check to scan the repository rather than the disk under it, so make check passes locally again with worktrees present. #38 removed sigenergy's SoH read. #39 stopped sungrow accepting a battery command on an inverter with no battery. Two real conflicts, both in drivers this branch had also touched: sigenergy main removed the SoH read at 30087 outright; this branch had bounded it. Removing a read whose result is discarded is strictly better than bounding it, so main's side stands and the bounded probe covers the remaining five reads. sungrow merged cleanly in the Lua: main's control-path guard plus this branch's bounded reads through optional_read. Zero violations, and the string-inverter refusal is intact. Both files now differ from main's bytes under main's version, so both move again -- sigenergy 1.1.1 -> 1.1.2, sungrow 1.5.1 -> 1.5.2. This is exactly what the signed channel refuses to publish otherwise, and what the SemVer gate in ftw#709 checks across a pin move. Swept the whole catalog afterwards: zero absent-register violations across every driver. make check green, 3008 tests pass. Co-Authored-By: Claude Opus 5 <[email protected]> Signed-off-by: Fredrik Ahlgren <[email protected]>
9 tasks done
frahlg
added a commit
that referenced
this pull request
Jul 28, 2026
Codex review on #39 found the guard incomplete, and it was right. When register 4999 fails or returns the documented 0/0xFFFF sentinel, detection settles on "unknown" and nothing ever classifies the device as "string". A guard testing for "string" alone falls straight through, so an SG inverter with an unreadable device-type register still got the 13049/13051 writes and still reported success. The suggested fix -- gate on a positively identified "hybrid" -- trades one outage for another. An SH inverter whose 4999 is unreadable settles on "unknown" too, but its battery block answers, so the driver reads that battery and reports its SoC every five seconds. Refusing to command a battery the driver is actively reading is its own outage, and detection giving up is common enough that DETECT_ATTEMPTS exists for it. So the rule is evidence rather than labels: take a battery command when the device named itself a hybrid, or when its battery registers have answered. Refuse otherwise. The read path may probe its way out of "unknown" because a failed read is bounded and self-correcting; a write to a register the model does not implement is neither. packages/v1/sungrow/targets/ftw.lua had the identical gap and gets the identical fix, so both control paths still refuse on one rule with one no_battery code. The v2 target had no pytest at all -- only the Lua harness, which CI does not run, which is the same way Pixii's 40288 came back. One parametrised test now holds both files to the rule, as #34 learned to do. It pins the refusal on a named string inverter and on an unidentified one that answers no battery register, and pins both ways refusing could go too far: a hybrid must still take a battery command, named or merely observed, and a string inverter must still take a curtail. Verified against the previous guard: the unidentified-string case fails for the catalog driver and the v2 target alike. Signed-off-by: Fredrik Ahlgren <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
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.
Summary
driver_commandaccepted abatterysetpoint on a model this driver had already classified as a string inverter. The read path learned the two Sungrow families apart in 1.4.0; the write path had not.Accepting was worse than a no-op. Measured against the harness mock, one command wrote three registers and returned success:
An SG string inverter does not implement the 13xxx block, so those are unexpected writes to live hardware. The read-back that would have caught the mismatch fails on such a device, and
set_battery_powertreats a failed read-back as transient and assumes the writes are good. So the host recorded an applied setpoint, renewed the lease on that answer, and the planner went on dispatching a battery that is not there.It now refuses with code
no_battery— the same codepackages/v1/sungrow/targets/ftw.luaalready returns, so the two control paths refuse in one vocabulary — writes nothing, and logs the reason the way curtail already does when rated power is missing. Curtail itself is untouched: an SG inverter has no battery, but it does have PV.This shipped once already
if model_family == "string" then return false endshipped in #17 as part of 1.2.1, with the comment explaining why. Promoting FTW's drivers in #27 replaced this file wholesale and removed it. #29 restored only the read half at 1.4.0. The guard survived in the FTW v2 target, whose own test stayed green throughout.Third time this shape of regression reaches a catalog driver, after Pixii's 40288 and SolarEdge legacy's 40123 — and the third time a package target's green test hid it. The comment above the guard now says so, and says not to remove it again.
The test had to move
drivers/tests/lua_harness/test_all_drivers.luacaught this. It failed on unmodifiedmainand gated nothing, because CI runs pytest and not the Lua harness. The guard now lives indrivers/tests/test_sungrow_model_family.py, which runs.Verified against the unfixed driver — the two refusal tests fail, the two over-refusal guards pass:
no_battery,unchanged, and a reason in the logDriver evidence
sungrow(1.5.0 → 1.5.1)control_enabledmovesset_self_consumption()still writes the same EMS block unconditionally fromdriver_init,deinit,driver_default_modeanddriver_cleanup. Left out on purpose — the host blocks later control when default mode fails, and an SG inverter does support curtail, so refusing there is a different safety call and needs its own changeSafety
Package or promotion evidence
12001703cb0c8250a057ff351dc29d09c7f87ee2277cf841298c96138844929e(drivers/lua/sungrow.lua, 41903 bytes)com.sourceful.driver.sungrow— unchanged at 1.3.2. The package builds frompackages/v1/sungrow/targets/ftw-observe.lua, which this PR does not touchftw-coreonly;make package-driver ID=sungrow TARGET=ftw-corebuilds cleanrequired:required, and unchanged by this PR.packages/v1/sungrow/targets/ftw.luaalready refuses withno_batteryand stays atcontrol_enabled: falsefalseChecks
Signed-off-by.make test-driver ID=sungrow— 57 passed, 4 skippedmake package-driver ID=sungrow TARGET=ftw-core— unsigned candidate 1.3.2 for ftw-coremake check— 2115 passed, 2251 skipped, no generator driftThree Lua-harness drivers still fail — ferroamp, fronius, sonnen. They fail identically on unmodified
main; they are harness fixture gaps, unrelated to this change.🤖 Generated with Claude Code