Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions custom_components/feedparser/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ class FeedParserSensor(CoordinatorEntity[FeedparserCoordinator], SensorEntity):
# `strings.json` has nothing to carry for it.
_attr_translation_key = "feed"
_attr_attribution = "Data retrieved using RSS feedparser"
# `entries` and `channel` are the bulk of the attributes (up to the
# recorder's size limit) and are rewritten whenever the feed changes. A card
# reads them from the live state, so a copy per change in the history only
# grows the database. `feed_url` stays recorded.
_unrecorded_attributes = frozenset({"entries", "channel"})

def __init__(
self: FeedParserSensor,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ def test_attributes_stay_below_recorder_limit(feed: FeedSource) -> None:
), f"{feed.name}: attributes are {size} bytes, the recorder would drop them"


def test_entries_and_channel_stay_out_of_the_recorder(feed: FeedSource) -> None:
"""Test that the large attributes are not written to the history.

They still reach the state; only the recorder skips them. `feed_url` is small
and identifies the feed, so it stays recorded.
"""
parsed = parse_local_feed(feed, show_topn=DEFAULT_TOPN)
sensor = build_sensor(parsed, feed.name)
assert {"entries", "channel"} <= sensor._unrecorded_attributes # noqa: SLF001
assert "feed_url" not in sensor._unrecorded_attributes # noqa: SLF001
assert {"entries", "channel", "feed_url"} <= set(sensor.extra_state_attributes)


def test_yaml_without_show_topn_keeps_every_entry() -> None:
"""Test that a YAML sensor is not silently capped by the new default.

Expand Down
Loading