Skip to content

Commit

Permalink
last_update_time should be newest carCapturedTimestamp of all fields …
Browse files Browse the repository at this point in the history
…and states
  • Loading branch information
t0bias-r committed Mar 4, 2024
1 parent 1e2d8de commit 35b7209
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 8 additions & 2 deletions custom_components/audiconnect/audi_connect_account.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion custom_components/audiconnect/audi_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 35b7209

Please sign in to comment.