FlyingDiver / Indigo-Connected-Drive

Plugin for the BMW Connected Drive portal
MIT License
3 stars 0 forks source link

Mising time zone in timestamp field #15

Closed turribeach closed 2 years ago

turribeach commented 2 years ago
last_update : 24 May 2022 20:38:16 BST
timestamp : 24 May 2022 15:37:11

Script Error embedded script error: Script Error time data '24 May 2022 15:37:11 ' does not match format '%d %B %Y %H:%M:%S %Z' Script Error Exception Traceback (most recent call shown last):

In fact there is a space at the end so even without the %Z it fails to convert to date. I think it will be best to have both dates with time zone. Thanks!

FlyingDiver commented 2 years ago

Hmm. I'm using the exact same format string for both timestamps. The space at the end is because there's a space before where it's supposed to put the TZ. But it's not going there. So I think this is because the timestamp received from the API does not have timezone info in it.

FlyingDiver commented 2 years ago

I hate dealing with timezones.

FlyingDiver commented 2 years ago

Ok, got that one figured out. It'll force the TZ to your local system TZ. So hopefully that's what the timestamp returned by the API is set to.

FlyingDiver commented 2 years ago

Fixed in next release.

turribeach commented 2 years ago

Thanks! Now it's even better as the timestamp field shows in my local time zone rather than UTC. We are currently on BST which is UTC +1:00.

FlyingDiver commented 2 years ago

Turns out the API returns UTC, but not with the TZ actually set in the datetime object. So I had to force it to UTC, then convert to local time.

turribeach commented 2 years ago

Yes I saw the same thing with the prior version of the plugin, this is how I was converting it:

car_Last_Updated_DT = datetime.datetime.strptime(my_car.states["timestamp"], "%d %B %Y %H:%M:%S %Z")
#Tell the datetime object that it's in UTC time zone since  datetime objects are 'naive' by default
car_Last_Updated_DT = car_Last_Updated_DT.replace(tzinfo=utc_time_zone)

Many thanks for updates, all looks great! Are you interested in adding my geofencing alerting to the plugin? I can add a new issue and post the code I am using although I need to make some changes to remove all the window/door/lids states and use your new fields.

FlyingDiver commented 2 years ago

Open an issue and describe the functionality, but don't post any code yet.