From 4f1f4a1b4ff056cc9595ce6f7fb801d2a7b35b00 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 10 Dec 2019 00:22:13 -0800 Subject: [PATCH] Nextbus: Sort results for upcoming times (#29811) Sort upcoming times across all direction's for a particular route and stop. --- homeassistant/components/nextbus/sensor.py | 4 +++- tests/components/nextbus/test_sensor.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/nextbus/sensor.py b/homeassistant/components/nextbus/sensor.py index 983c2272adc..5909804ebd1 100644 --- a/homeassistant/components/nextbus/sensor.py +++ b/homeassistant/components/nextbus/sensor.py @@ -225,7 +225,9 @@ class NextBusDepartureSensor(Entity): return # Generate list of upcoming times - self._attributes["upcoming"] = ", ".join(p["minutes"] for p in predictions) + self._attributes["upcoming"] = ", ".join( + sorted(p["minutes"] for p in predictions) + ) latest_prediction = maybe_first(predictions) self._state = utc_from_timestamp( diff --git a/tests/components/nextbus/test_sensor.py b/tests/components/nextbus/test_sensor.py index bc74ebcbe1e..bee9db445e2 100644 --- a/tests/components/nextbus/test_sensor.py +++ b/tests/components/nextbus/test_sensor.py @@ -206,7 +206,7 @@ async def test_direction_list( }, { "title": "Outbound 2", - "prediction": {"minutes": "4", "epochTime": "1553807374000"}, + "prediction": {"minutes": "0", "epochTime": "1553807374000"}, }, ], } @@ -221,7 +221,7 @@ async def test_direction_list( assert state.attributes["route"] == VALID_ROUTE_TITLE assert state.attributes["stop"] == VALID_STOP_TITLE assert state.attributes["direction"] == "Outbound, Outbound 2" - assert state.attributes["upcoming"] == "1, 2, 3, 4" + assert state.attributes["upcoming"] == "0, 1, 2, 3" async def test_custom_name(