Skip to content

Fix INA2xx MQTT energy restore handling - #6

Merged
KrX3D merged 5 commits into
0_15from
codex/review-and-fix-ina2xx-usermod-implementation
Feb 17, 2026
Merged

Fix INA2xx MQTT energy restore handling#6
KrX3D merged 5 commits into
0_15from
codex/review-and-fix-ina2xx-usermod-implementation

Conversation

@KrX3D

@KrX3D KrX3D commented Feb 5, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Prevent double-counting and incorrect resets when retained MQTT energy state is merged after boot or reconnects by deferring restore until time is synced and validating day/month boundaries.

Description

  • Added a MqttRestoreData buffer and flags (mqttRestorePending, mqttStateRestored) to collect retained MQTT energy payloads without immediately merging them (usermods/ina2xx_v2/ina2xx_v2.h).
  • Implemented isTimeValid() and applyMqttRestoreIfReady() to defer applying the retained state until localTime is valid and to only merge daily/monthly values when the restored reset day/month matches the device current day/month (usermods/ina2xx_v2/ina2xx_v2.cpp).
  • Changed onMqttMessage() to populate the restore buffer instead of directly adding values to the running totals, then trigger a safe apply attempt; added a call to applyMqttRestoreIfReady() from loop() so restore is applied as soon as conditions allow.
  • Centralized time validation in updateEnergy() to use isTimeValid() and added logging to help diagnose restore and merge decisions.

Testing

  • No automated tests were run against these changes during this update.
  • Static compile and basic code-path checks were considered during editing (manual review only).

Codex Task

@KrX3D
KrX3D merged commit b1a030e into 0_15 Feb 17, 2026
486 checks passed
@KrX3D
KrX3D deleted the codex/review-and-fix-ina2xx-usermod-implementation branch February 17, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant