From c968e455a951b0a070b430c9d69f25849c9a0468 Mon Sep 17 00:00:00 2001 From: Emilv2 Date: Thu, 12 Mar 2020 22:43:52 +0100 Subject: [PATCH] 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 --- homeassistant/components/delijn/sensor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/homeassistant/components/delijn/sensor.py b/homeassistant/components/delijn/sensor.py index 2cd238d0787..538e071e194 100644 --- a/homeassistant/components/delijn/sensor.py +++ b/homeassistant/components/delijn/sensor.py @@ -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):