diff --git a/homeassistant/components/swiss_public_transport/coordinator.py b/homeassistant/components/swiss_public_transport/coordinator.py index 114215520acd3b47db1c592262663c5c7917fde0..f91f9a7c768328a41ad970cad1ebd133367c09b8 100644 --- a/homeassistant/components/swiss_public_transport/coordinator.py +++ b/homeassistant/components/swiss_public_transport/coordinator.py @@ -34,6 +34,7 @@ class DataConnection(TypedDict): train_number: str transfers: int delay: int + line: str def calculate_duration_in_seconds(duration_text: str) -> int | None: @@ -104,6 +105,7 @@ class SwissPublicTransportDataUpdateCoordinator( destination=self._opendata.to_name, remaining_time=str(self.remaining_time(connections[i]["departure"])), delay=connections[i]["delay"], + line=connections[i]["line"], ) for i in range(limit) if len(connections) > i and connections[i] is not None diff --git a/homeassistant/components/swiss_public_transport/icons.json b/homeassistant/components/swiss_public_transport/icons.json index 0f868c18c1fac4c9c1a175cb4b208d6502f8e628..06a640a06b270562860b370ab901da480e2269a7 100644 --- a/homeassistant/components/swiss_public_transport/icons.json +++ b/homeassistant/components/swiss_public_transport/icons.json @@ -21,6 +21,9 @@ }, "delay": { "default": "mdi:clock-plus" + }, + "line": { + "default": "mdi:transit-connection-variant" } } }, diff --git a/homeassistant/components/swiss_public_transport/sensor.py b/homeassistant/components/swiss_public_transport/sensor.py index c186b9637050752fed16c6dc1fcf2b0830465165..eb73ce030623fb4e0e10208bd864802edd0a121e 100644 --- a/homeassistant/components/swiss_public_transport/sensor.py +++ b/homeassistant/components/swiss_public_transport/sensor.py @@ -71,6 +71,11 @@ SENSORS: tuple[SwissPublicTransportSensorEntityDescription, ...] = ( native_unit_of_measurement=UnitOfTime.MINUTES, value_fn=lambda data_connection: data_connection["delay"], ), + SwissPublicTransportSensorEntityDescription( + key="line", + translation_key="line", + value_fn=lambda data_connection: data_connection["line"], + ), ) diff --git a/homeassistant/components/swiss_public_transport/strings.json b/homeassistant/components/swiss_public_transport/strings.json index 29e73978538db1a91d5353d0d94429145b10fb69..b3bfd9aea8ff02ee8fcb27f46395964c7b7f7788 100644 --- a/homeassistant/components/swiss_public_transport/strings.json +++ b/homeassistant/components/swiss_public_transport/strings.json @@ -46,6 +46,9 @@ }, "delay": { "name": "Delay" + }, + "line": { + "name": "Line" } } }, diff --git a/tests/components/swiss_public_transport/fixtures/connections.json b/tests/components/swiss_public_transport/fixtures/connections.json index 4edead56f1402caa629741786e170b1fb90195e6..f2cd1014e6326332701bed1144acddf70957ee89 100644 --- a/tests/components/swiss_public_transport/fixtures/connections.json +++ b/tests/components/swiss_public_transport/fixtures/connections.json @@ -5,7 +5,8 @@ "platform": 0, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:04:00+0100", @@ -13,7 +14,8 @@ "platform": 1, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": null }, { "departure": "2024-01-06T18:05:00+0100", @@ -21,7 +23,8 @@ "platform": 2, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:06:00+0100", @@ -29,7 +32,8 @@ "platform": 3, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:07:00+0100", @@ -37,7 +41,8 @@ "platform": 4, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:08:00+0100", @@ -45,7 +50,8 @@ "platform": 5, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:09:00+0100", @@ -53,7 +59,8 @@ "platform": 6, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:10:00+0100", @@ -61,7 +68,8 @@ "platform": 7, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:11:00+0100", @@ -69,7 +77,8 @@ "platform": 8, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:12:00+0100", @@ -77,7 +86,8 @@ "platform": 9, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:13:00+0100", @@ -85,7 +95,8 @@ "platform": 10, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:14:00+0100", @@ -93,7 +104,8 @@ "platform": 11, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:15:00+0100", @@ -101,7 +113,8 @@ "platform": 12, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:16:00+0100", @@ -109,7 +122,8 @@ "platform": 13, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:17:00+0100", @@ -117,7 +131,8 @@ "platform": 14, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" }, { "departure": "2024-01-06T18:18:00+0100", @@ -125,6 +140,7 @@ "platform": 15, "transfers": 0, "duration": "10", - "delay": 0 + "delay": 0, + "line": "T10" } ] diff --git a/tests/components/swiss_public_transport/test_init.py b/tests/components/swiss_public_transport/test_init.py index 7ee8b696499ea0a60db467a0aafd9b5ebe580f1c..9ad4a8d50b0833bcaa8958d14de8aa01adeec08d 100644 --- a/tests/components/swiss_public_transport/test_init.py +++ b/tests/components/swiss_public_transport/test_init.py @@ -36,6 +36,7 @@ CONNECTIONS = [ "transfers": 0, "duration": "10", "delay": 0, + "line": "T10", }, { "departure": "2024-01-06T18:04:00+0100", @@ -44,6 +45,7 @@ CONNECTIONS = [ "transfers": 0, "duration": "10", "delay": 0, + "line": "T10", }, { "departure": "2024-01-06T18:05:00+0100", @@ -52,6 +54,7 @@ CONNECTIONS = [ "transfers": 0, "duration": "10", "delay": 0, + "line": "T10", }, ]