Skip to content

Commit

Permalink
Add status (#5)
Browse files Browse the repository at this point in the history
* Fix errors

* Update sensor.py

* Update sensor.py

* Update sensor.py

* Update sensor.py

* Add status field
  • Loading branch information
Neil Saunders authored Aug 23, 2022
1 parent 92b4679 commit 2fc3ed6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion custom_components/realtime_trains_api/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,20 @@ async def _add_journey_data(self, train, scheduled_departure, estimated_departur
if stop['crs'] == self._journey_end and stop['displayAs'] != 'ORIGIN':
scheduled_arrival = _timestamp(_to_colonseparatedtime(stop['gbttBookedArrival']), scheduled_departure)
estimated_arrival = _timestamp(_to_colonseparatedtime(stop['realtimeArrival']), scheduled_departure)

status = "OK"
if 'CANCELLED' in stop['displayAs']:
status = "Cancelled"
elif estimated_arrival > scheduled_arrival:
status = "Delayed"

newtrain = {
"stops_of_interest": stopsOfInterest,
"scheduled_arrival": scheduled_arrival.strftime(STRFFORMAT),
"estimate_arrival": estimated_arrival.strftime(STRFFORMAT),
"journey_time_mins": _delta_secs(estimated_arrival, estimated_departure) // 60,
"stops": stopCount
"stops": stopCount,
"status": status
}
train.update(newtrain)
found = True
Expand Down

0 comments on commit 2fc3ed6

Please sign in to comment.