Fix for GTFS sensor (#4828)

* Fix for GTFS sensor

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>

* GTFS fix

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>
This commit is contained in:
Hugo Dupras 2016-12-16 06:40:33 +01:00 committed by Paulus Schoutsen
parent f90b89bc74
commit c125c4af4f

View File

@ -95,6 +95,9 @@ def get_next_departure(sched, start_station_id, end_station_id):
for row in result:
item = row
if item == {}:
return None
today = datetime.datetime.today().strftime('%Y-%m-%d')
departure_time_string = '{} {}'.format(today, item[2])
arrival_time_string = '{} {}'.format(today, item[3])
@ -221,6 +224,13 @@ class GTFSDepartureSensor(Entity):
with self.lock:
self._departure = get_next_departure(self._pygtfs, self.origin,
self.destination)
if not self._departure:
self._state = 0
self._attributes = {'Info': 'No more bus today'}
if self._name == '':
self._name = (self._custom_name or "GTFS Sensor")
return
self._state = self._departure['minutes_until_departure']
origin_station = self._departure['origin_station']