fix: Home Assistant event filtering closed by default#1169
Merged
Conversation
Previously, when no watch_domains or watch_entities were configured, ALL state_changed events passed through to the agent, causing users to be flooded with notifications for every HA entity change. Now events are dropped by default unless the user explicitly configures: - watch_domains: list of domains to monitor (e.g. climate, light) - watch_entities: list of specific entity IDs to monitor - watch_all: true (new option — opt-in to receive all events) A warning is logged at connect time if no filters are configured, guiding users to set up their HA platform config. All 49 gateway HA tests + 52 HA tool tests pass.
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.
Problem
A user reported that every time any Home Assistant event occurs, Hermes notifies them — even for completely unrelated entity changes (CPU temp fluctuating, uptime counters, etc.).
Root Cause
In
homeassistant.py_handle_ha_event(), the event filter logic was:When neither
watch_domainsnorwatch_entitieswas configured (both empty sets), the condition wasFalseand the entire filter block was skipped. Every singlestate_changedevent from HA passed through to the agent, which processed it and sent a persistent notification back.Fix
Closed by default — events are now dropped unless the user explicitly opts in with one of:
watch_domains: list of HA domains to monitor (e.g.climate,light,binary_sensor)watch_entities: list of specific entity IDs to monitorwatch_all: true(new option) — explicit opt-in to receive ALL eventsA warning is logged at connect time if no filters are configured, guiding users to set up their config.
Changes
gateway/platforms/homeassistant.py: Addedwatch_allconfig option, addedelif not self._watch_all: returnguard, added connect-time warning logtests/gateway/test_homeassistant.py: Updated tests to reflect new default behavior, addedtest_no_filters_blocks_everything,test_watch_all_passes_everything,test_watch_all_parsedTest Results
All 49 gateway HA tests + 52 HA tool tests pass.