Skip to content

fix: probe an absent optional register once, not on every poll - #33

Merged
frahlg merged 1 commit into
mainfrom
fix-driver-poll-flap-on-absent-optional-registers
Jul 28, 2026
Merged

frahlg merged 1 commit into
mainfrom
fix-driver-poll-flap-on-absent-optional-registers

Conversation

@frahlg

@frahlg frahlg commented Jul 28, 2026

Copy link
Copy Markdown
Member

Brings the two driver fixes from srcfl/ftw#703 and srcfl/ftw#702 to the repository that owns the drivers. Original work and field diagnosis by @murwall.

The failure

Both drivers issue a Modbus read the hardware cannot answer:

Driver Register Hardware
pixii 40288 meter_energy_sf PowerShaper firmware below CPU 2.0.23
solaredge_legacy 40123 MPPT block K-series SE7K/10K/17K/25K, the display era

Both wrap the read in pcall and fall back sensibly, which is correct at the Lua level. But the host counts every failed host.modbus_read against the poll whether or not Lua handled it. So both drivers sat at driver_poll: 1 of N modbus reads failed every five seconds, went offline on the stale-telemetry watchdog, and stopped feeding the planner. On Pixii the watchdog also wrote setpoint=0 every five seconds.

Both now probe once, remember an absent register and stop issuing the read. A restart re-probes, so a firmware update that adds the register is picked up.

Why this repository, and why it came back

AGENTS.md is explicit that this repository is the only editable source for shared drivers and the main driver source for FTW. FTW's drivers/ is a bundled snapshot, so a fix landed there does not survive the next publication from the signed channel.

Pixii was fixed here once already, in #16 for issue #15. That fix went into packages/v1/pixii/targets/ftw.lua and the catalog driver both — but promoting FTW's driver in #27 overwrote drivers/lua/pixii.lua and took the catalog fix with it. The package target kept its copy, and the only regression test ran the package target, so nothing here went red while the flap reached customer hardware again.

The tests added in this PR run the catalog drivers, which is what the signed channel publishes.

Test bug this surfaced

Editing the drivers cost them byte-identity with baselines/ftw, which is what had exempted them from the Modbus suite — exactly as conftest.py describes. That exposed a real bug in _extract_decode_calls: the regex [^)]* stops at the first close paren, so host.decode_i16(reg(regs, 40084)) read as two arguments and failed a driver that was correct. It now matches parentheses and splits only at depth zero.

Verification

make check passes — 2030 passed, 2251 skipped.

The new tests were run against the unpatched baselines/ftw copies to confirm they catch the bug rather than merely passing:

Driver Unpatched Patched
pixii, 40288 over 3 polls 3 reads 1 read
solaredge_legacy, 40123 over 3 polls 3 reads 1 read

Guards live in drivers/tests/test_absent_optional_registers.py because CI runs pytest and never runs the Lua harness. The equivalent Lua-harness cases are added too, so both suites cover it.

Versions move by patch: pixii 2.1.0 → 2.1.1, solaredge_legacy 0.3.0 → 0.3.1. Behaviour is fixed, no interface changed.

Neither fix is verified on live hardware from this repository. @murwall ran both on real devices — SE17K firmware 0003.2251 for about 30 minutes with clean battery dispatch, and the Pixii register probe — so that evidence sits in the FTW PRs, not here.

Closes srcfl/ftw#703, closes srcfl/ftw#702

🤖 Generated with Claude Code

Pixii PowerShaper firmware below CPU 2.0.23 answers Modbus exception 2
on 40288 (meter_energy_sf). SolarEdge K-series inverters do not populate
the proprietary MPPT block at 40123. Both drivers caught the failure in
pcall and carried on, which is right at the Lua level — but the host
counts every failed modbus_read against the poll whether or not Lua
handled it. So both sat at "1 of N reads failed" every five seconds,
went offline on the stale-telemetry watchdog, and stopped feeding the
planner.

Both now probe once, remember an absent register and stop asking. A
restart re-probes, so a firmware update that adds the register is
picked up.

Pixii was fixed once already, in #16 for issue #15. That fix lived only
in packages/v1/pixii/targets/ftw.lua, so promoting FTW's driver in #27
reverted the catalog copy and the flap reached customer hardware again.
The tests added here run the catalog drivers, which is what the signed
channel publishes.

