From f72bf73b0338a3da4ba9dfe9e9fa185a676fc8a3 Mon Sep 17 00:00:00 2001
From: PatrickGlesner <34370149+PatrickGlesner@users.noreply.github.com>
Date: Tue, 28 Mar 2023 13:19:52 +0200
Subject: [PATCH] Fix NMBS IndexError (#90365)

---
 homeassistant/components/nmbs/sensor.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/homeassistant/components/nmbs/sensor.py b/homeassistant/components/nmbs/sensor.py
index b9a216875f4..8fb227140a1 100644
--- a/homeassistant/components/nmbs/sensor.py
+++ b/homeassistant/components/nmbs/sensor.py
@@ -162,7 +162,13 @@ class NMBSLiveBoard(SensorEntity):
         """Set the state equal to the next departure."""
         liveboard = self._api_client.get_liveboard(self._station)
 
-        if liveboard is None or not liveboard.get("departures"):
+        if (
+            liveboard is None
+            or liveboard.get("departures") is None
+            or liveboard.get("departures").get("number") is None
+            or liveboard.get("departures").get("number") == "0"
+            or liveboard.get("departures").get("departure") is None
+        ):
             return
 
         next_departure = liveboard["departures"]["departure"][0]
-- 
GitLab