Skip to content

Commit

Permalink
Fix Starline attributes timezone (home-assistant#105645)
Browse files Browse the repository at this point in the history
Co-authored-by: Franck Nijhof <[email protected]>
  • Loading branch information
Anonym-tsk and frenck authored Dec 27, 2023
1 parent e507d1c commit 4330452
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions homeassistant/components/starline/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
)


def _parse_datetime(dt_str: str | None) -> str | None:
if dt_str is None or (parsed := dt_util.parse_datetime(dt_str)) is None:
return None
return parsed.replace(tzinfo=dt_util.UTC).isoformat()


class StarlineAccount:
"""StarLine Account class."""

Expand Down Expand Up @@ -143,9 +149,7 @@ def device_info(device: StarlineDevice) -> DeviceInfo:
def gps_attrs(device: StarlineDevice) -> dict[str, Any]:
"""Attributes for device tracker."""
return {
"updated": dt_util.utc_from_timestamp(device.position["ts"])
.replace(tzinfo=None)
.isoformat(),
"updated": dt_util.utc_from_timestamp(device.position["ts"]).isoformat(),
"online": device.online,
}

Expand All @@ -155,7 +159,7 @@ def balance_attrs(device: StarlineDevice) -> dict[str, Any]:
return {
"operator": device.balance.get("operator"),
"state": device.balance.get("state"),
"updated": device.balance.get("ts"),
"updated": _parse_datetime(device.balance.get("ts")),
}

@staticmethod
Expand Down

0 comments on commit 4330452

Please sign in to comment.