Editing the drivers cost them byte-identity with baselines/ftw, which
is what had exempted them from the Modbus suite. That exposed a bug in
_extract_decode_calls: it counted a nested call's comma as an argument
separator, so host.decode_i16(reg(regs, 40084)) read as two arguments
and failed a driver that was correct. It now matches parentheses and
splits only at depth zero.

Verified against the unpatched baselines/ftw copies: both read the
absent register three times over three polls, where the patched drivers
read it once.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg force-pushed the fix-driver-poll-flap-on-absent-optional-registers branch from 7985757 to d805e48 Compare July 28, 2026 16:08
@frahlg
frahlg merged commit 7d23940 into main Jul 28, 2026
5 checks passed
@frahlg
frahlg deleted the fix-driver-poll-flap-on-absent-optional-registers branch July 28, 2026 16:09

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79857575fd

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread drivers/lua/pixii.lua
Comment on lines +115 to +116
if sf_present[addr] == nil then
sf_present[addr] = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Retry first-read failures before caching scale factors

When the first poll gets a transient timeout or short reply for any scale-factor register that the device actually supports, this branch treats the failure as proof that the register is absent and never reads it again. Every subsequent poll then scales the associated power, energy, voltage, or current with sf=0, potentially corrupting telemetry by orders of magnitude until the driver restarts; cache absence only for a confirmed illegal-address response, or after bounded retries.

Useful? React with 👍 / 👎.

Comment on lines +284 to +285
elseif mppt_present == nil then
mppt_present = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retry transient MPPT failures before declaring the block absent

On firmware that does expose the MPPT block, a timeout or short response during its first read also reaches this branch and permanently sets mppt_present to false. The driver then emits zero MPPT voltage/current on every poll until restart even after communication recovers, so absence should be latched only after a confirmed illegal-address response or a bounded sequence of failures.

Useful? React with 👍 / 👎.

frahlg added a commit that referenced this pull request Jul 28, 2026
#33 fixed the fourteen scale-factor reads and left twenty-three value
reads behind -- AC power, frequency, temperature, SoC, battery voltage
and current, the meter block, the energy counters. Each one still
retried forever while the driver went on emitting battery and meter
telemetry, which is the combination that takes a site offline.

Every read now goes through probe_read, the same helper kostal and
fronius use. That replaces the scale-factor-only cache #33 added.

  catalog driver   23 -> 0
  package target   17 -> 0

The package target had the same debt. Fixing one and not the other is
what let the original bug come back, so both move together.

One deliberate change of policy: #33 gave up after a single failure,
this gives up after three. A single failure is not proof a register is
missing -- the link may have been slow -- and three attempts absorb that
without disabling a register that is really there. Bounded is the
property that matters, and three is what sungrow already used.

test_absent_optional_registers.py asserted "at most one read", which
encoded the one-shot policy rather than the property. It now polls six
times and asserts the total stays within the budget, which proves the
driver stopped rather than merely started slowly. Renamed to match:
those tests are about giving up, not about probing once.

driver_fingerprint kept its three reads through probe_read and still
identifies a Pixii: verified make=Pixii, confidence=0.95.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
frahlg added a commit that referenced this pull request Jul 28, 2026
* fix(kostal,fronius): stop reading registers the device does not answer

First payment on the absent-register debt: 54 of 497 addresses.

Both drivers read every register through probe_read, which remembers
what the device did not answer and stops asking after three attempts.
Three rather than one absorbs a transient blip without disabling a
register that is really there, and a restart re-probes so firmware that
gains the register is picked up. This is the pattern sungrow already
used, written once per driver rather than at each of 27 call sites.

Measured with drivers/tests/lua_harness/absent_register_probe.lua:

  kostal   27 -> 0
  fronius  27 -> 0

Against a device that answers everything, both emit exactly what they
emitted before -- checked against their baselines/ftw copies.

Editing them cost both their byte-identity with baselines/ftw, so the
full catalog suite began applying: 96 checks that had been skipped. Both
pass without further change.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix(pixii): give up on every register, not just the scale factors

