From abc353c08309b131f2b8446c668556c384b4246a Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Fri, 10 Jun 2016 11:48:12 +0800 Subject: [PATCH] sensor/gtfs: add sanity check, origin earlier than destination (#2265) Previously experienced issues on routes where services operate in both directions. The query picked up not just paths where service goes from Origin -> Destination, but trips going Destination -> Origin, and shown bogus results. Ensure that this doesn't happen by requiring the origin station's stop_sequence value to be lower than the destination station. --- homeassistant/components/sensor/gtfs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/sensor/gtfs.py b/homeassistant/components/sensor/gtfs.py index 2355d03d34a935..ad954899e6def0 100644 --- a/homeassistant/components/sensor/gtfs.py +++ b/homeassistant/components/sensor/gtfs.py @@ -68,6 +68,7 @@ def get_next_departure(sched, start_station_id, end_station_id): AND time(origin_stop_time.departure_time) > time(:now_str) AND start_station.stop_id = :origin_station_id AND end_station.stop_id = :end_station_id + AND origin_stop_time.stop_sequence < destination_stop_time.stop_sequence ORDER BY origin_stop_time.departure_time LIMIT 1; """.format(day_name=day_name)) result = sched.engine.execute(sql_query, now_str=now_str,