Fix delijn sensor stuck on last passage (#32710)

* Fix delijn sensor stuck on last passage

If the returned passage is an empty list that means there are
no next passages, so the sensor should be updated accordingly

* Mark the sensor as unavailable instead of emptying data

* use available property

* add available property
This commit is contained in:
Emilv2 2020-03-12 22:43:52 +01:00 committed by GitHub
parent a3dd9979d2
commit c968e455a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,6 +66,7 @@ class DeLijnPublicTransportSensor(Entity):
self._attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
self._name = name
self._state = None
self._available = False
async def async_update(self):
"""Get the latest data from the De Lijn API."""
@ -88,8 +89,15 @@ class DeLijnPublicTransportSensor(Entity):
self._attributes["due_at_schedule"] = first["due_at_schedule"]
self._attributes["due_at_realtime"] = first["due_at_realtime"]
self._attributes["next_passages"] = self.line.passages
self._available = True
except (KeyError, IndexError) as error:
_LOGGER.debug("Error getting data from De Lijn: %s", error)
self._available = False
@property
def available(self):
"""Return True if entity is available."""
return self._available
@property
def device_class(self):