From 47c2109a0c9db87609c8daf5125049a7463bcd31 Mon Sep 17 00:00:00 2001 From: Mark Gascoyne Date: Thu, 6 Nov 2025 20:57:55 +0000 Subject: [PATCH] Fix: Handle None attributes in history data Fixes crash: 'NoneType' object has no attribute 'pop' Issue: Home Assistant history data can contain entries where 'attributes' key exists but has a None value instead of a dictionary. This causes a crash when trying to call .pop() on it. Solution: Changed from checking key existence ('attributes' in entry) to using entry.get('attributes') which returns None if the key doesn't exist or if its value is None, and only processes attributes when it's truthy. Reported by: daryl --- apps/predbat/ha.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/predbat/ha.py b/apps/predbat/ha.py index 40c671e75..97a51a01f 100644 --- a/apps/predbat/ha.py +++ b/apps/predbat/ha.py @@ -148,7 +148,7 @@ def update_entity(self, entity_id, new_history_data): # Filter useless data from history data for entry in new_history_data: - if "attributes" in entry: + if entry.get("attributes"): for attr in FILTER_ATTRIBUTES: entry["attributes"].pop(attr, None) for entry_attr in FILTER_ENTRIES: