From db2110f0c69c4977e029cda7b5a429b3ef455dc9 Mon Sep 17 00:00:00 2001 From: Thibault Maekelbergh <6213695+thibmaek@users.noreply.github.com> Date: Mon, 6 Apr 2020 21:15:29 +0200 Subject: [PATCH] Add some safety checks for property access in NMBS sensor (#33695) --- homeassistant/components/nmbs/sensor.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/homeassistant/components/nmbs/sensor.py b/homeassistant/components/nmbs/sensor.py index c6dd7b963ff..23b8bbea46b 100644 --- a/homeassistant/components/nmbs/sensor.py +++ b/homeassistant/components/nmbs/sensor.py @@ -152,6 +152,10 @@ class NMBSLiveBoard(Entity): def update(self): """Set the state equal to the next departure.""" liveboard = self._api_client.get_liveboard(self._station) + + if liveboard is None or not liveboard["departures"]: + return + next_departure = liveboard["departures"]["departure"][0] self._attrs = next_departure @@ -266,6 +270,9 @@ class NMBSSensor(Entity): self._station_from, self._station_to ) + if connections is None or not connections["connection"]: + return + if int(connections["connection"][0]["departure"]["left"]) > 0: next_connection = connections["connection"][1] else: