Skip to content

fix(deye-svk): skip energy headroom when the SoC read fails - #224

Merged
frahlg merged 1 commit into
srcfl:mainfrom
murre87:fix/deye-svk-nil-soc
Dec 1, 2026
Merged

frahlg merged 1 commit into
srcfl:mainfrom
murre87:fix/deye-svk-nil-soc

Conversation

@murre87

@murre87 murre87 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

deye-svk.lua computes the energy headroom from bat_soc whenever battery_capacity_wh > 0. When the SoC read fails in a poll, bat_soc is nil and math.floor(bat_soc * 100 + 0.5) raises a Lua error, so the whole poll fails. This adds the same guard the 50-125k-svk drivers already use (and bat_soc), so the headroom stays 0 for that poll. Version 0.2.2 -> 0.2.3 in the driver and manifest, CHANGELOG entry under Unreleased.

Seen in the field in EnergyWizard (driver from commit e07d27038e83): automatic error report ftw_deye-svk.poll: LuaError, murre87/energywizard#215. Fixed there by lazgeo (Co-authored-by in the commit). Context: murre87/energywizard#231.

Driver evidence

  • Driver id: deye-svk
  • Device make/model: Deye SUN hybrid (lean SvK fast-poll variant)
  • Firmware tested: none
  • Protocol/register source: unchanged, no register changes
  • Hardware test performed: no, not tested on Deye hardware (draft until it is)
  • Known limits: only guards the nil case; behaviour with a valid SoC is unchanged

Safety

  • The driver starts read-only, or this is a separately reviewed control change. (No control change.)
  • Vendor signs are converted at the driver boundary. (Unchanged.)
  • Cached telemetry becomes stale instead of being re-emitted as fresh. (Unchanged.)
  • No credentials, serial numbers, private addresses or site data are included.

Control evidence

not applicable (no control path changes)

Checks

  • Commits include Signed-off-by.
  • make test-driver ID=deye-svk (not run locally)
  • make check (not run locally; the Lua compiles with Lua 5.4)

murre87 added a commit to murre87/energywizard that referenced this pull request Nov 10, 2026
@murre87
murre87 marked this pull request as ready for review November 14, 2026 11:29
@murre87

murre87 commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Status?

@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.

Adds a bat_soc nil guard in deye-svk.lua so a failed SoC read skips the energy headroom for that poll instead of raising a Lua error. Bumps the driver and manifest to 0.2.3 and adds a CHANGELOG entry.

  • Diff is 3 lines of logic plus version and changelog. Version in driver, manifest and CHANGELOG all say 0.2.3.
  • Behaviour on a nil SoC: chg_eh_wh/dis_eh_wh stay 0 for that poll, which is what the PR says and matches the 50-125k-svk drivers.
  • Note: no CI checks are reported on this PR, and the PR itself says it was not reproduced on hardware. The reasoning holds from reading the code.
  • Security screen: no secrets, no new dependencies, no new network destinations, no authz changes.

Safe to merge from my read.

@frahlg

frahlg commented Nov 21, 2026

Copy link
Copy Markdown
Member

We have not reviewed this yet. The change reads right: a failed SoC read now skips the energy headroom for that poll. The branch conflicts with main; please rebase and set the version above main's. If the Lua error shows in your log, paste the line without IP or serial.

@murre87
murre87 force-pushed the fix/deye-svk-nil-soc branch from c3f99e5 to b20ede0 Compare November 21, 2026 11:07
@murre87

murre87 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (940a913). The only conflict was CHANGELOG.md; I kept both entries. The driver stays at 0.2.3, which is above main's 0.2.2. The manifest checksum and size were stale, so I regenerated the manifest, index, devices and support status. make check passes locally (5091 passed, 951 skipped). It is still a draft because it is not tested on Deye hardware.
About the log line: the report in murre87/energywizard#215 came from EnergyWizard's anonymous telemetry, which sends only where the error happened (ftw_deye-svk.poll, LuaError), never the error text. The stored excerpts for it have expired, so I have no log line to paste. The fix follows from the code path: bat_soc is nil after a failed SoC read, and math.floor(bat_soc * 100 + 0.5) then raises. If it shows up again I will paste the line (without IP or serial

@frahlg

frahlg commented Nov 21, 2026

Copy link
Copy Markdown
Member

Thanks for the rebase and for explaining where the report came from. We will review the diff next.

@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.

Adds the missing and bat_soc guard so a failed SoC read skips the energy headroom for that poll instead of raising on bat_soc * 100. Version bump to 0.2.3 is carried through driver, manifest, devices.yaml, index and support-status.

  • I recomputed sha256 and size_bytes for deye-svk.lua at this head: both match index.yaml and the manifest (0a4ed8af…, 22116).
  • Behaviour on a nil SoC: headroom stays 0/0 for that poll, which is the safe direction.
  • No secrets, new deps or new network destinations.

Safe to merge from my read. Note the PR says it is not reproduced on hardware, so the fix rests on reading the code path.

bat_soc is nil after a failed SoC read, and the headroom calculation then
raised a Lua error whenever battery_capacity_wh was set. Guard it the same
way as the 50-125k-svk drivers. Version 0.2.2 -> 0.2.3.

Reported and fixed in murre87/energywizard#215 by lazgeo.

Co-authored-by: lazgeo <gl@glic.se>
Signed-off-by: Emil Axfors <17743298+murre87@users.noreply.github.com>
@frahlg
frahlg force-pushed the fix/deye-svk-nil-soc branch from b20ede0 to e464a53 Compare December 1, 2026 07:27
@frahlg
frahlg merged commit 4bd5a6e into srcfl:main Dec 1, 2026
5 checks passed
@frahlg

frahlg commented Dec 1, 2026

Copy link
Copy Markdown
Member

Thanks, and thanks to lazgeo for the fix. Merged as 4bd5a6e, and deye-svk 0.2.3 is in the signed channel.

Main had moved, so we rebased your branch onto it, regenerated SUPPORT_STATUS.md and moved the CHANGELOG entry to the top. Your local branch no longer matches the fork; reset it before you reuse it.

Before merging we reproduced the crash in the Lua harness. With a battery capacity set and the SoC read failing, a poll on main raised attempt to perform arithmetic on a nil value (local 'bat_soc'). With the fix the poll completes.

frahlg added a commit that referenced this pull request Dec 1, 2026
Brings in deye-svk 0.2.3 (#224) and vag_vehicle 0.3.1 (#213). The only
conflict was CHANGELOG.md, where both sides added an Unreleased entry;
both are kept.

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.

3 participants