vingerha / gtfs2

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

Local stop departures not working with RT data #50

Closed mxbssn closed 2 months ago

mxbssn commented 2 months ago

Local stop departures not working when setting up real time integration. Works fine without it.

Steps/data to reproduce the behavior, e.g. Add a local stop Once set up, add the real time integration.

Release used 0.4.4

Additional Error getting gtfs realtime data, for origin: 0:ROIGE352: ROI GEORGE (23) with error: Error parsing message Error getting gtfs realtime data, for origin: 0:LITALDU1: HOTEL DE VILLE (10) with error: Error parsing message Error getting gtfs realtime data, for origin: 0:PARAIGE1: PARAIGES (18) with error: Error parsing message Error getting gtfs realtime data, for origin: 0:GARE30: GARE (20) with error: Error parsing message Error getting gtfs realtime data, for origin: 0:REPUBL88: REPUBLIQUE (22) with error: Error parsing message

Note : RT data works perfectly fine for a stop setup. The problem is only present with local stops.

vingerha commented 2 months ago

I need details, as per the request when you opened this ticket, no details = for sure no action Then, this is working for other people, myself included so are you sure to have provided the correct URL?

mxbssn commented 2 months ago

As I specified, the same link is used for a normal stop setup, and RT data is working on all of them. It is only a problem with the local stop option...

vingerha commented 2 months ago

WHAT link...do you think I can guess that from the log above?

mxbssn commented 2 months ago

Crikey... https://proxy.transport.data.gouv.fr/resource/lemet-metz-gtfs-rt-trip-update

I am sorry, I thought I copy-pasted the link in my first post.

vingerha commented 2 months ago

Will have a look later this week...thx

vingerha commented 2 months ago

And seems I 'lied' about it working, I updated my prod yesterday to 0.4.4. and ...yep...errors

vingerha commented 2 months ago

Can you please try 0.4.4.3 ? Cause of issue; with the cleaning of complexity I accidentally removed the vehicle location update and when puttting that back I did not think it through nor tested it.

mxbssn commented 2 months ago

I tried 0.4.4.3 and 0.4.4.2 and unfortunately the same errors come up...

`This error originated from a custom integration.

Logger: custom_components.gtfs2.coordinator Source: helpers/update_coordinator.py:315 integration: GTFS 2 (General Transit Feed Specification) (documentation, issues) First occurred: 12:41:23 (4 occurrences) Last logged: 12:43:21

Unexpected error fetching 492f35393e60f58f65118f35ff46aaad data: 'NoneType' object has no attribute 'startswith' Unexpected error fetching c88fc0c284432c1d012f0f6745513959 data: 'NoneType' object has no attribute 'startswith' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/coordinator.py", line 234, in _async_update_data self._data["local_stops_next_departures"] = await self.hass.async_add_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_helper.py", line 840, in get_local_stops_next_departures next_service = get_rt_route_trip_statuses(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_rt_helper.py", line 154, in get_rt_route_trip_statuses vehicle_positions = get_rt_vehicle_positions(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_rt_helper.py", line 232, in get_rt_vehicle_positions feed_entities = get_gtfs_feed_entities( ^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_rt_helper.py", line 66, in get_gtfs_feed_entities if url.startswith('file'): ^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'startswith' `

And

`Logger: homeassistant.components.sensor Source: helpers/entity_platform.py:356 integration: Sensor (documentation, issues) First occurred: 12:41:24 (5 occurrences) Last logged: 12:45:09

Error while setting up gtfs2 platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/coordinator.py", line 234, in _async_update_data self._data["local_stops_next_departures"] = await self.hass.async_add_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_helper.py", line 840, in get_local_stops_next_departures next_service = get_rt_route_trip_statuses(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_rt_helper.py", line 154, in get_rt_route_trip_statuses vehicle_positions = get_rt_vehicle_positions(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_rt_helper.py", line 232, in get_rt_vehicle_positions feed_entities = get_gtfs_feed_entities( ^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_rt_helper.py", line 66, in get_gtfs_feed_entities if url.startswith('file'): ^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'startswith'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/gtfs2/sensor.py", line 75, in async_setup_entry await coordinator.async_config_entry_first_refresh() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 287, in async_config_entry_first_refresh raise ex homeassistant.exceptions.ConfigEntryNotReady: 'NoneType' object has no attribute 'startswith' `

vingerha commented 2 months ago

Hi, I cannot reproduce...with me it works

image

image

vingerha commented 2 months ago

Did you restart HA after new version? And only (!) 0.443 will work

mxbssn commented 2 months ago

Okay, just looked into it a bit further, it works on 0.4.3, I had to create a new sensor. The old ones won't work even if I deactivate/reactivate the Realtime option, and thus even on 0.4.3

vingerha commented 2 months ago

You hopefully mean 0.4.4.3 ? And I am surprised that the old entries would continue to cause issues. The solution is a very simple code change and nothing in the configured entries. Only thing I can think of is that it stuck in memory...weird it is. Closing the ticket now

mxbssn commented 2 months ago

Oops, sorry, I was a bit too quick... It doesn't seem to work on my end even on 0.4.3 (or 0.4.4.3) It creates the sensors without Realtime fine, then when I activate the realtime option and add the link, if I refresh the location (to refresh the data), the sensors become unavailable...

I did not refresh the location in my previous test, and so the previously feteched data was showed and I dismissed it as working too quickly.

Logger: homeassistant.components.sensor Source: helpers/entity_platform.py:356 integration: Sensor (documentation, issues) First occurred: 13:52:20 (4 occurrences) Last logged: 14:00:01

Error while setting up gtfs2 platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/coordinator.py", line 234, in _async_update_data self._data["local_stops_next_departures"] = await self.hass.async_add_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_helper.py", line 846, in get_local_stops_next_departures next_service = get_rt_route_trip_statuses(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_rt_helper.py", line 154, in get_rt_route_trip_statuses vehicle_positions = get_rt_vehicle_positions(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_rt_helper.py", line 232, in get_rt_vehicle_positions feed_entities = get_gtfs_feed_entities( ^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/gtfs2/gtfs_rt_helper.py", line 66, in get_gtfs_feed_entities if url.startswith('file'): ^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'startswith'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/gtfs2/sensor.py", line 75, in async_setup_entry await coordinator.async_config_entry_first_refresh() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 287, in async_config_entry_first_refresh raise ex homeassistant.exceptions.ConfigEntryNotReady: 'NoneType' object has no attribute 'startswith'

vingerha commented 2 months ago

Hi, again, I cannot reproduce it as you see from my 'proof' above. So I can only assume that the version is not correctly downloaded...repeating that only 0.4.4.3 has the solution. You can verify the only change for this solution, being in the gtfs_rt_helper.py file On rows 155/6 it should show

    if self._vehicle_position_url:   
        vehicle_positions = get_rt_vehicle_positions(self)

Previously (and thus wrong) it showed

    if self._vehicle_position_url != "" :   
        vehicle_positions = get_rt_vehicle_positions(self)
mxbssn commented 2 months ago

Just amended the file manually, and I can confirm it works and the sensors now show RT information. Downgrading via HACS doesn't seem to work properly... Thx!

vingerha commented 2 months ago

Issues with multiple version changes and git are not fully unkown to me. Downgrading does work but I am not sure why sometimes I can not get the version I choose...multiple times trying, sticking with old ones