mirror of
https://github.com/home-assistant/core.git
synced 2025-06-24 17:11:53 +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)
|
||||
departure = get_time_until(self._attrs.departure.time)
|
||||
canceled = self._attrs.departure.canceled
|
||||
|
||||
attrs = {
|
||||
"destination": self._attrs.departure.station,
|
||||
@ -257,14 +256,13 @@ class NMBSSensor(SensorEntity):
|
||||
"vehicle_id": self._attrs.departure.vehicle,
|
||||
}
|
||||
|
||||
if not canceled:
|
||||
attrs["departure"] = f"In {departure} minutes"
|
||||
attrs["departure_minutes"] = departure
|
||||
attrs["canceled"] = False
|
||||
else:
|
||||
attrs["canceled"] = self._attrs.departure.canceled
|
||||
if attrs["canceled"]:
|
||||
attrs["departure"] = 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:
|
||||
attrs[ATTR_LATITUDE] = self.station_coordinates[0]
|
||||
@ -280,9 +278,8 @@ class NMBSSensor(SensorEntity):
|
||||
via.timebetween
|
||||
) + get_delay_in_minutes(via.departure.delay)
|
||||
|
||||
if delay > 0:
|
||||
attrs["delay"] = f"{delay} minutes"
|
||||
attrs["delay_minutes"] = delay
|
||||
attrs["delay"] = f"{delay} minutes"
|
||||
attrs["delay_minutes"] = delay
|
||||
|
||||
return attrs
|
||||
|
||||
|
Reference in New Issue
Block a user