From 8280841377de9818a7e6cd3f399081347d4b765f Mon Sep 17 00:00:00 2001 From: ctbjdm <42102637+ctbjdm@users.noreply.github.com> Date: Sun, 3 May 2026 12:50:47 -0400 Subject: [PATCH] Apply exclusions config to entity inventory The script reads the `exclusions` config but never applies it. Domain, pattern, area, and entity exclusions are silently ignored, so the entity inventory always lists every entity regardless of config. Fix: filter `self.states` once after fetch, using the existing `_should_exclude_entity()` method. All downstream functions (`_count_entities_by_domain`, `generate_entity_inventory`, etc.) work on the filtered list automatically with no further changes. Adds an "Excluded N entities (X -> Y)" log line so you can see at runtime how many entities your config filtered out. --- ha_docs_production.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ha_docs_production.py b/ha_docs_production.py index cb1ab81..66517f1 100644 --- a/ha_docs_production.py +++ b/ha_docs_production.py @@ -199,6 +199,22 @@ def __init__(self, ha_api: HomeAssistantAPI, config: Dict, styled: bool = True): self.custom_sections = config.get('custom_sections', {}) self.exclusions = config.get('exclusions', {}) +def _filter_excluded_entities(self): + """Apply exclusions config to self.states. Called once after states are loaded.""" + if not hasattr(self, 'exclusions') or not self.exclusions: + return + original_count = len(self.states) + self.states = [ + s for s in self.states + if not self._should_exclude_entity( + s['entity_id'], + s.get('attributes', {}).get('friendly_name', ''), + '' + ) + ] + excluded = original_count - len(self.states) + if excluded > 0: + print(f" 🚫 Excluded {excluded} entities ({original_count} -> {len(self.states)})") def _should_exclude_entity(self, entity_id: str, friendly_name: str = "", area: str = "") -> bool: """Check if entity should be excluded based on config""" import re @@ -236,6 +252,7 @@ def fetch_data(self): print(" 📡 Fetching entity states...") self.states = self.ha.get_states() + self._filter_excluded_entities() print(" 📡 Fetching services...") self.services = self.ha.get_services() @@ -1545,4 +1562,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main()