fix(filter): exclude_entity_globs now overrides include_entity_globs (#33)#34
Merged
jonathan-gtd merged 1 commit intojonathan-gtd:masterfrom May 6, 2026
Conversation
…onathan-gtd#33) Closes jonathan-gtd#33. Home Assistant's `generate_filter` (case 4a in homeassistant.helpers.entityfilter) lets `include_entity_globs` short-circuit *over* `exclude_entity_globs`: when an entity matches an include glob, the exclude globs are never checked. Per the issue, scribe users expect the opposite — an `exclude_entity_globs` match should be a hard reject, even when an `include_entity_globs` entry would otherwise have matched. Wrap the result of `generate_filter` with a small `_build_exclude_priority_filter` that: 1. checks `exclude_entities` and `exclude_entity_globs` first, returning False on any match, 2. otherwise defers to the upstream filter. The existing HA semantics for everything else (domain include/exclude, entity-level include, no-filter pass-through) are preserved exactly. The wrapper is a no-op when neither `exclude_entities` nor `exclude_entity_globs` is configured, so the common-case fast path is unchanged. Tests: * test_exclude_entity_globs_overrides_include_entity_globs — exact reproduction from the issue (`include: sensor.*_temperature`, `exclude: sensor.processor_*`): `sensor.processor_temperature` is now excluded, `sensor.living_room_temperature` is still included, and `sensor.processor_use` (excluded only) stays excluded.
Owner
|
Thanks :) |
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.
Closes #33.
Reproduction (from the issue)
Expected:
sensor.processor_temperatureis excluded.Actual:
sensor.processor_temperatureis still recorded.Root cause
Home Assistant's
generate_filter(homeassistant.helpers.entityfilter._generate_filter_from_sets_and_pattern_lists, case 4a) letsinclude_entity_globsshort-circuit overexclude_entity_globs:So when both globs match, the include glob short-circuits to
Trueand the exclude glob is never consulted. Scribe users — and the issue reporter — expect the opposite.Fix
Wrap the result of
generate_filterwith a small_build_exclude_priority_filterthat:exclude_entitiesandexclude_entity_globsfirst; on any match the entity is rejected,The wrapper preserves HA semantics for everything else (domain include/exclude, entity-level include, no-filter pass-through), and is a no-op when no excludes are configured (common-case fast path).
Test plan
Added
test_exclude_entity_globs_overrides_include_entity_globsintests/test_filter.py— the exact reproduction from the issue (include: sensor.*_temperature,exclude: sensor.processor_*):sensor.living_room_temperature(include only) → recorded.sensor.processor_temperature(matches both) → excluded (was: incorrectly recorded).sensor.processor_use(exclude only) → excluded.Local results:
python3 -m astparses both modified files cleanly.generate_filteroutput.requirements_test.txt; CI will run it.