mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
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 <t.barbette@gmail.com> * Update homeassistant/components/nmbs/sensor.py canceled must be compared as an int, as suggested by @MartinHjelmare Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
576fc9dc64
commit
33784446f6
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user