Add attributes departure_minutes and delay_minutes to the nmbs sensor (#30958)

* Improve sensor for automations

I've updated the sensor so that departure time and delay can be used in automatons.

Before, the departure time and delay time were only available wrapped in strings which makes it difficult to use them in automations. Using the extra attributes, one can easily use them in automations.

* Update homeassistant/components/nmbs/sensor.py

Co-Authored-By: springstan <46536646+springstan@users.noreply.github.com>

* Updates based on review

Changed min to minutes as requested

Co-authored-by: springstan <46536646+springstan@users.noreply.github.com>
This commit is contained in:
Ronald Dehuysser 2020-01-20 09:51:59 +01:00 committed by springstan
parent 9993333bf9
commit 053f18d6ce

View file

@ -130,6 +130,7 @@ class NMBSLiveBoard(Entity):
attrs = {
"departure": f"In {departure} minutes",
"departure_minutes": departure,
"extra_train": int(self._attrs["isExtra"]) > 0,
"vehicle_id": self._attrs["vehicle"],
"monitored_station": self._station,
@ -138,6 +139,7 @@ class NMBSLiveBoard(Entity):
if delay > 0:
attrs["delay"] = f"{delay} minutes"
attrs["delay_minutes"] = delay
return attrs
@ -200,6 +202,7 @@ class NMBSSensor(Entity):
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"],
@ -224,6 +227,7 @@ class NMBSSensor(Entity):
if delay > 0:
attrs["delay"] = f"{delay} minutes"
attrs["delay_minutes"] = delay
return attrs