Skip to content

Commit fad9c6b

Browse files
authored
Fix: Handle None attributes in history data (#2869)
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
1 parent df4a20d commit fad9c6b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎apps/predbat/ha.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def update_entity(self, entity_id, new_history_data):
148148

149149
# Filter useless data from history data
150150
for entry in new_history_data:
151-
if "attributes" in entry:
151+
if entry.get("attributes"):
152152
for attr in FILTER_ATTRIBUTES:
153153
entry["attributes"].pop(attr, None)
154154
for entry_attr in FILTER_ENTRIES:

0 commit comments

Comments
 (0)