forked from home-assistant/core
Add some safety checks for property access in NMBS sensor (#33695)
This commit is contained in:
committed by
GitHub
parent
34ecc803b3
commit
db2110f0c6
@@ -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:
|
||||
|
Reference in New Issue
Block a user