Skip to content

feat(state): the energy ledger keeps hourly totals for four years - #1951

Merged
frahlg merged 1 commit into
masterfrom
feat/ledger-hourly-four-years
Nov 2, 2026
Merged

frahlg merged 1 commit into
masterfrom
feat/ledger-hourly-four-years

Conversation

@frahlg

@frahlg frahlg commented Nov 2, 2026

Copy link
Copy Markdown
Member

Stacked on #1950. Retarget to master once #1950 merges.

Why

Skatteverket's refund of energy tax after battery storage (#1950) is worked out hour by hour for one calendar year and may be claimed until three years after that year ends. The ledger kept hourly totals for two years and daily totals after that, so a year claimed late had its first months as daily totals, which the report counts as incomplete.

What

  • EnergyLedgerRetention goes from 2 × 365 days to 4 × 366 days: the hours of a year now last until its claim deadline, leap years included. Five-minute detail (30 days) and the daily tier after the hourly horizon are unchanged.
  • The note under the refund figure no longer tells owners to download the CSV before the hours are gone.

Cost

The ledger stores about one hourly row per asset and flow (more only where an hour mixes qualities). A site with a grid meter, battery, solar, a charger and observed load has about ten flows, so roughly 88,000 rows a year. Two more years of hours adds about 175,000 rows, a few tens of MB in history.db, instead of the same years as daily rows.

Evidence

go test ./internal/state -run 'Ledger|Prune|Plain|Energy' and node --test web/battery-return.test.mjs pass. The prune tests use the constant, so they move with it. No conflict with #1751, the other open PR touching energy_ledger.go.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T09:31:38.039220Z d117cb9 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

frahlg added a commit to srcfl/ftw-app that referenced this pull request Nov 2, 2026
srcfl/ftw#1951 keeps the ledger's hourly totals for four years, so the
refund's note now says the box keeps them for the three years an owner
can apply, as the box's own History does. The test of a second launch
waits for the home file to land before it reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg force-pushed the feat/ledger-hourly-four-years branch 2 times, most recently from d6d8b88 to 871b79e Compare November 2, 2026 11:52
Skatteverket's refund of energy tax after battery storage is worked out
hour by hour for a calendar year and may be claimed until three years
after the year ends. With two years of hours, the start of an older year
was already daily totals and counted as incomplete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg force-pushed the feat/ledger-hourly-four-years branch from 871b79e to f7952f5 Compare November 2, 2026 14:52
@frahlg
frahlg changed the base branch from feat/battery-return-tax to master November 2, 2026 14:52
@frahlg frahlg closed this Nov 2, 2026
@frahlg frahlg reopened this Nov 2, 2026
@frahlg
frahlg merged commit cd1ce6e into master Nov 2, 2026
22 of 23 checks passed
frahlg added a commit to srcfl/ftw-app that referenced this pull request Nov 2, 2026
…ket (#145)

* feat(ios): the energy tax refund after battery storage, for Skatteverket

A Swedish household gets back the energy tax on grid electricity a
battery stored and later sent back to the grid. Core works out the
figure for one calendar year (srcfl/ftw#1950). History now has a row
for it under the day, for a home in SE1 to SE4 with a battery. The
screen shows the year's figure in whole kWh rounded down, the hours
behind it, the battery it was counted with and each month, and shares
the hourly basis as CSV. A problem from the box shows its reason and no
figure. Both routes are Read in Core, so the session's API passthrough
carries them as they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(ios): the box keeps the hourly readings as long as one can apply

srcfl/ftw#1951 keeps the ledger's hourly totals for four years, so the
refund's note now says the box keeps them for the three years an owner
can apply, as the box's own History does. The test of a second launch
waits for the home file to land before it reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(ios): the energy tax refund with one account per battery

Core now counts each battery on its own (srcfl/ftw#1953), and #1950 and
#1953 ship in the same beta. The answer lists the batteries with their
size and least efficiency, names the drivers it read nothing from in
`unread`, and drops the top-level `efficiency`, `capacity_wh` and the
`batteries` count with its problem.

- Decode the list and `unread`. One battery keeps its line; with several,
  each has a line with what came from it, its size and the least it gives
  back, as the box's own History card writes it. The figure stays the
  box's total.
- `battery_size` names the batteries without a size; `battery_unread`
  names the drivers in `unread`, in English and Swedish. Any other reason
  keeps the plain text.
- The kept answers move to version 2, so one in the old shape is dropped.
- The demo box answers in the new shape and writes the CSV one row per
  battery and hour. Two years back it read two batteries; the oldest year
  has a size for a battery it read nothing from.
- Debug builds take `-FTWRefundYear`, and the screenshot script shoots
  both cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant