Add some safety checks for property access in NMBS sensor (#33695)
This commit is contained in:
parent
34ecc803b3
commit
db2110f0c6
1 changed files with 7 additions and 0 deletions
|
@ -152,6 +152,10 @@ class NMBSLiveBoard(Entity):
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Set the state equal to the next departure."""
|
"""Set the state equal to the next departure."""
|
||||||
liveboard = self._api_client.get_liveboard(self._station)
|
liveboard = self._api_client.get_liveboard(self._station)
|
||||||
|
|
||||||
|
if liveboard is None or not liveboard["departures"]:
|
||||||
|
return
|
||||||
|
|
||||||
next_departure = liveboard["departures"]["departure"][0]
|
next_departure = liveboard["departures"]["departure"][0]
|
||||||
|
|
||||||
self._attrs = next_departure
|
self._attrs = next_departure
|
||||||
|
@ -266,6 +270,9 @@ class NMBSSensor(Entity):
|
||||||
self._station_from, self._station_to
|
self._station_from, self._station_to
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if connections is None or not connections["connection"]:
|
||||||
|
return
|
||||||
|
|
||||||
if int(connections["connection"][0]["departure"]["left"]) > 0:
|
if int(connections["connection"][0]["departure"]["left"]) > 0:
|
||||||
next_connection = connections["connection"][1]
|
next_connection = connections["connection"][1]
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue