Fix timezone issue (#92005)

pull/92025/head
Arjan 2023-04-25 21:02:02 +02:00 committed by GitHub
parent 083f42cce6
commit 74e3cac8b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 8 deletions

View File

@ -610,14 +610,6 @@ class GTFSDepartureSensor(SensorEntity):
self._include_tomorrow,
)
# Define the state as a UTC timestamp with ISO 8601 format
if not self._departure:
self._state = None
else:
self._state = self._departure["departure_time"].replace(
tzinfo=dt_util.UTC
)
# Fetch trip and route details once, unless updated
if not self._departure:
self._trip = None
@ -648,6 +640,19 @@ class GTFSDepartureSensor(SensorEntity):
)
self._agency = False
# Define the state as a UTC timestamp with ISO 8601 format
if not self._departure:
self._state = None
else:
if self._agency:
self._state = self._departure["departure_time"].replace(
tzinfo=dt_util.get_time_zone(self._agency.agency_timezone)
)
else:
self._state = self._departure["departure_time"].replace(
tzinfo=dt_util.UTC
)
# Assign attributes, icon and name
self.update_attributes()