#33 fixed the fourteen scale-factor reads and left twenty-three value
reads behind -- AC power, frequency, temperature, SoC, battery voltage
and current, the meter block, the energy counters. Each one still
retried forever while the driver went on emitting battery and meter
telemetry, which is the combination that takes a site offline.

Every read now goes through probe_read, the same helper kostal and
fronius use. That replaces the scale-factor-only cache #33 added.

  catalog driver   23 -> 0
  package target   17 -> 0

The package target had the same debt. Fixing one and not the other is
what let the original bug come back, so both move together.

One deliberate change of policy: #33 gave up after a single failure,
this gives up after three. A single failure is not proof a register is
missing -- the link may have been slow -- and three attempts absorb that
without disabling a register that is really there. Bounded is the
property that matters, and three is what sungrow already used.

test_absent_optional_registers.py asserted "at most one read", which
encoded the one-shot policy rather than the property. It now polls six
times and asserts the total stays within the budget, which proves the
driver stopped rather than merely started slowly. Renamed to match:
those tests are about giving up, not about probing once.

driver_fingerprint kept its three reads through probe_read and still
identifies a Pixii: verified make=Pixii, confidence=0.95.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: stop re-reading registers foxess and growatt never answer

The host counts every failed host.modbus_read against the poll whether or
not the driver caught the error with pcall — "driver_poll: N of M modbus
reads failed". Both drivers wrapped each read in pcall, shrugged off the
failure, and then asked again five seconds later. A device missing one
optional register therefore failed a read on every poll until the
stale-telemetry watchdog marked the driver offline, and the site reported
nothing at all instead of one field less.

Both drivers now route every read through a probe_read helper that counts
failures per address and stops asking after three. Three attempts absorb a
transient blip. A restart re-probes, so firmware that gains the register is
picked up.

Only the timing of a read changed. Addresses, counts, register kinds,
decoding, scaling, sign conventions, emitted fields and control paths are
untouched.

Measured with drivers/tests/lua_harness/absent_register_probe.lua —
registers the driver fails forever while still reporting telemetry:

  driver    before  after
  foxess        19      0
  growatt       19      0

Against a device that answers everything, both drivers emit the same
records as before (pv=1 battery=1 meter=1), with identical field values and
an identical modbus read sequence.

The ratchet in drivers/tests/test_absent_register_settles.py now asks for
the foxess and growatt entries to be dropped from
drivers/tests/absent-register-baseline.json. That file is handled centrally
and is deliberately not touched here.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* docs: write down the helper the catalog standardised on

The rule was already in WRITING-A-DRIVER.md; what was missing was the
code that follows it and the command that checks it. Both now sit
beside the rule, so the next driver does not have to rediscover the
shape by reading someone else's file.

Also records why three attempts rather than one: a single failure is
not proof a register is missing, and bounded is the property that
matters, not the number.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: stop sma and deye re-reading registers the device never answers

FTW's Go host counts every failed host.modbus_read against the poll whether
or not the Lua driver caught the error with pcall -- it reports "driver_poll:
N of M modbus reads failed". A driver that decides it can live without a
register, then goes on reading it every five seconds, holds a failed read on
every poll until the stale-telemetry watchdog marks it offline. The site then
reports nothing, which is far worse than reporting one field less. This took
two drivers offline on customer hardware.

Both drivers now route every register read through a probe_read helper: three
attempts absorb a transient blip, after that the address is left alone and the
driver logs once. A restart re-probes, so firmware that gains the register is
picked up.

Measured with drivers/tests/lua_harness/absent_register_probe.lua -- registers
the driver keeps failing while still emitting telemetry:

    driver   before   after
    sma          22       0
    deye         21       0

Behaviour against a device that answers everything is unchanged. Compared to
the pre-existing copies in baselines/ftw/drivers/, both drivers emit the same
pv/battery/meter records with identical field values, the same metrics, the
same serial and make, and issue the same read sequence.

Deye's read_battery_voltage stays a plain pcall: it belongs to the control
path, runs only on a battery command and never from driver_poll, so it costs
no failed poll.

No version bumps, no generator runs, and the ratchet baseline is untouched.
drivers/tests/absent-register-baseline.json still records sma 22 and deye 21,
so test_absent_register_settles.py now fails both with its "clean now -- good,
remove it from the baseline" message. That is the intended signal for whoever
updates the baseline centrally.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* chore: take sma and deye off the absent-register baseline

