perf: rate-limit + delta-only PSU time sync#22
Open
malaiwah wants to merge 1 commit into
Open
Conversation
The original on_time_sync action fired six Modbus writes (year, month,
day, hour, minute, second) every time the HA time component synced —
which can be on every reconnect. That contended with sensor polling
and wore the PSU's flash for no benefit on a clock that hasn't moved.
This change:
* persists the last successful sync timestamp in flash (global)
* skips entirely if the last sync is < 24h old AND the PSU clock
is already within 30 s of HA time
* only writes the individual date/time registers that actually differ
Behaviour on a freshly-flashed device or after a clock-drift event is
unchanged. Steady-state cost drops from ~6 writes per reconnect to 0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #21
Replaces the unconditional 6-write
on_time_syncaction with:last_psu_time_syncglobal (restore_value: yes)make_call().set_value().perform()that touches only the date components that actually differVerification
esphome configpasses for both YAMLsesphome compileclean (lambdas validate; RAM 46.2% / Flash 49.5%)Boot-time behaviour, briefly
restore_valuelives in RTC RAM by default → preserved across software reboots, reset on cold boot. First boot after power-loss triggers one sync (after first poll completes — the NaN guard prevents writing against uninitialised state).restore_valuepersists in NVS across cold boots → only one sync ever (until 24h drift).Disclosure
Drafted with Claude (Anthropic). Author-reviewed.