Prevent energy history returning zero in Teslemetry (#146202)

This commit is contained in:
Brett Adams 2025-06-10 23:00:02 +10:00 committed by Franck Nijhof
parent 8312780c47
commit e4140d71ab
No known key found for this signature in database
GPG Key ID: AB33ADACE7101952

View File

@ -195,9 +195,13 @@ class TeslemetryEnergyHistoryCoordinator(DataUpdateCoordinator[dict[str, Any]]):
raise UpdateFailed(e.message) from e raise UpdateFailed(e.message) from e
# Add all time periods together # Add all time periods together
output = dict.fromkeys(ENERGY_HISTORY_FIELDS, 0) output = dict.fromkeys(ENERGY_HISTORY_FIELDS, None)
for period in data.get("time_series", []): for period in data.get("time_series", []):
for key in ENERGY_HISTORY_FIELDS: for key in ENERGY_HISTORY_FIELDS:
output[key] += period.get(key, 0) if key in period:
if output[key] is None:
output[key] = period[key]
else:
output[key] += period[key]
return output return output