Skip to content

fix(huawei): read the inverter again after a silent start, and send no zeros (2.2.2) - #304

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

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

Conversation

@frahlg

@frahlg frahlg commented Dec 4, 2026

Copy link
Copy Markdown
Member

Problem

huawei 2.2.1 read the meter power (37113) without a guard but last in the poll, after every other register had gone through probe_read, which leaves a register alone until restart after three misses. A SUN2000 asleep at start-up, or held by another Modbus client (a common case with the Huawei dongle), used up every try while answering nothing. When it answered again, only 37113 was still asked, and the driver sent:

  • pv with w = 0 and 0 V / 0 A strings;
  • battery with w = 0 and soc = 0, an empty battery the planner could dispatch into;
  • meter with every phase field, frequency and energy at 0.

That went on until FTW restarted the driver. The serial, read through the same guard, never reached Core, so its forecast identity check stayed pending.

Change

  • 37113 is read first, on every poll, and never given up. When it fails the driver sends nothing and asks nothing else, as before, and logs once when it stops and once when it answers again.
  • Every other register is asked only after 37113 answered; the serial last, so a timeout there cannot make the host skip the poll's other reads.
  • A register that misses three times on an inverter that does answer is asked again every five minutes, not never. A short reply counts as a miss.
  • A field whose register did not answer is left out, not sent as 0. pv is sent only when the PV input power (32064) answered, and battery only when the battery power (37001) answered. A SUN2000 without a LUNA2000 that answers 37001 with 0 still sends a battery, as before.
  • Register addresses, scales and signs are unchanged. The driver stays read-only.

Test evidence

  • test_wakes_after_silence.lua (shared with fix(saj): read the serial and battery again after the inverter wakes (1.3.1) #301), run by test_huawei_wakes.py: silent from start-up, silent mid-session, each register refused six times. 2.2.1 fails: asleep at start-up: register 32016 not read after the device answered.
  • New case in test_huawei_wakes.py: 32064, 37001, 37004, 37101 and 37118 refused while the meter answers. 2.2.1 sends 4 PV and 4 battery readings, l1_v = 0 and hz = 0; 2.2.2 sends none and leaves those fields out.
  • make test-driver ID=huawei: 65 passed, 4 skipped.
  • make absent-register-report ID=huawei: every address settles except 37113, which emits nothing while it fails (allowed).
  • make invented-number-report ID=huawei: none.
  • make check: 5576 passed, 927 skipped.

Not yet verified

  • No hardware run. A SUN2000 whose PV input or battery power register does not answer now shows no PV or no battery instead of 0 W; nobody has checked how the apps show that.
  • After merge, FTW's pin in drivers/BUNDLED_SOURCE.json has to move.

🤖 Generated with Claude Code

…o zeros (2.2.2)

huawei 2.2.1 read every register but the meter power (37113) through a
guard that left it alone until restart after three misses, and read the
meter last. An inverter asleep at start-up, or held by another Modbus
client, used up every try while answering nothing. The driver then sent
PV 0 W and an empty battery (0 W, SoC 0) next to a live meter until FTW
restarted it, and never read the serial number Core keys the device on.

The meter power is now read first, on every poll; when it does not
answer the driver sends nothing and asks nothing else, as before. Every
other register is asked only once it has answered, the serial last. A
register that misses three times on an inverter that does answer is
asked again every five minutes. A field whose register did not answer is
left out rather than sent as 0: PV is sent only when its input power
answered, and the battery only when its power answered.

test_wakes_after_silence.lua and a new no-zeros case in
test_huawei_wakes.py both fail on 2.2.1 and pass on 2.2.2.

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:27:19.201480Z 70931a2 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.

huawei 2.2.2: meter power (37113) is read first and gates the rest of the poll, unanswered fields are left out instead of sent as 0, and refused registers are retried every five minutes.

  • No blocking findings. pv and battery are only emitted when their power register answered, and the sign flips go through a nil-safe negate().
  • Minor: the 37046 limits read now needs all four registers. Before, a two-register reply still gave the charge limit. Probably fine, just a change in behaviour.
  • Security: driver stays read-only; no secrets, new dependencies or new network destinations in the driver diff.
  • Open, as the description says: no hardware run.

Safe to merge from my read. I read the driver diff and CI is green; I did not run the tests myself.

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