From 658c48b2370cae2ecf429c25c7f66f97660d00e8 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Sat, 8 Feb 2020 14:52:05 +0000 Subject: [PATCH] Handle missing next train from NS (#31626) * Handle missing next train * Ignore next attribute instead --- .../components/nederlandse_spoorwegen/sensor.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/nederlandse_spoorwegen/sensor.py b/homeassistant/components/nederlandse_spoorwegen/sensor.py index 74b94421e3d..f4bb99399ea 100644 --- a/homeassistant/components/nederlandse_spoorwegen/sensor.py +++ b/homeassistant/components/nederlandse_spoorwegen/sensor.py @@ -191,10 +191,15 @@ class NSDepartureSensor(Entity): attributes["arrival_delay"] = True # Next attributes - if self._trips[1].departure_time_actual is not None: - attributes["next"] = self._trips[1].departure_time_actual.strftime("%H:%M") - elif self._trips[1].departure_time_planned is not None: - attributes["next"] = self._trips[1].departure_time_planned.strftime("%H:%M") + if len(self._trips) > 1: + if self._trips[1].departure_time_actual is not None: + attributes["next"] = self._trips[1].departure_time_actual.strftime( + "%H:%M" + ) + elif self._trips[1].departure_time_planned is not None: + attributes["next"] = self._trips[1].departure_time_planned.strftime( + "%H:%M" + ) return attributes @@ -223,7 +228,7 @@ class NSDepartureSensor(Entity): try: self._trips = self._nsapi.get_trips( - trip_time, self._departure, self._via, self._heading, True, 0, 2, + trip_time, self._departure, self._via, self._heading, True, 0, 2 ) if self._trips: if self._trips[0].departure_time_actual is None: