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 GitHub
parent d82be09ed4
commit d0d1fb2da7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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