Both measured clean, so the ratchet asks for the entries to go.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* chore: version the four drivers that stopped re-reading absent registers

foxess 1.1.0 -> 1.1.1, growatt 2.1.0 -> 2.1.1, sma 2.1.0 -> 2.1.1,
deye 2.1.0 -> 2.1.1. Read paths only; the signed channel refuses to
publish changed bytes under a version it already published.

Editing them cost each its byte-identity with baselines/ftw, so the
full catalog suite now applies: 149 checks that had been skipped. All
pass without further change.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: stop solis, huawei and goodwe re-reading registers the device never answers

FTW's Go host counts every failed host.modbus_read against the poll whether or
not the Lua driver caught the error with pcall -- it reports "driver_poll: N of
M modbus reads failed". A driver that decides it can live without a register,
then goes on reading it every five seconds, holds a failed read on every poll
until the stale-telemetry watchdog marks it offline. The site then reports
nothing, which is far worse than reporting one field less. This took two
drivers offline on customer hardware.

All three drivers now route their register reads through a probe_read helper:
three attempts absorb a transient blip, after that the address is left alone
and the driver logs once. A read that succeeds clears the count, and a restart
re-probes, so firmware that gains the register is picked up.

Measured with drivers/tests/lua_harness/absent_register_probe.lua -- registers
the driver keeps failing while still emitting telemetry:

    driver   before   after
    solis        19       0
    huawei       17       0
    goodwe       15       0

Behaviour against a device that answers everything is unchanged. Compared to
the pre-existing copies in baselines/ftw/drivers/, all three emit the same
pv/battery/meter records with identical field values, the same metrics, and
issue the same read sequence.

Huawei's meter power register (37113) stays a plain pcall. When it fails the
driver already emits nothing at all, so it never claims the device is fine
while paying for a failed read -- the probe confirms it. Giving up on it would
silence the driver for good after three transient blips instead of letting it
recover as soon as the meter answers.

No version bumps, no generator runs, and the ratchet baseline is untouched.
drivers/tests/absent-register-baseline.json still records solis 19, huawei 17
and goodwe 15, so test_absent_register_settles.py now fails all three with its
"clean now -- good, remove it from the baseline" message. That is the intended
signal for whoever updates the baseline centrally.

The three goodwe lua_harness suites (test_goodwe_failures, test_goodwe_profiles,
test_goodwe_ftw_contract) describe a future goodwe v1.0.3 and already fail
against the shipped v1.0.0. All 27 profile/scenario combinations produce
byte-identical output before and after this change.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* chore: version solis, huawei and goodwe, and record the round

Completes the first round against the absent-register debt: 209 of 497
addresses across 9 of 49 drivers, all measured to zero and all emitting
what they emitted before.

Two reads are deliberately left as plain pcall, and both are right as
they stand. Huawei's meter register 37113 already emits nothing when it
fails -- that is the honest-failure path, not the outage -- and bounding
it would silence the driver permanently after three blips rather than
letting it recover when the meter answers. Deye's read_battery_voltage
runs only on a battery command and never during a poll, so it costs no
failed poll, and bounding it would let poll-time failures veto a later
charge command without trying.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: stop seven drivers re-reading registers the device never answers

The Go host counts every failed host.modbus_read against the poll, whether
or not Lua caught it with pcall. A driver that decides it can live without
a register and then keeps reading it every five seconds is marked offline
by the stale-telemetry watchdog, and the site reports nothing at all. That
is worse than reporting one field less, and it took two drivers offline on
customer hardware.

Give each of these drivers the bounded probe the other nine already use:
three tries per address, then leave it alone until restart. Three rather
than one because a single failure is not proof the register is missing --
the link may just have been slow. A read that succeeds clears its count,
so a device that comes back is polled in full again.

fronius_smart_meter routes every read through its own read_f32 helper, so
bounding that one helper bounds all thirteen of its addresses.

Violations measured with drivers/tests/lua_harness/absent_register_probe.lua,
before -> after:

  fronius_smart_meter  13 -> 0
  solinteg             13 -> 0
  abb_meter             7 -> 0
  janitza               7 -> 0
  acrel                 6 -> 0
  sigenergy             6 -> 0
  wallbox               4 -> 0

