Fix NMBS IndexError (#90365)

pull/90408/head
PatrickGlesner 2023-03-28 13:19:52 +02:00 committed by GitHub
parent de2ca31a71
commit f72bf73b03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -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]