Make history coordinator more reliable in Tesla Fleet (#149854)

This commit is contained in:
Brett Adams 2025-08-03 03:54:19 +10:00 committed by GitHub
parent 3e615fd373
commit 7dd2b9e422
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -247,11 +247,15 @@ class TeslaFleetEnergySiteHistoryCoordinator(DataUpdateCoordinator[dict[str, Any
raise UpdateFailed(e.message) from e
self.updated_once = True
if not data or not isinstance(data.get("time_series"), list):
raise UpdateFailed("Received invalid data")
# Add all time periods together
output = dict.fromkeys(ENERGY_HISTORY_FIELDS, 0)
for period in data.get("time_series", []):
for key in ENERGY_HISTORY_FIELDS:
output[key] += period.get(key, 0)
if key in period:
output[key] += period[key]
return output