Repository navigation
Conversation
Pass `state_info` with `unrecorded_attributes` on every async_set call so HA's recorder strips `smart_icons_color` and `smart_icons_background` before persisting state-changed events to the state_attributes table. The state_changed event still fires — the painter needs it for live updates — but the database-side payload shrinks, and adjacent state_attributes rows deduplicate better since the "real" entity attributes change less often than our decoration writes. Implementation notes: - `_SMART_ICONS_UNRECORDED_ATTRS` declares the keys to exclude. `ATTR_ICON` is intentionally NOT included — it's HA's standard glyph attribute that other integrations and templates may legitimately change, so recording its history is correct. - `_state_info_excluding_smart_icons` merges our exclusion set with the target's existing `unrecorded_attributes` (if any). Some integrations declare their own (e.g. a sensor that excludes `last_reset` from history); a bare override would re-enable recording of attrs the integration author chose to exclude. The merge preserves both. - Both write paths (`_apply_target` and `_release_target`) carry the same state_info — uniform contract; the recorder hint travels with every write the injector produces. This is a recorder-disk optimization, not a memory fix — it does not affect the in-memory event bus traffic, only the persisted row payload size and deduplication. Tests: - Asserts state_info carries our two attribute keys on a normal apply write. - Asserts the merge preserves the entity-owner's existing unrecorded_attributes declaration when present. - Asserts state_info also travels with the release write (consistency of contract). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
3 of 4 tasks
Owner
Author
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.
Summary
Tell HA's recorder to strip
smart_icons_colorandsmart_icons_backgroundfrom the JSON it persists to thestate_attributestable. Thestate_changedevent still fires (the painter needs it for live updates) — only the database-side payload changes:state_attributesrows shrink (our 2 attrs gone from the JSON)Motivated by a question that came up during a separate memory-leak investigation: even though the leak turned out not to be Smart Icons, recorder-side noise reduction is a real ongoing concern for installs with broad glob rules (e.g.
sensor.*mapping rules that re-evaluate on every sensor change).Mechanism
HA's recorder reads
state.state_info["unrecorded_attributes"](afrozenset[str]) and strips matching attribute keys before writing the row. The set is per-State, populated via the optionalstate_infoparameter tohass.states.async_set. Seedb_schema.pyin HA recorder for the exact filter.Two implementation points worth noting:
ATTR_ICONis NOT excluded. It's HA's standard glyph attribute — other integrations, templates, and user automations legitimately change it. Recording the history oficonchanges is correct; only our two namespaced extensions are recorder noise.unrecorded_attributesis load-bearing. Some integrations declare their own (e.g. a sensor that excludeslast_resetfrom history). A naïvestate_info=override would clobber the entity author's declaration._state_info_excluding_smart_iconsmerges both sets.What this is NOT
Not a memory fix. The reporter's HA install was leaking memory; investigation confirmed it's not Smart Icons (memory continued climbing with the integration uninstalled). This PR addresses a related-but-separate concern: recorder DB growth from our writes.
Test plan
tests/test_injector.py: