cyberjunky / home-assistant-garmin_connect

The Garmin Connect integration allows you to expose data from Garmin Connect to Home Assistant.
MIT License
224 stars 29 forks source link

Enhancement:Last Synced on local timezone #154

Open ivercellino opened 3 months ago

ivercellino commented 3 months ago

Hello, nice integration, I use on my Home Assistant from some time now. I've noticed that the last_synced attributes were not in my timezone. I've made some coding myself to fix it, just for your information if you want to implement in the stable release:

In sensor.py import pytz, then in extra_state_attributes: ` tz = get_localzone() gmt_sync_timestamp = datetime.datetime.strptime(self.coordinator.data["lastSyncTimestampGMT"], "%Y-%m-%dT%H:%M:%S.%f") local_sync_timestamp = gmt_sync_timestamp.replace(tzinfo=pytz.utc).astimezone(tz)

attributes = { "last_synced": local_sync_timestamp, } `

Of course pytz was added as a riquerement.

Regards