No read in these seven was left alone: none sits behind a control path,
and none is an honest-failure read where the driver already stops emitting.
Against a device that answers everything, all seven emit byte-identical
telemetry -- same emit counts, same field values, same metrics.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: seven meters and inverters stop re-reading absent registers

fronius_smart_meter, solinteg, abb_meter, janitza, acrel, sigenergy
and wallbox: 56 addresses, all measured to zero, all emitting exactly
what they emitted before.

fronius_smart_meter routes all thirteen reads through one read_f32
helper, so bounding that helper fixed the whole driver.

None of the seven needed an exemption. Every read sits in driver_poll,
every emit is unconditional, and the control paths use host.write
rather than modbus_read -- so neither the honest-failure case nor the
control-path case applied.

Editing fronius_smart_meter exposed a disagreement its byte-identity
with baselines/ftw had been hiding: the manifest said 2.1.0 while the
DRIVER table said 1.0.0. That split is deliberate for a driver kept
identical to FTW's -- two lineages, FTW's version in the table and this
repository's in the manifest -- but it stops making sense the moment
the file is edited here. The version bump writes both, so they now
agree on 2.1.1.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: stop eight drivers re-reading registers the device never answers

FTW's Go host counts every failed host.modbus_read against the poll,
whether or not Lua caught it with pcall. A driver that decides it can
live without a register and then reads it again every five seconds
holds the poll in a failing state, the stale-telemetry watchdog marks
the device offline, and the site then reports nothing at all. Reporting
one field less is better than that.

Route the poll-time reads through probe_read, which drops an address
after three misses and logs once. Three rather than one, because a
single miss is more often a slow link than a missing register. A
restart re-probes.

Violations, measured with the absent-register probe harness:
sofar 14 to 0, keba 10 to 0, atmoce 9 to 0, circutor 7 to 0,
abb_terra 6 to 0, goe 6 to 0, victron 4 to 0, solaredge_legacy 1 to 0.

Two reads stay unbounded on purpose, both in solaredge_legacy: the
SunSpec probe at 40000 and the Model 103 block at 40069. Failing either
already stops the driver emitting, so the failed read is the honest
report of an unreadable inverter, not a cost paid for a field we chose
to skip. Capping them would turn three slow polls into silence that
lasts until someone restarts the daemon.

No driver in this batch reads a register from a control path, so
nothing here can let a poll-time failure veto a later setpoint.

Behaviour against a device that answers everything is unchanged.
Emitted payloads, metrics and set_sn match over three polls, against
baselines/ftw/drivers for sofar, victron and solaredge_legacy, and
against HEAD for the five catalog-only drivers.

The absent-register ratchet now fails for these eight and asks for the
baseline to shrink. That file is updated centrally.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: eight more drivers stop re-reading absent registers

sofar, keba, atmoce, circutor, abb_terra, goe, victron and
solaredge_legacy: 57 addresses, all measured to zero, all emitting
exactly what they emitted before.

Two reads in solaredge_legacy are deliberately left as plain pcall,
and both measure SETTLED 0 EMITTED 0 -- the driver already reports
nothing when they fail, which is the honest outcome rather than the
outage:

  40000  the SunSpec identity probe
  40069  the Model 103 block that carries AC power

Bounding either would turn three slow polls into silence lasting until
someone restarts the daemon. Both carry a comment saying so, and the
shared guard names them as excluded.

Three of these are EV chargers, where a control-path read would have
needed the same care deye did. None of the eight reads a register
outside driver_poll: atmoce and solaredge_legacy only write from
driver_command, sofar and victron return without touching Modbus, and
keba, circutor, abb_terra and goe have no command surface at all.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: stop eight drivers re-reading registers the device never answers

FTW's Go host counts every failed host.modbus_read against the poll,
whether or not Lua caught it with pcall. A driver that decides it can
live without a register and then reads it again every five seconds keeps
paying for it forever, and the stale-telemetry watchdog eventually marks
the site offline. The site then reports nothing, which is worse than
reporting one field less. It has already taken two drivers off customer
hardware.

The rule: a driver that keeps reporting telemetry must not keep failing
reads. Emitting nothing while failing is honest; doing both is the bug.

