vingerha / gtfs2

Support GTFS in Home Assistant GUI-only
https://github.com/vingerha/gtfs2
MIT License
65 stars 4 forks source link

Unable to set up a Real Time update for scheduled departures in your vicintiy #61

Closed jzucker2 closed 2 months ago

jzucker2 commented 2 months ago

Describe the bug

I can add a local stop and it works for scheduled departures but throws weird errors when trying to add real time afterwards.

Seems like the response data is expected to be a dictionary but ends up being a list?

But then it also seems that when throwing that exception, another exception is generated over scoping around the error?

Steps/data to reproduce the behavior, e.g.

I followed directions listed. Note: I only set up a local stop but didn't do any lines (wasn't sure if that was necessary tbh)

  1. set up a data source for Bart
  2. Performed service call to download real time data using http://api.bart.gov/gtfsrt/tripupdate.aspx
  3. Add entry -> scheduled
  4. Select source -> bart, Object used -> (My apartment)
  5. Then it loaded up the local stop and showed data.
  6. Clicked "configure" and added RT data using http://host.docker.internal:8123/local/gtfs2/bart.rt

Release used Using gtfs2 0.4.5 Home Assistant in Docker: https://github.com/home-assistant/core/releases/tag/2024.4.3

Additional

home-assistant  | 2024-04-22 15:54:01.740 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Successfully updated trip data
home-assistant  | 2024-04-22 15:54:01.746 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Search departure times for route: 2, trip: 1509105, type: trip, direction: 0
home-assistant  | 2024-04-22 15:54:01.747 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Entity found params - group: trip, route_id: , direction_id: 0, self_trip_id: 1509105, with rt trip: {'trip_id': '1509105', 'start_time': '', 'start_date': '', 'route_id': '', 'direction_id': '0'}
home-assistant  | 2024-04-22 15:54:01.747 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Departure times Route Trip: {}
home-assistant  | 2024-04-22 15:54:01.747 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_helper] Departure time: 2024-04-22 15:42:00-07:00
home-assistant  | 2024-04-22 15:54:01.747 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_helper] Row from query: {'stop_id': '16TH', 'stop_name': '16th Street / Mission', 'latitude': 37.765176, 'longitude': -122.419755, 'trip_id': '1508853', 'trip_headsign': 'SFO / SF / Richmond', 'direction_id': 0, 'departure_time': '15:44:00', 'route_long_name': 'Millbrae/Daly City to Richmond', 'route_short_name': 'Red-N', 'route_type': 1, 'today': 1, 'tomorrow': 1, 'start_date': '2024-01-16', 'end_date': '2024-08-09', 'calendar_date': '2024-04-22', 'today_cd': 0, 'route_id': '8'}
home-assistant  | 2024-04-22 15:54:01.747 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_helper] Find rt for local stop route: 8 - direction: 0 - stop: 16TH
home-assistant  | 2024-04-22 15:54:01.747 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] GTFS RT get_feed_entities for url: file://www/gtfs2/Near Albion Bart Stop_localstop.rt , headers: None, label: trip data
home-assistant  | 2024-04-22 15:54:01.748 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Successfully updated trip data
home-assistant  | 2024-04-22 15:54:01.755 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Search departure times for route: 8, trip: 1508853, type: trip, direction: 0
home-assistant  | 2024-04-22 15:54:01.755 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Entity found params - group: trip, route_id: , direction_id: 0, self_trip_id: 1508853, with rt trip: {'trip_id': '1508853', 'start_time': '', 'start_date': '', 'route_id': '', 'direction_id': '0'}
home-assistant  | 2024-04-22 15:54:01.755 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Departure times Route Trip: {}
home-assistant  | 2024-04-22 15:54:01.755 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_helper] Departure time: 2024-04-22 15:44:00-07:00
home-assistant  | 2024-04-22 15:54:01.757 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_helper] Row from query: {'stop_id': '16TH', 'stop_name': '16th Street / Mission', 'latitude': 37.765176, 'longitude': -122.419755, 'trip_id': '1508752', 'trip_headsign': 'SF / OAK Airport / Berryessa', 'direction_id': 0, 'departure_time': '15:46:00', 'route_long_name': 'Daly City to Berryessa/North San Jose', 'route_short_name': 'Green-N', 'route_type': 1, 'today': 1, 'tomorrow': 1, 'start_date': '2024-01-16', 'end_date': '2024-08-09', 'calendar_date': '2024-04-22', 'today_cd': 0, 'route_id': '6'}
home-assistant  | 2024-04-22 15:54:01.757 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_helper] Find rt for local stop route: 6 - direction: 0 - stop: 16TH
home-assistant  | 2024-04-22 15:54:01.757 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] GTFS RT get_feed_entities for url: file://www/gtfs2/Near Albion Bart Stop_localstop.rt , headers: None, label: trip data
home-assistant  | 2024-04-22 15:54:01.758 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Successfully updated trip data
home-assistant  | 2024-04-22 15:54:01.767 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Search departure times for route: 6, trip: 1508752, type: trip, direction: 0
home-assistant  | 2024-04-22 15:54:01.767 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Entity found params - group: trip, route_id: , direction_id: 0, self_trip_id: 1508752, with rt trip: {'trip_id': '1508752', 'start_time': '', 'start_date': '', 'route_id': '', 'direction_id': '0'}
home-assistant  | 2024-04-22 15:54:01.767 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Stop found: {'stop_sequence': 0, 'stop_id': '16TH', 'arrival': {'delay': 97, 'time': 1713826117}, 'departure': {'delay': 97, 'time': 1713826137}}
home-assistant  | 2024-04-22 15:54:01.767 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Not using realtime stop data for old due-in-minutes: -5
home-assistant  | 2024-04-22 15:54:01.767 DEBUG (SyncWorker_39) [custom_components.gtfs2.gtfs_rt_helper] Departure times Route Trip: {'': {'0': {'16TH': {'departures': [], 'delays': [97]}}}}
home-assistant  | 2024-04-22 15:54:01.769 ERROR (MainThread) [custom_components.gtfs2.coordinator] Unexpected error fetching d36040045cde5e5e8718e60b81f950a4 data: name 'err' is not defined
home-assistant  | Traceback (most recent call last):
home-assistant  |   File "/config/custom_components/gtfs2/coordinator.py", line 246, in _async_update_data
home-assistant  |     self._data["local_stops_next_departures"] = await self.hass.async_add_executor_job(
home-assistant  |                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
home-assistant  |   File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
home-assistant  |     result = self.fn(*self.args, **self.kwargs)
home-assistant  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
home-assistant  |   File "/config/custom_components/gtfs2/gtfs_helper.py", line 888, in get_local_stops_next_departures
home-assistant  |     delays = next_service.get(self._route, {}).get(self._direction, {}).get(self._stop_id, []).get("delays", [])
home-assistant  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
home-assistant  | AttributeError: 'list' object has no attribute 'get'
home-assistant  | 
home-assistant  | During handling of the above exception, another exception occurred:
home-assistant  | 
home-assistant  | Traceback (most recent call last):
home-assistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
home-assistant  |     self.data = await self._async_update_data()
home-assistant  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
home-assistant  |   File "/config/custom_components/gtfs2/coordinator.py", line 250, in _async_update_data
home-assistant  |     raise UpdateFailed(f"Error in getting local stops data: {err}")
home-assistant  |                                                              ^^^
home-assistant  | NameError: name 'err' is not defined
home-assistant  | 2024-04-22 15:54:01.774 DEBUG (MainThread) [custom_components.gtfs2.coordinator] Finished fetching d36040045cde5e5e8718e60b81f950a4 data in 0.123 seconds (success: False)
home-assistant  | 2024-04-22 15:54:01.775 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up gtfs2 platform for sensor
home-assistant  | Traceback (most recent call last):
home-assistant  |   File "/config/custom_components/gtfs2/coordinator.py", line 246, in _async_update_data
home-assistant  |     self._data["local_stops_next_departures"] = await self.hass.async_add_executor_job(
home-assistant  |                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
home-assistant  |   File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
home-assistant  |     result = self.fn(*self.args, **self.kwargs)
home-assistant  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
home-assistant  |   File "/config/custom_components/gtfs2/gtfs_helper.py", line 888, in get_local_stops_next_departures
home-assistant  |     delays = next_service.get(self._route, {}).get(self._direction, {}).get(self._stop_id, []).get("delays", [])
home-assistant  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
home-assistant  | AttributeError: 'list' object has no attribute 'get'
home-assistant  | 
home-assistant  | During handling of the above exception, another exception occurred:
home-assistant  | 
home-assistant  | Traceback (most recent call last):
home-assistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
home-assistant  |     self.data = await self._async_update_data()
home-assistant  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
home-assistant  |   File "/config/custom_components/gtfs2/coordinator.py", line 250, in _async_update_data
home-assistant  |     raise UpdateFailed(f"Error in getting local stops data: {err}")
home-assistant  |                                                              ^^^
home-assistant  | NameError: name 'err' is not defined
home-assistant  | 
home-assistant  | The above exception was the direct cause of the following exception:
home-assistant  | 
home-assistant  | Traceback (most recent call last):
home-assistant  |   File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform
home-assistant  |     await asyncio.shield(awaitable)
home-assistant  |   File "/config/custom_components/gtfs2/sensor.py", line 75, in async_setup_entry
home-assistant  |     await coordinator.async_config_entry_first_refresh()
home-assistant  |   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 287, in async_config_entry_first_refresh
home-assistant  |     raise ex
home-assistant  | homeassistant.exceptions.ConfigEntryNotReady: name 'err' is not defined
jzucker2 commented 2 months ago

I did just notice this https://github.com/vingerha/gtfs2/issues/15 ... so it seems that Bart RT is just not supported?

vingerha commented 2 months ago

Yes....indeed, I tried to get it reworked to json but the aspx is making my life not so great. I am not too well known on how to get data from the aspx and BART is not providing protobuf as well....I asked them, no response