mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
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>
This commit is contained in:
parent
5860932635
commit
570f80a73c
@ -82,6 +82,10 @@ class DeLijnPublicTransportSensor(SensorEntity):
|
|||||||
|
|
||||||
self._attributes["stopname"] = self._name
|
self._attributes["stopname"] = self._name
|
||||||
|
|
||||||
|
if not self.line.passages:
|
||||||
|
self._available = False
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
first = self.line.passages[0]
|
first = self.line.passages[0]
|
||||||
if first["due_at_realtime"] is not None:
|
if first["due_at_realtime"] is not None:
|
||||||
@ -97,8 +101,8 @@ class DeLijnPublicTransportSensor(SensorEntity):
|
|||||||
self._attributes["is_realtime"] = first["is_realtime"]
|
self._attributes["is_realtime"] = first["is_realtime"]
|
||||||
self._attributes["next_passages"] = self.line.passages
|
self._attributes["next_passages"] = self.line.passages
|
||||||
self._available = True
|
self._available = True
|
||||||
except (KeyError, IndexError):
|
except (KeyError) as error:
|
||||||
_LOGGER.error("Invalid data received from De Lijn")
|
_LOGGER.error("Invalid data received from De Lijn: %s", error)
|
||||||
self._available = False
|
self._available = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user