Each driver gets the bounded probe_read the blueprint and nine shipping
drivers already use. Three tries before it gives up, because one failure
proves nothing — the link may just have been slow. A read that answers
again clears the count.

Absent-register violations, before -> after:

  saj              13 -> 0
  solax            12 -> 0
  kstar             8 -> 0
  schneider_meter   7 -> 0
  alfen             6 -> 0
  etrel             5 -> 0
  easee             4 -> 0
  ctek              3 -> 0

Left unbounded on purpose, both in ctek and both documented in the file:
the API-version read and the charge-limit readback in driver_init. Each
runs once at startup and costs nothing per poll. Bounding the readback
would also spend the poll-time budget for the same register early.
ctek's driver_command only writes, so no control path can be vetoed by a
poll-time failure.

Against a device that answers every register all eight drivers behave
exactly as before, over five polls, down to the ordered host-call trace
and every emitted field. Checked against baselines/ftw/drivers/ctek.lua
for ctek and against git HEAD for the seven catalog-only drivers.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: two tests kept their own copy of the DER vocabulary

tools/validate_manifest.py holds VALID_DERS, and ev, heatpump and
vehicle were added to it for the drivers promoted from FTW. Two tests
carried their own hardcoded {pv, battery, meter, v2x_charger} and were
left behind.

Nothing noticed, because every driver emitting one of the new types was
byte-identical to its baseline and therefore exempt. Editing ctek for an
unrelated reason made both tests fail on a rule that had already been
changed to allow what it does.

Both now read the tool's list. This is the third hand-maintained copy of
a contract to have drifted here; the CHANGELOG records the previous two.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: stop eight drivers re-reading registers the device never answers

The host counts every failed host.modbus_read against the poll whether or
not Lua caught it with pcall. A driver that decides it can live without a
register and then reads it again every five seconds sits at "N of M modbus
reads failed" forever, the stale-telemetry watchdog marks it offline, and
the site reports nothing at all -- worse than reporting one field less.
This took two drivers off customer hardware.

Each of these eight kept emitting telemetry while a read kept failing. They
now ask three times -- one miss can just be a slow link -- and then leave
the register alone until the driver restarts, so a firmware update that
adds the register is still picked up.

sma_pv, mennekes, siemens_pac, chint, varta, solis_string and ctek_v2 gain
a local probe_read; solis_string routes its read_input helper through it.
sungrow already had the same mechanism in optional_read, so its remaining
poll-time reads go through that rather than a second copy of the logic.

Absent-register probe violations, before -> after:

  sma_pv        15 -> 0
  mennekes      10 -> 0
  sungrow        9 -> 0
  siemens_pac    7 -> 0
  chint          6 -> 0
  varta          5 -> 0
  solis_string   4 -> 0
  ctek_v2        3 -> 0

Left alone on purpose, with a comment in each file saying why:

  sma_pv probe_capabilities (30885, 30513, 40915) and ctek_v2
  read_setpoint (0x2200) run once per restart and cache the answer, so
  they cost no repeated failed read. Counting them would spend attempts
  on registers the poll has not asked for yet.

  sungrow's control-path reads (13049, 13073, 13086, 13088, 5000 in the
  curtail and battery functions) run only when a command arrives. Bounding
  them would let poll-time failures veto a later command without trying.

Against a device that answers every register, all eight are byte-identical
in emitted streams, field values, metrics and modbus calls -- checked
against baselines/ftw/drivers where that file exists, against HEAD for the
four catalog-only drivers, and against HEAD for sungrow as well, since the
FTW snapshot predates its model-family detection. The Lua harness reports
the same 59 passed / 4 failed before and after; all four failures are
pre-existing and three are in drivers this commit does not touch.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: stop eight drivers re-reading registers the device never answers

The Go host counts every failed host.modbus_read against the poll whether or
not Lua caught it with pcall. A driver that decides it can live without a
register and then reads it again every five seconds keeps paying for it, and
the stale-telemetry watchdog marks the device offline. The site then reports
nothing, which is worse than reporting one field less. It took two drivers off
customer hardware.

Give each poll-path register three chances, then leave it alone until restart.
Three rather than one because a single failure is not proof a register is
missing -- the link may just have been slow. A read that succeeds clears its
own counter, so a blip costs nothing.

