Skip to content

Stop writing a state on every poll: remove force_update - #197

Merged
iantrich merged 2 commits into
masterfrom
claude/remove-force-update
Nov 18, 2026
Merged

iantrich merged 2 commits into
masterfrom
claude/remove-force-update

Conversation

@iantrich

Copy link
Copy Markdown
Member

Fixes #185.

Why

_attr_force_update = True was added in 0.2.0 to work around #104. The entries list was changed in place, and Home Assistant compares attributes shallowly, so it missed changes to the same list object. Since 1.0, FeedReader.read() returns a new list on every poll, so Home Assistant sees changed entries without the workaround. The comment no longer described the code.

With force_update, every poll wrote a state and fired state_changed, even when the feed hadn't changed. That meant:

  • a recorder row in states for every poll,
  • automations triggered on the sensor ran on every poll instead of only when something changed,
  • logbook and history filled with updates that changed nothing.

Change

This removes _attr_force_update and its comment. A short comment explains why it isn't needed. The comment on _unrecorded_attributes now says "changes often" instead of "changes on every poll".

Tests

test_unchanged_poll_writes_no_state is the test the issue proposed:

  • Two polls of an unchanged feed fire no state_changed. This fails on master, which fires an event on every poll.
  • A poll whose entries change but whose count stays the same fires exactly one state_changed, with the new entries in the attributes.

The existing test_update_preserves_previous_attribute_snapshot still covers the new-list-per-read guarantee that makes this safe.

The full offline suite passes (240 tests). pre-commit (black, ruff, mypy) is clean, and sensor.py compiles under Python 3.13.

Release notes

  • An automation triggered on the sensor's state with no to:/from: used to run on every poll. It now runs only when the feed changes. Worth a line for anyone who relied on the old behavior as a poll tick.

Generated by Claude Code

_attr_force_update was added in 0.2.0 because the entries list was
changed in place, and Home Assistant's shallow attribute comparison
missed changes to the same list object (#104). Since 1.0,
FeedReader.read() returns a new list on every poll, so changed entries
are detected without it.

With force_update, every poll wrote a state and fired state_changed even
when the feed hadn't changed: a recorder row per poll, automations
triggered on the sensor running every poll, and logbook/history noise.

Fixes #185

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FvqVzfJq7yZSkZfSyG3YHT
@iantrich
iantrich marked this pull request as ready for review November 17, 2026 23:23
…-update

# Conflicts:
#	tests/test_integration.py
@iantrich
iantrich merged commit 137643c into master Nov 18, 2026
9 checks passed
@iantrich
iantrich deleted the claude/remove-force-update branch November 18, 2026 01:09
@iantrich iantrich mentioned this pull request Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove _attr_force_update = True from the sensor

2 participants