Repository navigation
Report 0, not unknown, when a feed has no entries - #196
Merged
Merged
Conversation
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
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.
Fixes #182.
Problem
FeedParserSensor.native_valuereturnedlen(self.feed_entries) or None. So a feed that loaded fine but had no entries, or no entries matchingmatch/exclude_match, showed asunknown. 0.1.12 reported0. Templates such asstate == 0never matched, andstates('sensor.x') | intwithout a default raised an error. Withmatch, 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:0unavailableUpdateFailed, unchanged)unknowncoordinator.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 tounknown.Tests
test_empty_feed_state_is_zero: a feed with an empty<channel>gives state0andentries: [].test_no_matching_entries_state_is_zero: a YAML sensor whosematchmatches nothing gives state0.master. The test harness'snative_valuemirrors the new behavior.The full offline suite passes (241 tests). pre-commit (black, ruff, mypy) is clean, and
sensor.pycompiles under Python 3.13.Generated by Claude Code