Skip to content

Commit

Permalink
Fix timezone issue (home-assistant#92005)
Browse files Browse the repository at this point in the history
  • Loading branch information
vingerha authored Apr 25, 2023
1 parent 083f42c commit 74e3cac
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions homeassistant/components/gtfs/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,6 @@ def update(self) -> None:
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
Expand Down Expand Up @@ -648,6 +640,19 @@ def update(self) -> None:
)
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()

Expand Down

0 comments on commit 74e3cac

Please sign in to comment.