Skip to content

Commit

Permalink
fix(EU): handle EU server time issue workaround (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuinigeRijder authored Oct 5, 2024
1 parent b1a2eef commit 437877d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
15 changes: 3 additions & 12 deletions hyundai_kia_connect_api/ApiImplType1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 11 additions & 1 deletion hyundai_kia_connect_api/Vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 437877d

Please sign in to comment.