evsemaster 1.2.2__tar.gz → 1.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {evsemaster-1.2.2 → evsemaster-1.2.3}/PKG-INFO +1 -1
- {evsemaster-1.2.2 → evsemaster-1.2.3}/evsemaster/evse_protocol.py +21 -10
- {evsemaster-1.2.2 → evsemaster-1.2.3}/pyproject.toml +1 -1
- {evsemaster-1.2.2 → evsemaster-1.2.3}/LICENSE +0 -0
- {evsemaster-1.2.2 → evsemaster-1.2.3}/README.md +0 -0
- {evsemaster-1.2.2 → evsemaster-1.2.3}/evsemaster/__init__.py +0 -0
- {evsemaster-1.2.2 → evsemaster-1.2.3}/evsemaster/data_types.py +0 -0
|
@@ -269,24 +269,35 @@ class SimpleEVSEProtocol:
|
|
|
269
269
|
|
|
270
270
|
def _datetime_to_shanghai_epoch(self, dt: datetime) -> int:
|
|
271
271
|
"""
|
|
272
|
-
The EVSE handles time weirdly,
|
|
273
|
-
|
|
274
|
-
|
|
272
|
+
The EVSE handles time weirdly,
|
|
273
|
+
It expects the time to be whatever the requested time would be in Asia/Shanghai timezone.
|
|
274
|
+
While setting the time we can just swap the timezone to Asia/Shanghai and get the epoch from that.
|
|
275
275
|
"""
|
|
276
276
|
shanghai_tz = zoneinfo.ZoneInfo("Asia/Shanghai")
|
|
277
|
-
|
|
278
|
-
dt = dt.replace(tzinfo=shanghai_tz)
|
|
279
|
-
else:
|
|
280
|
-
dt = dt.astimezone(shanghai_tz)
|
|
277
|
+
dt = dt.replace(tzinfo=shanghai_tz)
|
|
281
278
|
return int(dt.timestamp())
|
|
282
279
|
|
|
283
280
|
def _shanghai_epoch_to_datetime(self, epoch: int) -> datetime:
|
|
284
281
|
"""
|
|
285
|
-
|
|
282
|
+
This EVSE returns timestamps in the weirdest way possible.
|
|
283
|
+
The timestamps it gives you back are TZ converted to our TZ but the time is all wrong
|
|
284
|
+
Because it gives the time it gives back is the time our epoch would happen IN SHANGHAI
|
|
285
|
+
So we need to calculate the offset between Shanghai and our local timezone
|
|
286
|
+
and apply that to the naive datetime we get from the epoch.
|
|
286
287
|
"""
|
|
287
288
|
shanghai_tz = zoneinfo.ZoneInfo("Asia/Shanghai")
|
|
288
|
-
|
|
289
|
-
|
|
289
|
+
local_tz = datetime.now().astimezone().tzinfo
|
|
290
|
+
|
|
291
|
+
now = datetime.now()
|
|
292
|
+
shanghai_now = now.replace(tzinfo=shanghai_tz)
|
|
293
|
+
local_now = now.replace(tzinfo=local_tz)
|
|
294
|
+
|
|
295
|
+
# Calculate the offset between Shanghai and local timezone, from their pov
|
|
296
|
+
offset = shanghai_now.utcoffset() - local_now.utcoffset()
|
|
297
|
+
|
|
298
|
+
naive_dt = datetime.fromtimestamp(epoch)
|
|
299
|
+
corrected_dt = naive_dt + offset
|
|
300
|
+
return corrected_dt.replace(tzinfo=local_tz)
|
|
290
301
|
|
|
291
302
|
async def set_nickname(self, nickname: str) -> bool:
|
|
292
303
|
"""Set the EVSE nickname."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|