Add some safety checks for property access in NMBS sensor (#33695)

This commit is contained in:
Thibault Maekelbergh 2020-04-06 21:15:29 +02:00 committed by GitHub
parent 34ecc803b3
commit db2110f0c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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