Check early for empty passages in delijn (#59612)
* Add a check to verify if there is a passage Late in the evening and at night, there can be no passages anymore, so check it to avoid an unnecessary exception * One passage is enough! Requesting minimum 2 passages was an error due to counting from 1 and not zero * Invert check and put it out of the try-catch code Adding also the KeyError in the log message * Clean up * Putting comment in the correct python syntax * Clean up Co-authored-by: Martin Hjelmare <marhje52@gmail.com>pull/59667/head
parent
5860932635
commit
570f80a73c
homeassistant/components/delijn
|
@ -82,6 +82,10 @@ class DeLijnPublicTransportSensor(SensorEntity):
|
|||
|
||||
self._attributes["stopname"] = self._name
|
||||
|
||||
if not self.line.passages:
|
||||
self._available = False
|
||||
return
|
||||
|
||||
try:
|
||||
first = self.line.passages[0]
|
||||
if first["due_at_realtime"] is not None:
|
||||
|
@ -97,8 +101,8 @@ class DeLijnPublicTransportSensor(SensorEntity):
|
|||
self._attributes["is_realtime"] = first["is_realtime"]
|
||||
self._attributes["next_passages"] = self.line.passages
|
||||
self._available = True
|
||||
except (KeyError, IndexError):
|
||||
_LOGGER.error("Invalid data received from De Lijn")
|
||||
except (KeyError) as error:
|
||||
_LOGGER.error("Invalid data received from De Lijn: %s", error)
|
||||
self._available = False
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue