mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
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:
parent
f90b89bc74
commit
c125c4af4f
@ -95,6 +95,9 @@ def get_next_departure(sched, start_station_id, end_station_id):
|
|||||||
for row in result:
|
for row in result:
|
||||||
item = row
|
item = row
|
||||||
|
|
||||||
|
if item == {}:
|
||||||
|
return None
|
||||||
|
|
||||||
today = datetime.datetime.today().strftime('%Y-%m-%d')
|
today = datetime.datetime.today().strftime('%Y-%m-%d')
|
||||||
departure_time_string = '{} {}'.format(today, item[2])
|
departure_time_string = '{} {}'.format(today, item[2])
|
||||||
arrival_time_string = '{} {}'.format(today, item[3])
|
arrival_time_string = '{} {}'.format(today, item[3])
|
||||||
@ -221,6 +224,13 @@ class GTFSDepartureSensor(Entity):
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
self._departure = get_next_departure(self._pygtfs, self.origin,
|
self._departure = get_next_departure(self._pygtfs, self.origin,
|
||||||
self.destination)
|
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']
|
self._state = self._departure['minutes_until_departure']
|
||||||
|
|
||||||
origin_station = self._departure['origin_station']
|
origin_station = self._departure['origin_station']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user