Nederlandse_spoorwegen sensor: list index out of range

anyone else seeing this in the logs for the Nederlandse Spoorwegen sensor:

2020-02-07 17:53:23 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 284, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 328, in _async_write_ha_state
    attr.update(self.device_state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/nederlandse_spoorwegen/sensor.py", line 190, in device_state_attributes
    if self._trips[1].departure_time_actual is not None:
IndexError: list index out of range
2020-02-07 17:53:33 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 284, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 328, in _async_write_ha_state
    attr.update(self.device_state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/nederlandse_spoorwegen/sensor.py", line 190, in device_state_attributes
    if self._trips[1].departure_time_actual is not None:
IndexError: list index out of range

in multitudes…
my sensors are displaying fine in the frontend…

new setup, hassio 105.2

It looks like there were changes 4 days ago in the git logs

Also, I assume you’ve generated a new API key? “New Setup” kind of implies you did, but just checking.

Breaking Change:

The “RetrieveTripInformationPublic” API (“Public-Travel-Information” product) will be deprecated on 31-01-2020. All users MUST create a new API token for the “Reisinformatie” API (“Ns-App” product) and use that one instead.

You say the sensors are working, but I’m not sure how with this.

I’m not sure if the changes from 4 days ago were include in 0.105.2. You could try manually updating the component to the latest. Just create a custom_component/nederlandse_spoorwegen and do a git pull of the latest manually. After reboot, it will be using this latest one. Just be sure to remove it if the push the latest to HA so you get those future updates.

yes, I did.That wasn’t too obvious, but I finally found my way through the clutter on the NS website…

yes they are working:

Ive also filed an issue, and @YarmoM is working on it:

1 Like

In the mean time, set up your logger to ignore those errors.

logger:
  default: warning
  logs:
    #increasing this to above 'error' for now to ignore log spam
    homeassistant.components.nederlandse_spoorwegen: fatal

The recent changes did make it to 0.105! Together with the NSAPI maintainers (not made by NS), we are discovering inconsistencies in the new NS API, it seems that it’s causing multiple different bugs in the integration. I’ll do some more digging today, see what exactly needs fixing.

https://github.com/home-assistant/home-assistant/pull/31626 should have fixed this issue, will be available in 0.105.3. The circumstances are quite hard to replicate, so if the bug returns, just let me know :slight_smile:

unfortunately this doesn’t work at all…

multitudes of this (and others) keep popping up in the log:

2020-02-09 17:03:53 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.roosendaal_rotterdam fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 461, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 240, in wrapper
    result = method(*args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/nederlandse_spoorwegen/sensor.py", line 208, in update
    2,
  File "/usr/local/lib/python3.7/site-packages/ns_api.py", line 932, in get_trips
    return self.parse_trips(raw_trips, requested_time)
  File "/usr/local/lib/python3.7/site-packages/ns_api.py", line 843, in parse_trips
    newtrip = Trip(trip, requested_time)
  File "/usr/local/lib/python3.7/site-packages/ns_api.py", line 606, in __init__
    trip_part = TripSubpart(part)
  File "/usr/local/lib/python3.7/site-packages/ns_api.py", line 454, in __init__
    stop = TripStop(raw_stop)
  File "/usr/local/lib/python3.7/site-packages/ns_api.py", line 409, in __init__
    self.platform_changed = bool(self.actual_platform != self.planned_platform)
AttributeError: 'TripStop' object has no attribute 'planned_platform'

Hmm, yeah I can see that. The ERROR is for a root class (helpers.entity.py).

You could up your log level default above ‘error’, but that would be for everything!

But, @YarmoM says he has it fixed. If you want the fix now, update that component manually, or wait for 0.105.3.

Yeah, I’ll wait… hope Hue gets fixed soon too…

Thanks for logging this one, it’s new to me but all revolves around the same issue: single attributes randomly disappear from the API’s response… Don’t know who thought would be a great idea. I’ll mention it in the NSAPI library’s repo, see what we can do

1 Like