extract line, too. It is published for each direction to MQTT

This commit is contained in:
Ollo
2026-02-28 21:42:39 +01:00
parent 4cad8e7202
commit 26d01f9f1d
2 changed files with 14 additions and 0 deletions

View File

@@ -12,12 +12,18 @@ async fn publish_departure_data(client: &AsyncClient, data: &straba::NextDepartu
client client
.publish("departure/outbound/station", QoS::AtLeastOnce, false, data.outbound_station.as_bytes()) .publish("departure/outbound/station", QoS::AtLeastOnce, false, data.outbound_station.as_bytes())
.await?; .await?;
client
.publish("departure/outbound/line", QoS::AtLeastOnce, false, data.outbound_line.as_bytes())
.await?;
client client
.publish("departure/outbound/diff", QoS::AtLeastOnce, false, format!("{}", data.outbound_diff).as_bytes()) .publish("departure/outbound/diff", QoS::AtLeastOnce, false, format!("{}", data.outbound_diff).as_bytes())
.await?; .await?;
client client
.publish("departure/inbound/station", QoS::AtLeastOnce, false, data.inbound_station.as_bytes()) .publish("departure/inbound/station", QoS::AtLeastOnce, false, data.inbound_station.as_bytes())
.await?; .await?;
client
.publish("departure/inbound/line", QoS::AtLeastOnce, false, data.inbound_line.as_bytes())
.await?;
client client
.publish("departure/inbound/diff", QoS::AtLeastOnce, false, format!("{}", data.inbound_diff).as_bytes()) .publish("departure/inbound/diff", QoS::AtLeastOnce, false, format!("{}", data.inbound_diff).as_bytes())
.await?; .await?;

View File

@@ -79,8 +79,10 @@ pub struct NextDeparture {
pub request_time: i64, pub request_time: i64,
pub station_name: String, pub station_name: String,
pub outbound_station: String, pub outbound_station: String,
pub outbound_line: String,
pub outbound_diff: i64, pub outbound_diff: i64,
pub inbound_station: String, pub inbound_station: String,
pub inbound_line: String,
pub inbound_diff: i64, pub inbound_diff: i64,
pub failure: bool, pub failure: bool,
} }
@@ -149,8 +151,10 @@ pub fn fetch_data(station_id: u64, debug_print: Option<bool>) -> NextDeparture {
let mut return_value = NextDeparture { let mut return_value = NextDeparture {
failure: false, failure: false,
outbound_station: String::from(""), outbound_station: String::from(""),
outbound_line: String::from(""),
outbound_diff: 10000, outbound_diff: 10000,
inbound_station: String::from(""), inbound_station: String::from(""),
inbound_line: String::from(""),
inbound_diff: 10000, inbound_diff: 10000,
request_time: seconds as i64, request_time: seconds as i64,
station_name: String::from(""), station_name: String::from(""),
@@ -204,6 +208,7 @@ pub fn fetch_data(station_id: u64, debug_print: Option<bool>) -> NextDeparture {
if stop.destination_label.contains("Rheinau") { if stop.destination_label.contains("Rheinau") {
if diff < return_value.outbound_diff { if diff < return_value.outbound_diff {
return_value.outbound_station = stop.destination_label; return_value.outbound_station = stop.destination_label;
return_value.outbound_line = el.line.line_group.label.clone();
return_value.outbound_diff = diff; return_value.outbound_diff = diff;
} }
} else if stop.destination_label.contains("Hochschule") } else if stop.destination_label.contains("Hochschule")
@@ -212,17 +217,20 @@ pub fn fetch_data(station_id: u64, debug_print: Option<bool>) -> NextDeparture {
{ {
if diff < return_value.inbound_diff { if diff < return_value.inbound_diff {
return_value.inbound_station = stop.destination_label; return_value.inbound_station = stop.destination_label;
return_value.inbound_line = el.line.line_group.label.clone();
return_value.inbound_diff = diff; return_value.inbound_diff = diff;
} }
} else if stop.destination_label.contains("Mannheim") { } else if stop.destination_label.contains("Mannheim") {
if diff < return_value.inbound_diff { if diff < return_value.inbound_diff {
return_value.inbound_station = stop.destination_label; return_value.inbound_station = stop.destination_label;
return_value.inbound_line = el.line.line_group.label.clone();
return_value.inbound_diff = diff; return_value.inbound_diff = diff;
} }
} else { } else {
// Unkown stations are declared as outbound // Unkown stations are declared as outbound
if diff < return_value.outbound_diff { if diff < return_value.outbound_diff {
return_value.outbound_station = stop.destination_label; return_value.outbound_station = stop.destination_label;
return_value.outbound_line = el.line.line_group.label.clone();
return_value.outbound_diff = diff; return_value.outbound_diff = diff;
} }
} }