Absent-register probe violations, before -> after:

  solaredge         13 -> 0
  ferroamp_modbus   10 -> 0
  alphaess           9 -> 0
  carlo_gavazzi      7 -> 0
  socomec            7 -> 0
  schrack_ev         5 -> 0
  solaredge_pv       4 -> 0
  ctek_hybrid        3 -> 0

Left unbounded on purpose, with a comment at each site:

  solaredge_pv  the Model 103 block at 40069. When it fails the driver emits
                nothing, so the failing read is already the honest report that
                the device is unreadable, not a claim that it is fine.
                Bounding it would silence the driver permanently after three
                transient blips.
  solaredge     driver_fingerprint's SunSpec identity reads (40000, 40004,
                40052). Never reached from driver_poll, so they cost no failed
                poll, and this is the probe that decides whether the device is
                a SolarEdge at all.
  ctek_hybrid   the startup API-version check and charge-limit readback. Both
                run once from driver_init.

Behaviour against a device that answers everything is unchanged: for all eight
drivers the emitted payloads compare field for field identical, and the reads
issued over three polls match call for call on address, count and register
kind.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix: sixteen more drivers, and the absent-register debt reaches zero

sma_pv, mennekes, sungrow, siemens_pac, chint, varta, solis_string,
ctek_v2, solaredge, ferroamp_modbus, alphaess, carlo_gavazzi, socomec,
schrack_ev, solaredge_pv and ctek_hybrid: 117 addresses, all measured to
zero, all emitting what they emitted before.

That empties absent-register-baseline.json. The ratchet becomes a plain
gate: every driver is held to the rule with no exceptions, and an entry
appearing there again is a regression rather than a budget.

sungrow already had the mechanism in optional_read with the same bound
of three, so its nine unbounded poll reads went through that rather
than a second copy of the same logic. solis_string routes its existing
read_input through the guard, fixing four sites at once.

Nine reads across six drivers stay unbounded on purpose, in two shapes.
Where a failed read already silences the driver -- solaredge_legacy
40000 and 40069, solaredge_pv 40069, huawei 37113 -- the failing read is
the honest report that the device is unreadable. Where a read runs only
on a command -- deye, sungrow's curtail path, solaredge's fingerprint --
it costs the poll nothing.

Editing solis_string exposed a gap in the PV field vocabulary: it
carries four trackers rather than two and reports DC input power beside
AC output. Added with the reasoning, the way the Sungrow and Pixii
fields were.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

---------

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
tommylindgren pushed a commit to tommylindgren/device-drivers that referenced this pull request Aug 10, 2026
A driver that keeps reporting telemetry must not keep failing reads. The
host counts every failed host.modbus_read against the poll whether or not
Lua caught it, so a driver that decided it can live without a register and
then goes on paying for it every five seconds is marked offline by the
watchdog. The site then reports nothing, which is worse than reporting one
field less.

Emitting nothing while failing is not a violation. A device that cannot
answer its identity block really is unreadable, and failing the poll is the
honest outcome. The violation is doing both.

tests/test_blueprint.py has held the blueprint to this property since it
was written. It applied to an imaginary driver and to none that ship.

Running it against the catalog found 49 of 50 Modbus drivers violating it
on at least one register, 497 of 543 probed addresses. Pixii and SolarEdge
legacy were not unlucky; they were the two that met firmware omitting a
register they read. Unpatched pixii scores 37 and the fix in srcfl#33 took it
to 23 -- the scale factors -- so the value reads are still there.

Failing 49 drivers would gate every unrelated change, so the counts go in
absent-register-baseline.json and the test ratchets: a count that rises
fails, a driver not listed must be clean, and a count that falls fails
until the file is updated so the debt cannot be re-borrowed.

conftest.py needed fixing first. It skips catalog-convention checks for
drivers promoted from FTW, which is right for conventions this repository
grew -- spelling, key names, structure. It was applied to every
parametrised check without distinction, so a rule about behaviour on
hardware was skipped for exactly the 34 drivers the outage happened in.
The first run of this suite reported 46 passed, 34 skipped, and looked
green. Checks marked holds_for_ftw_drivers now apply to everything.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
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