From 27bb50428ede53478db3a23c51c2904ccf4f46d3 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 6 Mar 2024 08:42:22 +1000 Subject: [PATCH] Fix timezone in timestamp parsing --- teslemetry_stream/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/teslemetry_stream/__init__.py b/teslemetry_stream/__init__.py index 5d1654b..22f9db5 100644 --- a/teslemetry_stream/__init__.py +++ b/teslemetry_stream/__init__.py @@ -3,7 +3,7 @@ import asyncio import json import logging -from datetime import datetime +from datetime import datetime, timezone from .const import TelemetryFields, TelemetryAlerts @@ -192,7 +192,9 @@ async def __anext__(self) -> dict: if self.parse_timestamp: main, _, ns = data["createdAt"].partition(".") data["timestamp"] = int( - datetime.strptime(main, "%Y-%m-%dT%H:%M:%S").timestamp() + datetime.strptime(main, "%Y-%m-%dT%H:%M:%S") + .replace(tzinfo=timezone.utc) + .timestamp() ) * 1000 + int(ns[:3]) LOGGER.debug("event %s", json.dumps(data)) return data