New SL APIs
Worth mentioning that the trafiklab has this announcement, and they're sunsetting older APIs end 2024.03.30
https://www.trafiklab.se/api/trafiklab-apis/sl/
https://www.trafiklab.se/api/trafiklab-apis/sl/transport/
I don't mean to be rude and drop shadow on awesome work that @DSorlov did here, but I can't pass by without mentioning that I started working on the new SL API integration.
Here is the library that I made to expose both new APIs - Deviations and Transpoirt https://github.com/NecroKote/trafiklab-sl (#67 might be also related)
I plan to make a PR here in the coming weeks that's going to use it
Any assistance would be awesome as my time right now is very limited! <3
Good news all round. I'd prefer it to keep working after next Friday, so things need to happen here before then. 😅
... and here is the rewritten card that should be easier to develop and maintain in the future (only compatible with #71's content)
I have comitted to dev, making sure i can get it working and then will release
It still requires some work thou. But it's a start. My biggest cocern is lack of migrations from older schemas - people would have to reconfigure from scratch. And if so, we at least need to provide a cleanup during migration. Oh, and I haven't yet touched UI for Deviations (Trafik Status) With new API is't not clear to me how to present all this
Do we get a new release soon? :)
I am looking for new maintainers as my time simply is not sufficient to maintain this project any more. Please reach out to me.
@DSorlov I am interested in helping if you have the bandwith to get me up to speed
@DSorlov and @nemanjab17 I'm considering spending a bit of time on this as well. It's a fun little thing. One could also use or take inspiration from NetoKote/trafiklab-sl
Edit: Seems like @NecroKote has a good, working fork of this, ofc using his own library. Feeling a bit stupid.
@NecroKote, @nemanjab17 and @frli4797.. I see a brilliant future here.. are you up for adding you as maintainers? and also @NecroKote your code would be very welcome! <3
I would be happy to donate my code to the hasl org.
I have added you to all the required repos! Have fun! You are free to let it rip! =) <3
@NecroKote I hate to the guy bumping people, but I still wanted to ask you if you could get a PR going for merging your changes/improvements to this repo?
At this point, could I be added, I am already a maintainer for other home assistant addons.
I hate to the guy bumping people, but I still wanted to ask you if you could get a PR going for merging your changes/improvements to this repo?
"Soon" (tm)
But seriously, I'm trying to find time to dust off the changes, considering all the changes to HASS codebase. Not to mention, the new "deviations" do not have a card yet, and that is something I'd like to address before releasing.
Also, I expect rolling the changes out to be the trickiest part since my version is incompatible with the existing configuration or cards.
In the meantime, you can help by testing the fork (and the accompanying card) and providing feedback.
At this point, could I be added, I am already a maintainer for other home assistant addons.
We could use all the help we can get here 🙏
I'm currently happily running your fork, so a sample of one is under way. Curious to what the right strategy here is? To me there are two main themes:
- Merge the fork after some additional testing, thus sacrificing some features represented in the older versions, that won't be supported under the new version. (Which is not a huge thing as very little of the original add-on is currently working.)
- Develop the new card and sensor (fork) in parallel to the existing version.
My very humble opinion favors alternative one here, as this would be directionally correct. Not perfect, but HASL users would get to a working version, even though with less functionality and most likely with some issues initially.
@NecroKote are you willing to open up issues or discussions on your fork or do you want to keep the info located in this discussion?
After updating HomeAssistant today, and running your fork for about a week or so, all of the departure cards and integrations stopped working with a statement that the HASL3 integration was no longer providing the data. Unfortunately, I don't have logs of this.
My assumption here, is that it is due to either migration from HASL3 to your fork or some other reason, that I don't know.
So to try and resolve that:
- I have removed all of the previous HASL integrations, cleared out everything that I could with the existing configuration
- dropped in your fork
- Tried to reconfigure for my locations
- Now I receive errors and no entities or devices after configuring
As an example of what I am configuring it to look like
Then I received this error:
2024-12-15 12:43:38.892 ERROR (MainThread) [homeassistant.config_entries] Error unloading entry SL Pendeltag - Towards South for hasl3
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 855, in async_unload
result = await component.async_unload_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/hasl3/__init__.py", line 310, in async_unload_entry
hass.data[DOMAIN].pop(entry.entry_id)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: '01JEF9QD4A1DDAFRA830YXTRE2'
2024-12-15 12:43:47.658 ERROR (MainThread) [homeassistant.config_entries] Error unloading entry SL Traffic - Departures - Bus 134 for hasl3
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 855, in async_unload
result = await component.async_unload_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/hasl3/__init__.py", line 310, in async_unload_entry
hass.data[DOMAIN].pop(entry.entry_id)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: '01JEF2Y79EER3GP0M8JSXY4QQ8'
When attempting to add on a fresh installation, there are no devices or entities that appear after a complete wipe of everything.
2024-12-15 14:20:53.306 DEBUG (MainThread) [custom_components.hasl3.sensors] [async_update] Entered
2024-12-15 14:20:53.306 DEBUG (MainThread) [custom_components.hasl3.sensors] [async_update] Processing RR Departure Sensor 9531 (SL Pendeltag - Towards Central)
2024-12-15 14:20:53.306 DEBUG (MainThread) [custom_components.hasl3.worker] [check_sensor_state] Entered
2024-12-15 14:20:53.306 DEBUG (MainThread) [custom_components.hasl3.worker] [check_sensor_state] No sensor specified, will return default
2024-12-15 14:20:53.306 DEBUG (MainThread) [custom_components.hasl3.worker] [get_minutes_diff] diff 330.0, d1 2024-12-15 14:20:53, d2 2024-12-15 14:15:23
2024-12-15 14:20:53.306 DEBUG (MainThread) [custom_components.hasl3.worker] [process_rrd] Entered
2024-12-15 14:20:53.306 DEBUG (MainThread) [custom_components.hasl3.worker] [process_rrd] Processing key $APIKEY
2024-12-15 14:20:53.306 DEBUG (MainThread) [custom_components.hasl3.worker] [process_rrd] Processing stop 9531
2024-12-15 14:20:53.306 DEBUG (MainThread) [custom_components.hasl3.rrapi] Will call RRDB API
2024-12-15 14:20:53.430 ERROR (MainThread) [custom_components.hasl3.rrapi] RRAPI_API_Error API_AUTH: access denied for $APIKEY on departureBoard identified by stationBoard
2024-12-15 14:20:53.430 DEBUG (MainThread) [custom_components.hasl3.worker] [process_rrd] Error occurred during update 9531
2024-12-15 14:20:53.430 DEBUG (MainThread) [custom_components.hasl3.worker] [process_rrd] Completed stop 9531
2024-12-15 14:20:53.431 DEBUG (MainThread) [custom_components.hasl3.worker] [process_rrd] Completed key $APIKEY
2024-12-15 14:20:53.431 DEBUG (MainThread) [custom_components.hasl3.worker] [process_rrd] Completed
2024-12-15 14:20:53.431 DEBUG (MainThread) [custom_components.hasl3.sensors] [async_update] Update processed
2024-12-15 14:20:53.431 DEBUG (MainThread) [custom_components.hasl3.sensors] [async_update] Completed
2024-12-15 14:20:53.431 DEBUG (MainThread) [custom_components.hasl3.worker] [check_sensor_state] Entered
2024-12-15 14:20:53.431 DEBUG (MainThread) [custom_components.hasl3.worker] [check_sensor_state] No sensor specified, will return default
2024-12-15 14:21:12.877 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up hasl3 platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 366, in _async_setup_platform
await asyncio.shield(awaitable)
File "/config/custom_components/hasl3/sensor.py", line 76, in async_setup_entry
await coro(hass, entry, async_add_entities)
File "/config/custom_components/hasl3/sensors/departure.py", line 122, in async_setup_entry
coordinator = DepartureDataUpdateCoordinator(
hass, websession, key, interval, sensor_id
)
File "/config/custom_components/hasl3/sensors/departure.py", line 157, in __init__
self.client = TransportClient()
~~~~~~~~~~~~~~~^^
TypeError: AsyncClient.__init__() missing 1 required positional argument: 'session'
2024-12-15 14:21:23.306 DEBUG (MainThread) [custom_components.hasl3.sensors] [async_update] Entered
2024-12-15 14:21:23.306 DEBUG (MainThread) [custom_components.hasl3.sensors] [async_update] Processing RR Departure Sensor 9531 (SL Pendeltag - Towards Central)
2024-12-15 14:21:23.307 DEBUG (MainThread) [custom_components.hasl3.worker] [check_sensor_state] Entered
2024-12-15 14:21:23.307 DEBUG (MainThread) [custom_components.hasl3.worker] [check_sensor_state] No sensor specified, will return default
2024-12-15 14:21:23.307 DEBUG (MainThread) [custom_components.hasl3.worker] [get_minutes_diff] diff 30.0, d1 2024-12-15 14:21:23, d2 2024-12-15 14:20:53
2024-12-15 14:21:23.307 DEBUG (MainThread) [custom_components.hasl3.sensors] [async_update] Not due for update, skipping
2024-12-15 14:21:23.307 DEBUG (MainThread) [custom_components.hasl3.sensors] [async_update] Completed
2024-12-15 14:21:23.307 DEBUG (MainThread) [custom_components.hasl3.worker] [check_sensor_state] Entered
2024-12-15 14:21:23.307 DEBUG (MainThread) [custom_components.hasl3.worker] [check_sensor_state] No sensor specified, will return default
And a different error when using the logger component:
2024-12-15 15:18:30.025 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up hasl3 platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 366, in _async_setup_platform
await asyncio.shield(awaitable)
File "/config/custom_components/hasl3/sensor.py", line 76, in async_setup_entry
await coro(hass, entry, async_add_entities)
File "/config/custom_components/hasl3/sensors/departure.py", line 122, in async_setup_entry
coordinator = DepartureDataUpdateCoordinator(
hass, websession, key, interval, sensor_id
)
File "/config/custom_components/hasl3/sensors/departure.py", line 157, in __init__
self.client = TransportClient()
~~~~~~~~~~~~~~~^^
TypeError: AsyncClient.__init__() missing 1 required positional argument: 'session'
Seems like it is related to the API key, but, not sure if it is a client or API key related problem. Looking in to Trafiklab's site, my API key is still valid and hasn't hit any limitations on their site.
@delize, let's keep discussions in this repo.
The problem you are experiencing is due to breaking API changes in the underlying library trafiklab-sl (v1.0.0) and a very permissive dependency string in my fork (>=0.2.0). I'm sorry for the inconvenience. I'm trying to prepare a proper release. Here
In the meantime, you can manually install the new version from this repo's feature/new-sl-api branch.
I use HA through Docker, so my only understanding of how to do that would be via HACS.
It's all good, just took it as a surprise, and in the long run, it helps get rid of anyone else having this issue. :)
When trying this repo's branch, I can't due to the error that the integration is already available (due to it being in the HACS store by default).
If I add your's: https://github.com/NecroKote/HA-sl-integration/tree/feature/new-sl-api
I still see similar behavior of no entities/devices, and the same error in the log:
2024-12-15 16:04:03.187 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up hasl3 platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 366, in _async_setup_platform
await asyncio.shield(awaitable)
File "/config/custom_components/hasl3/sensor.py", line 76, in async_setup_entry
await coro(hass, entry, async_add_entities)
File "/config/custom_components/hasl3/sensors/departure.py", line 122, in async_setup_entry
coordinator = DepartureDataUpdateCoordinator(
hass, websession, key, interval, sensor_id
)
File "/config/custom_components/hasl3/sensors/departure.py", line 157, in __init__
self.client = TransportClient()
~~~~~~~~~~~~~~~^^
TypeError: AsyncClient.__init__() missing 1 required positional argument: 'session'
@delize you can't really use both this version and my fork at the same time, since they both provide same custom component - hasl3. And I'm not really sure if HACS allows installing different branches if there is already a release version system in place
Anyways, I've just packaged a new pre-release version v3.2.0b0 that anyone can install via HACS.
It WILL NOT pop-up as a regular upgrade since I marked it with pre-release, so you need to select this specific version when installing.
(For anyone feeling adventurous, you can even enable the "Pre-release" switch in HASS, allowing these pre-releases to be treated as regular updates)
@frli4797 if you can help with trying this one here I would greatly appreciate it 🙏
If it works - I can finally kill my fork and continue working on v3.2.0 in this repo
👍 All good, everything seems to be working again after installing the pre-release and reconfiguring my stops.
I'm a beginner using HA. Trying to setup HASL. Where can I find the API key that is needed? According to the information at Trafiklab the API key is no longer needed to use the SL API.
I'm a beginner using HA. Trying to setup HASL. Where can I find the API key that is needed? According to the information at Trafiklab the API key is no longer needed to use the SL API.
Hey @danwie, you don't need any keys to use the SL part of this integration. But if you want to have a stop search functionality, you would need a "SL Platsuppslag" key that you can get for free on Trafiklab
Hey @danwie, you don't need any keys to use the SL part of this integration. But if you want to have a stop search functionality, you would need a "SL Platsuppslag" key that you can get for free on Trafiklab
Thanks. But "SL Platsuppslag" is not available when selecting key.
Try using the very last key in the list - Trafikverket öppet API.
Disregard the advice above. It's strange, since new API explicitly says that no API key is required while still requiring a "key" during qury. I'll take a look at this
Never mind, the new "Trafikverket öppet API" is the correct key for stop lookup api.
Another, question. I've installed both cards using HACS. But they don't show in the list of cards when I try to add them to the dashboard. Do I need to manually write the YAML?
@danwie Can we please move this to another discussion ? This thread already became quite a mess and I would like to prevent it from getting even more out of hand.
@danwie Can we please move this to another discussion ? This thread already became quite a mess and I would like to prevent it from getting even more out of hand.
Sorry. And it was my fault - I found the problem. I didn't use the new card that you created.
Closing this one since new SL API are finally making it's way into pre-release version starting 3.2.0b0