From 26d01f9f1db944d319ebf66e9bcd4de52556cde6 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 28 Feb 2026 21:42:39 +0100 Subject: [PATCH] extract line, too. It is published for each direction to MQTT --- src/main.rs | 6 ++++++ src/straba.rs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/main.rs b/src/main.rs index 8aa779c..03b2307 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,12 +12,18 @@ async fn publish_departure_data(client: &AsyncClient, data: &straba::NextDepartu client .publish("departure/outbound/station", QoS::AtLeastOnce, false, data.outbound_station.as_bytes()) .await?; + client + .publish("departure/outbound/line", QoS::AtLeastOnce, false, data.outbound_line.as_bytes()) + .await?; client .publish("departure/outbound/diff", QoS::AtLeastOnce, false, format!("{}", data.outbound_diff).as_bytes()) .await?; client .publish("departure/inbound/station", QoS::AtLeastOnce, false, data.inbound_station.as_bytes()) .await?; + client + .publish("departure/inbound/line", QoS::AtLeastOnce, false, data.inbound_line.as_bytes()) + .await?; client .publish("departure/inbound/diff", QoS::AtLeastOnce, false, format!("{}", data.inbound_diff).as_bytes()) .await?; diff --git a/src/straba.rs b/src/straba.rs index 240a8f5..f895652 100644 --- a/src/straba.rs +++ b/src/straba.rs @@ -79,8 +79,10 @@ pub struct NextDeparture { pub request_time: i64, pub station_name: String, pub outbound_station: String, + pub outbound_line: String, pub outbound_diff: i64, pub inbound_station: String, + pub inbound_line: String, pub inbound_diff: i64, pub failure: bool, } @@ -149,8 +151,10 @@ pub fn fetch_data(station_id: u64, debug_print: Option) -> NextDeparture { let mut return_value = NextDeparture { failure: false, outbound_station: String::from(""), + outbound_line: String::from(""), outbound_diff: 10000, inbound_station: String::from(""), + inbound_line: String::from(""), inbound_diff: 10000, request_time: seconds as i64, station_name: String::from(""), @@ -204,6 +208,7 @@ pub fn fetch_data(station_id: u64, debug_print: Option) -> NextDeparture { if stop.destination_label.contains("Rheinau") { if diff < return_value.outbound_diff { return_value.outbound_station = stop.destination_label; + return_value.outbound_line = el.line.line_group.label.clone(); return_value.outbound_diff = diff; } } else if stop.destination_label.contains("Hochschule") @@ -212,17 +217,20 @@ pub fn fetch_data(station_id: u64, debug_print: Option) -> NextDeparture { { if diff < return_value.inbound_diff { return_value.inbound_station = stop.destination_label; + return_value.inbound_line = el.line.line_group.label.clone(); return_value.inbound_diff = diff; } } else if stop.destination_label.contains("Mannheim") { if diff < return_value.inbound_diff { return_value.inbound_station = stop.destination_label; + return_value.inbound_line = el.line.line_group.label.clone(); return_value.inbound_diff = diff; } } else { // Unkown stations are declared as outbound if diff < return_value.outbound_diff { return_value.outbound_station = stop.destination_label; + return_value.outbound_line = el.line.line_group.label.clone(); return_value.outbound_diff = diff; } }