Skip to content

Commit 21d0f2b

Browse files
committed
Add attribute for next arrivals
1 parent 02db550 commit 21d0f2b

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

custom_components/gtfs2/gtfs_helper.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,12 @@ def get_next_departure(hass, _data):
394394
timetable_remaining_line = []
395395
timetable_remaining_headsign = []
396396
timetable_upcoming_trips = []
397+
timetable_upcoming_arrivals = []
397398
for key, value in sorted(timetable.items()):
398399
upcoming = datetime.datetime.strptime(key[0], "%Y-%m-%d %H:%M:%S").replace(tzinfo=timezone)
400+
upcoming_arrival = datetime.datetime.combine(
401+
upcoming.date(),
402+
datetime.datetime.strptime(value["dest_arrival_time"],"%H:%M:%S").time()).replace(tzinfo=timezone_dest)
399403
#_LOGGER.debug ("Upcoming list values for departure in defined tz: %s, Now_in_defined_timezone_plus_offset: %s, key: %s, value %s", upcoming, now_local_tz, key, value)
400404
if upcoming > now_local_tz:
401405
_LOGGER.debug("Adding list item for departure/key: %s, Upcoming: %s, Value: %s", key, upcoming, value )
@@ -408,6 +412,9 @@ def get_next_departure(hass, _data):
408412
timetable_upcoming_trips.append(
409413
str(value["trip_id"])
410414
)
415+
timetable_upcoming_arrivals.append(
416+
dt_util.as_utc(upcoming_arrival).isoformat()
417+
)
411418

412419
#_LOGGER.debug(
413420
# "Timetable Remaining Departures on this Start/Stop, per line: %s",
@@ -421,6 +428,10 @@ def get_next_departure(hass, _data):
421428
# "Timetable Remaining Trips on this Start/Stop: %s",
422429
# timetable_upcoming_trips,
423430
#)
431+
#_LOGGER.debug(
432+
# "Timetable arrival times on this Start/Stop: %s",
433+
# timetable_upcoming_arrivals,
434+
#)
424435

425436

426437
# Format arrival and departure dates and times, accounting for the
@@ -511,6 +522,7 @@ def get_next_departure(hass, _data):
511522
"next_departures_lines": timetable_remaining_line,
512523
"next_departures_headsign": timetable_remaining_headsign,
513524
"next_departures_trip_id": timetable_upcoming_trips,
525+
"next_departures_destination_arrival_times": timetable_upcoming_arrivals,
514526
}
515527

516528
return data_returned

custom_components/gtfs2/sensor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,14 @@ def _update_attrs(self): # noqa: C901 PLR0911
429429
self._attributes["next_departures_trips"] = self._departure[
430430
"next_departures_trip_id"][:10]
431431

432+
# Add next departures arrivals
433+
prefix = "next_departures_destination_arrival_times"
434+
self._attributes["next_departures_destination_arrival_times"] = []
435+
if self._next_departures:
436+
self._attributes["next_departures_destination_arrival_times"] = self._departure[
437+
"next_departures_destination_arrival_times"][:10]
438+
439+
432440
self._attributes["gtfs_updated_at"] = self.coordinator.data[
433441
"gtfs_updated_at"]
434442

0 commit comments

Comments
 (0)