Repository navigation
Add opt-in throttleMs option and flushEntityStates helper - #824
Draft
MindFreeze wants to merge 2 commits into
Draft
MindFreeze wants to merge 2 commits into
MindFreeze wants to merge 2 commits into
Conversation
1 of 12 tasks
Member
|
@copilot resolve the merge conflicts in this pull request |
…te-updates # Conflicts: # README.md # lib/states.ts # test/states.spec.ts
Contributor
This branch has not been deployed
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.
Adds a minimal opt-in throttling primitive to
entityStatesColl/subscribeEntityStates(Home Assistant 2022.4+), leaving the default per-message behavior unchanged:throttleMs?: number | (() => number)— folds updates arriving within the interval into one{ ...store.state }copy and publishes on the leading and trailing edge (coll.statestill updates on every message).0batches messages from the same task into a single microtask notification (same model as Publish entity state messages from one frame as one update #820).Infinitywhile a tab is hidden).flushEntityStates(conn)— flushes any pending updates immediately (e.g., onvisibilitychangeor after a user action).Browser/UI policy (slow-device detection,
document.hidden, user-action fast-paths) stays out of this library so consumers can plug in whatever strategy they need.Benchmarks (Chromium 158, 5,000 entities, 6× CPU throttling)
Paced stream — 10 WS frames/sec over 30 s (300 frames, 806 events, library + subscribers):
throttleMs: 0throttleMs: 0(per-frame)throttleMs: 100throttleMs: 250throttleMs: 1000Busy Lovelace dashboard stress test — 30 WS frames/sec over 15 s (6× CPU):
throttleMs: 0(per-frame)throttleMs: 250throttleMs: 1000throttleMs: () => Infinity+flushEntityStates(hidden tab)