vingerha / gtfs2

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

[FEATURE]: Add option to set Accept: application/x-protobuf header #49

Closed pcuser42 closed 2 months ago

pcuser42 commented 2 months ago

Describe the solution you'd like Auckland Transport's realtime API returns JSON data by default, but does return Protobuf if the Accept header is set to application/x-protobuf. Add an option to set this header if required by the data source.

Describe alternatives you've considered Looking at Auckland Transport's documentation, this header is the only way to get Protobuf data, and getting realtime data without it is not possible. I've tried adding a .pb extension to the URL in case this somehow worked, but just resulted in a 404.

Additional context Static GTFS data source: https://gtfs.at.govt.nz/gtfs.zip

Realtime API data requires an API key. The URLs I've been using (with the key in the header): https://api.at.govt.nz/realtime/legacy/tripupdates https://api.at.govt.nz/realtime/legacy/vehiclelocations https://api.at.govt.nz/realtime/legacy/servicealerts

vingerha commented 2 months ago

try 0.4.4.1, as I donot have local/static data I only tested with the service call and that collects the correct format

pcuser42 commented 2 months ago

Thanks @vingerha, turning the header option on and filling in the data at least gives me a different error now. This from the logs:

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: 7 April 2024 at 22:04:22 (42 occurrences)
Last logged: 10:02:48

Unexpected error fetching 81a9a115923e852b7c1c918b331ba5e2 data: 'mappingproxy' object has no attribute 'et'
Unexpected error fetching b19571e655f843f0232866f28bc3595a data: 'mappingproxy' object has no attribute 'et'
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 140, in _async_update_data
    if options.et(CONF_API_KEY,None):
       ^^^^^^^^^^
AttributeError: 'mappingproxy' object has no attribute 'et'

I'm not sure if this is related though.

vingerha commented 2 months ago

Too many things to work on and only limited testing ... typo fixed in 0.4.4.2

pcuser42 commented 2 months ago

Thanks @vingerha, no more errors and debug data suggests the API can now be contacted. 😄

I'm just getting a dash in the realtime attributes, but it's also possible that I've misconfigured something else, so will keep digging on this.

vingerha commented 2 months ago

Do try the service call so you can see the readable data too

On 8 Apr 2024, at 09:33, Alex Burgess @.***> wrote:



Thanks @vingerhahttps://github.com/vingerha, no more errors and debug data suggests the API can now be contacted. 😄

I'm just getting a dash in the realtime attributes, but it's also possible that I've misconfigured something else, so will keep digging on this.

— Reply to this email directly, view it on GitHubhttps://github.com/vingerha/gtfs2/issues/49#issuecomment-2042053634, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKREVY35DJDYNCQ5KNQA2GLY4JB3NAVCNFSM6AAAAABF27B3W6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBSGA2TGNRTGQ. You are receiving this because you were mentioned.Message ID: @.***>