mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 01:21:51 +02:00
Small nmbs sensor attributes refactoring (#145956)
Attributes refactoring
This commit is contained in:
@ -247,7 +247,6 @@ class NMBSSensor(SensorEntity):
|
|||||||
|
|
||||||
delay = get_delay_in_minutes(self._attrs.departure.delay)
|
delay = get_delay_in_minutes(self._attrs.departure.delay)
|
||||||
departure = get_time_until(self._attrs.departure.time)
|
departure = get_time_until(self._attrs.departure.time)
|
||||||
canceled = self._attrs.departure.canceled
|
|
||||||
|
|
||||||
attrs = {
|
attrs = {
|
||||||
"destination": self._attrs.departure.station,
|
"destination": self._attrs.departure.station,
|
||||||
@ -257,14 +256,13 @@ class NMBSSensor(SensorEntity):
|
|||||||
"vehicle_id": self._attrs.departure.vehicle,
|
"vehicle_id": self._attrs.departure.vehicle,
|
||||||
}
|
}
|
||||||
|
|
||||||
if not canceled:
|
attrs["canceled"] = self._attrs.departure.canceled
|
||||||
attrs["departure"] = f"In {departure} minutes"
|
if attrs["canceled"]:
|
||||||
attrs["departure_minutes"] = departure
|
|
||||||
attrs["canceled"] = False
|
|
||||||
else:
|
|
||||||
attrs["departure"] = None
|
attrs["departure"] = None
|
||||||
attrs["departure_minutes"] = None
|
attrs["departure_minutes"] = None
|
||||||
attrs["canceled"] = True
|
else:
|
||||||
|
attrs["departure"] = f"In {departure} minutes"
|
||||||
|
attrs["departure_minutes"] = departure
|
||||||
|
|
||||||
if self._show_on_map and self.station_coordinates:
|
if self._show_on_map and self.station_coordinates:
|
||||||
attrs[ATTR_LATITUDE] = self.station_coordinates[0]
|
attrs[ATTR_LATITUDE] = self.station_coordinates[0]
|
||||||
@ -280,9 +278,8 @@ class NMBSSensor(SensorEntity):
|
|||||||
via.timebetween
|
via.timebetween
|
||||||
) + get_delay_in_minutes(via.departure.delay)
|
) + get_delay_in_minutes(via.departure.delay)
|
||||||
|
|
||||||
if delay > 0:
|
attrs["delay"] = f"{delay} minutes"
|
||||||
attrs["delay"] = f"{delay} minutes"
|
attrs["delay_minutes"] = delay
|
||||||
attrs["delay_minutes"] = delay
|
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user