vingerha / gtfs2

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

Changed Service Call for RT Update with 0.4.6 - How to adapt to new Configuration? #80

Closed dafunkydan closed 1 month ago

dafunkydan commented 1 month ago

Describe the bug Updating RT Info by Service Call, when a API Key needs to be constructed and handed over, is broken for me in the latest Version (0.4.6).

Changelog says: Any service call, if used with api-key, has a higher risk of being broken, needs re-config. I don't know how i need to modify my prior working Service call. On < 0.4.6 i used:

service: gtfs2.update_gtfs_rt_local
data:
  url: https://gtfs-rt-sandbox-dds.rnv-online.de/tripupdates
  api_key_location: header
  accept: false
  debug_output: true
  file: GTFS-RT-RNV2-Temporary
  rt_type: trip_data
  api_key: Bearer {{ state_attr('sensor.rnv_gtfs_rt_api_key', 'access_token') }}

Which now gives me the Error: KeyError: 'api_key_name'

How does the Service Call need to get modified in order to work with the latest Version?

Release used

Additional

2024-05-25 08:52:09.743 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service
2024-05-25 08:52:09.758 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: name 'self' is not defined
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 501, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2786, in _execute_service
    return await self._hass.async_add_executor_job(target, service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  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/__init__.py", line 123, in update_gtfs_rt_local
    get_gtfs_rt(hass, DEFAULT_PATH_RT, call.data)
  File "/config/custom_components/gtfs2/gtfs_rt_helper.py", line 388, in get_gtfs_rt
    self._trip_update_url = self._trip_update_url + "?" + data[CONF_API_KEY_NAME] + "=" + data[CONF_API_KEY]
                            ^^^^
NameError: name 'self' is not defined
vingerha commented 1 month ago

Thanks, please try 4.6.1

dafunkydan commented 1 month ago

Thanks! Now running without Errors (when adding api_key_name: api_key) , but the RT-Files is 0 bytes. _converted.txt just shows: []

When switching back to 0.4.5.5 a valid File gets downloaded.

vingerha commented 1 month ago

where can I get the key?

vingerha commented 1 month ago

ah... and key name is 'Authorization'...try with that...

dafunkydan commented 1 month ago

key name is 'Authorization'

That did the Trick, Thanks! 😎 Hope i haven't overlooked it somewhere.

vingerha commented 1 month ago

Well... it is in the documentation :)

dafunkydan commented 1 month ago

Oh no... Deeply Sorry! 😢 Though, I still cant find it in this Documentation or in the Changelog. For my next future unnecessary Question, where would i need to check next time? Thanks for your, as always, lighning fast Support!

vingerha commented 1 month ago

grmbl..that is because the page was still in edit-mode ... quick and dirty is usually...dirty

https://github.com/vingerha/gtfs2/wiki/4.-Service-call#2-download-gtfs-realtime-data-to-reduce-multiple-downloads-from-the-same-source-for-different-trips

dafunkydan commented 1 month ago

quick and dirty is usually...dirty

True 😄 Thanks you so much!