From 35b7209937735c6f57502469eb6a5e43420c2d59 Mon Sep 17 00:00:00 2001 From: t0bias-r Date: Mon, 4 Mar 2024 20:24:21 +0100 Subject: [PATCH] last_update_time should be newest carCapturedTimestamp of all fields and states --- custom_components/audiconnect/audi_connect_account.py | 10 ++++++++-- custom_components/audiconnect/audi_models.py | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/custom_components/audiconnect/audi_connect_account.py b/custom_components/audiconnect/audi_connect_account.py index 9a5c5d67..904f6da6 100644 --- a/custom_components/audiconnect/audi_connect_account.py +++ b/custom_components/audiconnect/audi_connect_account.py @@ -1,6 +1,6 @@ import json import time -from datetime import timedelta, datetime +from datetime import timedelta, datetime, timezone import logging import asyncio from typing import List @@ -438,7 +438,13 @@ async def update_vehicle_statusreport(self): status.data_fields[i].name: status.data_fields[i].value for i in range(0, len(status.data_fields)) } - self._vehicle.state["last_update_time"] = status.data_fields[0].send_time + + # last_update_time should be newest carCapturedTimestamp of all fields and states + self._vehicle.state["last_update_time"] = datetime(1970,1,1, tzinfo=timezone.utc) + for f in status.data_fields: + self._vehicle.state["last_update_time"] = max(self._vehicle.state["last_update_time"], f.measure_time) + for state in status.states: + self._vehicle.state["last_update_time"] = max(self._vehicle.state["last_update_time"], state["measure_time"]) for state in status.states: self._vehicle.state[state["name"]] = state["value"] except TimeoutError: diff --git a/custom_components/audiconnect/audi_models.py b/custom_components/audiconnect/audi_models.py index c1f03701..8304a379 100644 --- a/custom_components/audiconnect/audi_models.py +++ b/custom_components/audiconnect/audi_models.py @@ -56,7 +56,6 @@ def __init__(self, data): self.appendWindowState(data) self.appendDoorState(data) - self._tryAppendStateWithTs(data, "last_update_time", -1, ["measurements", "odometerStatus", "value", "carCapturedTimestamp"]) self._tryAppendStateWithTs(data, "carType", -1, ["fuelStatus", "rangeStatus", "value", "carType"]) self._tryAppendStateWithTs(data, "engineTypeFirstEngine", -2, ["fuelStatus", "rangeStatus", "value", "primaryEngine", "type"])