From 33784446f63b7396c88601f48b2f11685d63f13b Mon Sep 17 00:00:00 2001 From: Tom Barbette Date: Thu, 26 May 2022 18:04:22 +0200 Subject: [PATCH] Add nmbs canceled attribute (#57113) * nmbs: Add canceled attribute If a train is canceled, change the state to canceled and also add an attribute that can be matched. Personnaly I look for the attribute and add a "line-through" CSS style to show my train was canceled. I discovered this was not displayed the hard way :) Signed-off-by: Tom Barbette * Update homeassistant/components/nmbs/sensor.py canceled must be compared as an int, as suggested by @MartinHjelmare Co-authored-by: Martin Hjelmare Co-authored-by: Martin Hjelmare --- homeassistant/components/nmbs/sensor.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/nmbs/sensor.py b/homeassistant/components/nmbs/sensor.py index 00624748aba..fdb03652756 100644 --- a/homeassistant/components/nmbs/sensor.py +++ b/homeassistant/components/nmbs/sensor.py @@ -215,10 +215,9 @@ class NMBSSensor(SensorEntity): delay = get_delay_in_minutes(self._attrs["departure"]["delay"]) departure = get_time_until(self._attrs["departure"]["time"]) + canceled = int(self._attrs["departure"]["canceled"]) attrs = { - "departure": f"In {departure} minutes", - "departure_minutes": departure, "destination": self._station_to, "direction": self._attrs["departure"]["direction"]["name"], "platform_arriving": self._attrs["arrival"]["platform"], @@ -227,6 +226,15 @@ class NMBSSensor(SensorEntity): ATTR_ATTRIBUTION: "https://api.irail.be/", } + if canceled != 1: + attrs["departure"] = f"In {departure} minutes" + attrs["departure_minutes"] = departure + attrs["canceled"] = False + else: + attrs["departure"] = None + attrs["departure_minutes"] = None + attrs["canceled"] = True + if self._show_on_map and self.station_coordinates: attrs[ATTR_LATITUDE] = self.station_coordinates[0] attrs[ATTR_LONGITUDE] = self.station_coordinates[1]