Skip to content

fix(saj): read the serial and battery again after the inverter wakes (1.3.1) - #301

Open
frahlg wants to merge 1 commit into
mainfrom
fix/saj-wake
Open

frahlg wants to merge 1 commit into
mainfrom
fix/saj-wake

Conversation

@frahlg

@frahlg frahlg commented Dec 4, 2026

Copy link
Copy Markdown
Member

Problem

FTW Core keys a device on its serial number, and its saved forecast receipt holds it. saj 1.3.0 asked the identity block (0x8F00) first in every poll with its own sn_tries count, and the BMS block (0xA000) on every poll, each with three tries for the life of the process. An inverter asleep at start-up, or held by another Modbus client, used up those tries while answering nothing. The serial then never reached Core, so its forecast identity check stayed pending, and the battery was never reported until FTW restarted the driver. This is the fault #298 fixed for SolarEdge.

Change

  • The identity block and the BMS block are asked only in a poll whose live power block (0x40A5) answered. The identity block is read last, so a timeout there cannot make the host skip the poll's other reads during its reconnect backoff. sn_tries is gone.
  • After three misses on an inverter that does answer, a register is asked again every five minutes instead of never. Core keeps a poll fresh when the device refuses one read and others answer, so this costs a refused read in sixty polls on a model without the register. The first answer logs once.
  • The live power block is still asked on every poll; while it is silent the driver sends nothing.
  • No register, scale or field changed.

Test evidence

  • New drivers/tests/lua_harness/test_wakes_after_silence.lua, run by test_saj_wakes.py. It runs the driver healthy, then compares three cases with that run: asleep from driver_init for eight polls then awake; silent for eight polls mid-session; and each register the healthy run reads refused for six polls while the rest answer, which must be asked again within five minutes. After waking, the driver must emit the same kinds, report the same serial and read the same registers.
    1.3.0 fails it: asleep at start-up: no battery emitted after the device answered.
  • make test-driver ID=saj: 124 passed, 21 skipped.
  • make absent-register-report ID=saj: every address settles except 16549, the live power block, which emits nothing while it fails (allowed).
  • make check: 5575 passed, 927 skipped.

The harness is shared: the other driver PRs in this series add the same file, byte for byte, so they merge cleanly in any order.

Not yet verified

  • No hardware run; saj stays experimental. The case needs an H2/HS2 that is off or held by another client when FTW starts.
  • After merge, FTW's pin in drivers/BUNDLED_SOURCE.json has to move.

🤖 Generated with Claude Code

…(1.3.1)

FTW Core keys a device on its serial number, and its saved forecast
receipt holds it. saj 1.3.0 asked the identity block first in every poll
and the BMS block on every poll, both with three tries for the life of
the process. An inverter asleep at start-up, or held by another Modbus
client, used up those tries while answering nothing: the serial never
reached Core and the battery was never reported.

Both blocks are now asked only in a poll whose live power block
answered, and the identity block last, so a timeout there cannot make
the host skip the poll's other reads. After three misses on an inverter
that does answer, a register is asked again every five minutes instead
of never. The live power block is still asked on every poll.

A new harness, test_wakes_after_silence.lua, compares a driver with a
healthy run of itself after a silent start, after a silent spell
mid-session, and after each register is refused six times. 1.3.0 fails
it; 1.3.1 passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T18:17:53.835363Z 1a1fbaf 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.

@miravoss26 miravoss26 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identity and BMS reads now happen only when the live power block answers, and a given-up register is retried every five minutes instead of never.

  • Low: read_identity no longer has its own attempt bound. If 0x8F00 answers but the serial decodes empty, probe_read clears the failure count and sn_read stays false, so the block is read on every poll for the whole session (before: three times). Suggest counting an empty serial as a miss, or spacing it by RETRY_EVERY_MS.
  • Security screen: no secrets, new dependencies or network destinations seen in the driver diff.

I read the driver diff only and did not run the tests. Safe to merge from my read; the point above is a small follow-up.

This branch has not been deployed

No deployments
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.

2 participants