From 437877d6528dea0d056d5020d848c9828f4eb0a2 Mon Sep 17 00:00:00 2001 From: Zuinige Rijder <90704821+ZuinigeRijder@users.noreply.github.com> Date: Sat, 5 Oct 2024 08:06:05 +0200 Subject: [PATCH] fix(EU): handle EU server time issue workaround (#643) --- hyundai_kia_connect_api/ApiImplType1.py | 15 +++------------ hyundai_kia_connect_api/Vehicle.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/hyundai_kia_connect_api/ApiImplType1.py b/hyundai_kia_connect_api/ApiImplType1.py index e89ad900..0fa22eb8 100644 --- a/hyundai_kia_connect_api/ApiImplType1.py +++ b/hyundai_kia_connect_api/ApiImplType1.py @@ -48,18 +48,9 @@ def _get_authenticated_headers( def _update_vehicle_properties_ccs2(self, vehicle: Vehicle, state: dict) -> None: if get_child_value(state, "Date"): - # `Date` field is in UTC time - if vehicle.last_updated_at: - vehicle.last_updated_at = parse_datetime( - get_child_value(state, "Date"), dt.timezone.utc - ) - elif vehicle.last_updated_at < parse_datetime( - get_child_value(state, "Date"), dt.timezone.utc - ): - vehicle.last_updated_at = parse_datetime( - get_child_value(state, "Date"), dt.timezone.utc - ) - + vehicle.last_updated_at = parse_datetime( + get_child_value(state, "Date"), self.data_timezone + ) else: vehicle.last_updated_at = dt.datetime.now(self.data_timezone) diff --git a/hyundai_kia_connect_api/Vehicle.py b/hyundai_kia_connect_api/Vehicle.py index 32ab5417..5b2cb75b 100644 --- a/hyundai_kia_connect_api/Vehicle.py +++ b/hyundai_kia_connect_api/Vehicle.py @@ -356,7 +356,17 @@ def last_updated_at(self): @last_updated_at.setter def last_updated_at(self, value): - self._last_updated_at = get_safe_local_datetime(value) + # workaround for: Timestamp of "last_updated_at" sensor is wrong #931 + # https://github.com/Hyundai-Kia-Connect/kia_uvo/issues/931#issuecomment-2381569934 + newest_updated_at = get_safe_local_datetime(value) + previous_updated_at = self._last_updated_at + if newest_updated_at and previous_updated_at: # both filled + if newest_updated_at < previous_updated_at: + utcoffset = newest_updated_at.utcoffset() + newest_updated_at_corrected = newest_updated_at + utcoffset + if newest_updated_at_corrected >= previous_updated_at: + newest_updated_at = newest_updated_at_corrected + self._last_updated_at = newest_updated_at @property def location_latitude(self):