Skip to content

fix(sungrow): keep reading the serial and device type after the inverter wakes (1.7.2) - #300

Open
frahlg wants to merge 1 commit into
mainfrom
fix/sungrow-serial-retry
Open

frahlg wants to merge 1 commit into
mainfrom
fix/sungrow-serial-retry

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. sungrow 1.7.1 read the serial first in each poll and gave it three tries for the life of the process (sn_tries). An inverter asleep at start-up, or held by another Modbus client, used up those tries while answering nothing. The device then stayed known only by its address, and Core's forecast identity check stayed pending. This is the fault #298 fixed for SolarEdge; on 4 Dec 2026 it held back a site's load forecast for 12 hours.

settle_poll already starts every other register's count over when the link comes back, but not sn_tries. Device-type detection (register 4999) gave up the same way: three tries on a dead link, then unknown for the session, so a hybrid's external meter was no longer reported with power_origin = "external_meter".

Change

  • The serial is read last in a poll, and only in one where another read answered. A sleeping inverter costs it nothing.
  • After three misses on an inverter that does answer, it is asked again every five minutes instead of never. The first answer reports it and logs once.
  • A reconnect starts the serial's count over, like every other register's.
  • Detection that gave up during an outage gets one more try once the inverter answers again. If 4999 still gives nothing it settles on unknown in that same poll, so a hybrid block read is not held back.
  • No other register's read changed.

Test evidence

  • New drivers/tests/lua_harness/test_sungrow_serial_retry.lua (run by test_sungrow_serial_retry.py):
    1. every read and write fails from driver_init for six polls, then the inverter wakes: the serial is reported on the first poll after waking and the hybrid's meter is named again;
    2. the serial is refused three times while the inverter answers, is not asked for five minutes, fails its first retry and answers its second.
      1.7.1 fails case 1: serial not reported on the first poll after waking: nil.
  • make test-driver ID=sungrow: 154 passed, 4 skipped.
  • make absent-register-report ID=sungrow: every address settles.
  • make check: 5575 passed, 927 skipped.

Not yet verified

  • No hardware run. The case needs an SH inverter that is off or held by another client when FTW starts, then wakes.
  • While writing the test I noticed the driver reads the serial from host address 4990 for ten registers, which ends on 4999, the device-type register. Every other address in this driver is the documented number minus one, and the reference map (mkaiser) reads the serial from 4989. If that is right, 1.7.x reports the serial without its first two characters. I did not change the address: Core and saved forecast receipts hold the serial as it is reported today, so changing it needs a decision and a check against a real inverter's nameplate.
  • After merge, FTW's pin in drivers/BUNDLED_SOURCE.json has to move, or an offline boot keeps running 1.7.1.

🤖 Generated with Claude Code

…ter wakes (1.7.2)

FTW Core keys a device on its serial number, and its saved forecast
receipt holds it. The driver read the serial first in each poll and gave
it 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, so the device stayed known only by its address and
Core's forecast identity check stayed pending. Device-type detection gave
up the same way and stayed on "unknown", so a hybrid's external meter was
no longer named as one.

The serial is now read last in a poll, and only in one where another read
answered. After three misses on an inverter that does answer, it is asked
again every five minutes instead of never, and a reconnect starts its
count over like every other register's. Detection that gave up during an
outage gets one more try once the inverter answers again.

A new harness test starts the inverter asleep, wakes it after six polls,
and checks the serial and the hybrid's meter; then fails the serial three
times on a live inverter, fails its first retry and answers its second.
The old driver fails it.

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:15:03.054772Z aa2b8aa 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.

The serial is now read last, only in a poll where another read answered, retried every five minutes after three misses, and its count (plus a gave-up device-type detection) starts over on reconnect. That matches the description.

  • Security screen: no secrets, new dependencies or network destinations seen in the driver diff. No new writes to the device.
  • No findings. I read the driver diff only, did not run the tests, and there is no hardware run (as you note).

Safe to merge from my read.

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