Skip to content

ina2xx_v2: fix CodeRabbit review findings from wled/WLED#4237 - #59

Merged
KrX3D merged 1 commit into
0_15from
fix/ina2xx-v2-coderabbit-review
Nov 26, 2026
Merged

KrX3D merged 1 commit into
0_15from
fix/ina2xx-v2-coderabbit-review

Conversation

@KrX3D

@KrX3D KrX3D commented Nov 25, 2026

Copy link
Copy Markdown
Owner
  • Fixes the CodeRabbit findings on Usermod INA219 + INA226 Current, Voltage & Power Sensor wled/WLED#4237 that are real bugs: the INA226 correction factor is now applied after setResistorRange(), the MQTT restore no longer times out at once or starts from an invalid total, and invalid energy and shunt values are rejected.
  • Energy integration uses unrounded power, keeps the day/month rollover for negative power, and doesn't count across a sensor re-init. The INA226 overflow flag is refreshed on every sample.
  • Saving settings no longer deletes the sensor in the web task while loop() uses it; the sensor is re-created in loop(). Enabling the usermod while MQTT is connected now subscribes. enabled is no longer read from the JSON state API.
  • Readme: ina2xx_v2 name, nodemcuv2 example, check_interval range, heartbeat vs. check interval, energy only after NTP sync.

Changelog

  • 2026-11-25: initial version. Compiles for esp32dev (INA219 and INA226, WLED_DEBUG) and nodemcuv2.

🤖 Generated with Claude Code

- INA226: apply the correction factor after setResistorRange(), which
  rewrote the calibration register with the uncorrected value
- MQTT restore: plain wait tick plus flag (millis()|1 could time out at
  once), only restore with a valid total, republish once restored
- Validate energy from the JSON API; reject shunt_resistor <= 0
- Integrate unrounded power, keep the day/month rollover for negative
  power, do not integrate across a re-init or disabled period
- INA226: refresh the overflow flag on every sample
- Re-create the sensor in loop() instead of the web task (use-after-free),
  subscribe when enabled while MQTT is connected, drop "enabled" from
  the JSON state API (re-enabling there could never work)
- Readme: ina2xx_v2 name, nodemcuv2 example, check_interval range,
  heartbeat vs check_interval, energy only after NTP sync

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@KrX3D

KrX3D commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

locally added

@KrX3D
KrX3D merged commit 9d441b5 into 0_15 Nov 26, 2026
@KrX3D
KrX3D deleted the fix/ina2xx-v2-coderabbit-review branch November 26, 2026 19:32
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