Repository navigation
feat(history): one account per battery for the battery-storage tax figure - #1953
Merged
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
frahlg
force-pushed
the
claude/battery-return-per-battery-032049
branch
from
November 2, 2026 11:35
9bcfe12 to
37be3d7
Compare
frahlg
force-pushed
the
claude/battery-return-per-battery-032049
branch
from
November 2, 2026 11:57
37be3d7 to
b4ace70
Compare
…gure Sites with more than one battery had no figure, because one shared account let one battery's exports carry another's grid energy. Each battery meter now keeps its own account, size and run efficiencies, and for each battery solar, a car and the other batteries count first in every hour. A driver's battery size goes to the meter with an asset of its name, so a new identity keeps it. The hourly CSV has one row per battery and hour. Co-Authored-By: Claude Opus 5.5 <[email protected]>
frahlg
force-pushed
the
claude/battery-return-per-battery-032049
branch
from
November 2, 2026 15:14
b4ace70 to
d833173
Compare
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.
Stacked on #1950 (
feat/battery-return-tax, up to a17faf1). Merge that first. GitHub then moves this PR's base tomaster.Why
#1950 refuses any site with more than one battery: one shared account would let battery A's exports carry battery B's grid energy, which overstates the figure. Fredrik asked for this follow-up on 2 November 2026. With an account for each battery, those sites get a figure.
What
Account per battery meter. b077033 joins assets of one kind that never read at the same time into one meter. Each battery meter now has its own account, size floor and run efficiencies. 3950f98 and a17faf1 made that method; here it runs once per battery.
Bounds per battery and hour:
The account per battery. Each hour plays in the order that credits least:
Missing readings and new assets. When battery b's readings are missing, or when another asset takes over in b's meter, only b's account resets and only b's run ends. The hour counts for no battery, because every bound needs every battery's discharge.
Size per battery.
battery_capacity_whgoes to the battery meter that has an asset with the driver's name.labelis the driver name, written on every reading (go/cmd/ftw/energy_history.go). So a new identity behind the same driver keeps the size, even when the new asset has no label yet.devicestable. Two drivers on one inverter share adevicesrow whosedriver_nameflips between them, but each driver keeps its own asset.No figure, with a reason, in two cases:
battery_size: a battery meter read in the year has no size.battery_unread: a sized driver did not read a battery in the year.A battery first read after the year counts as absent, as feat(history): the figure for Skatteverket's energy tax refund after battery storage #1950 already treats solar. The
batteriesproblem is gone.API.
batteriesis now a list. Each entry has the label, the latest asset id, whether it is sized, the size, the charge-weighted efficiency and the returned energy. A newunreadfield lists drivers that read no battery. The top-levelefficiencyandcapacity_whmoved into the list.CSV.
batterycolumn (the meter's latest asset id),other_batteries_discharge_whand that battery's run efficiency.grid_to_battery_whandbattery_to_grid_whcan be rebuilt from that row alone.returned_whalso needs the same battery's previous row, for what it held.returned_wh. With one battery there is one row per hour, as before.View. Several batteries get one line each. Each reason has its own message, which names the drivers. No month rows appear when there is no figure. The note says each battery keeps its own account.
Evidence
Siteliterals and field paths such asr.Batteries[0].Efficiencychanged, andlen(r.Batteries)inTestANewIdentityContinuesTheMeter.Buildon 1000 random one-battery sites, 500 of them with an identity change. The sites had gaps, spread counters, missing points, V2X, dark hours, and hours that both charge and discharge. Every hour (including its run efficiency), month, size, efficiency and figure matched bit for bit. The probe is not committed./api/configanswered 401, so the 9.6 kWh size was assumed.go test ./internal/batteryreturn ./internal/apiandnpm testpass.make verifypasses on the rebased tree.ftwbinary against 30 days of seeded ledger data with two batteries:Independent review
A Sonnet subagent tried to make the code overstate in three rounds. It compared against the lowest figure the flows allow, played at minute level.
Round 1 ran on the proportional mix. The per-battery code was sound, and three overstatements in the method went to feat(history): the figure for Skatteverket's energy tax refund after battery storage #1950. 3950f98 fixed them.
Round 2 ran on 3950f98 per battery. The per-battery bounds held, with 0 violations on 12 000 sites with 1 to 3 batteries. Three overstatements also hit one battery:
I reproduced the first two. The reviewer's repair went into a17faf1, and this PR carries it per battery.
Round 3, on b4ace70, found no overstatement:
For the owner
statewould need a schema change.🤖 Generated with Claude Code