Skip to content

Report 0, not unknown, when a feed has no entries - #196

Merged
iantrich merged 1 commit into
masterfrom
claude/empty-feed-zero
Nov 18, 2026
Merged

iantrich merged 1 commit into
masterfrom
claude/empty-feed-zero

Conversation

@iantrich

Copy link
Copy Markdown
Member

Fixes #182.

Problem

FeedParserSensor.native_value returned len(self.feed_entries) or None. So a feed that loaded fine but had no entries, or no entries matching match/exclude_match, showed as unknown. 0.1.12 reported 0. Templates such as state == 0 never matched, and states('sensor.x') | int without a default raised an error. With match, zero matching entries is the usual state for an alert-style sensor.

Fix

The sensor now reports the entry count, including 0. That gives three distinct states:

state meaning
0 the feed loaded and has no entries, or none match
unavailable the feed couldn't be fetched or parsed (coordinator UpdateFailed, unchanged)
unknown no feed has been loaded yet (coordinator.data is None)

The README's description of the sensor state now lists these. The repository doesn't contain the "When nothing matches, the state is unknown" note from the 1.3.0 release notes, so it can't be changed here. The next release notes should mention the change for anyone who adapted to unknown.

Tests

  • test_empty_feed_state_is_zero: a feed with an empty <channel> gives state 0 and entries: [].
  • test_no_matching_entries_state_is_zero: a YAML sensor whose match matches nothing gives state 0.
  • Both fail on master. The test harness's native_value mirrors the new behavior.

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


Generated by Claude Code

native_value returned `len(entries) or None`, so a feed that loaded fine
but had no entries, or none matching match/exclude_match, showed as
unknown. 0.1.12 reported 0, and templates such as `state == 0` or
`states(...) | int` broke on unknown. With match, this is the normal
state for alert-style sensors.

The sensor now reports the entry count, 0 included. It is unknown only
while no feed has been loaded yet; a feed that can't be fetched still
makes the entity unavailable.

Fixes #182

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:16
@iantrich
iantrich merged commit 3939232 into master Nov 18, 2026
10 checks passed
@iantrich
iantrich deleted the claude/empty-feed-zero branch November 18, 2026 01:04
@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.

Sensor state is unknown instead of 0 when a feed has no entries (or none match)

2 participants