From 5f8418a255d9384305e2fa7e08a11aa442e69921 Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Sun, 27 Sep 2020 20:41:05 +0200
Subject: show train class based on IRIS data

---
 lib/DBInfoscreen/Controller/Stationboard.pm | 40 ++++++++++++++---------------
 1 file changed, 20 insertions(+), 20 deletions(-)

(limited to 'lib')

diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm
index cba737c..aebd4b6 100644
--- a/lib/DBInfoscreen/Controller/Stationboard.pm
+++ b/lib/DBInfoscreen/Controller/Stationboard.pm
@@ -426,29 +426,16 @@ sub render_train {
 	];
 
 	my $linetype = 'bahn';
-	if ( $departure->{train_type} eq 'S' ) {
-		$linetype = 'sbahn';
-	}
-	elsif ($departure->{train_type} eq 'IC'
-		or $departure->{train_type} eq 'ICE'
-		or $departure->{train_type} eq 'EC'
-		or $departure->{train_type} eq 'ECE'
-		or $departure->{train_type} eq 'EN' )
-	{
-		$linetype = 'fern';
-	}
-	elsif ($departure->{train_type} eq 'THA'
-		or $departure->{train_type} eq 'TGV'
-		or $departure->{train_type} eq 'FLX'
-		or $departure->{train_type} eq 'NJ' )
-	{
+	my @classes  = $result->classes;
+	if ( @classes == 0 ) {
 		$linetype = 'ext';
 	}
-	elsif ( $departure->{train_line}
-		and $departure->{train_line} =~ m{^S\d} )
-	{
+	elsif ( grep { $_ eq 'S' } @classes ) {
 		$linetype = 'sbahn';
 	}
+	elsif ( grep { $_ eq 'F' } @classes ) {
+		$linetype = 'fern';
+	}
 
 	$self->render_later;
 
@@ -841,10 +828,22 @@ sub handle_result {
 			( $info, $moreinfo ) = $self->format_hafas_result_info($result);
 		}
 
-		my $time = $result->time;
+		my $time     = $result->time;
+		my $linetype = 'bahn';
 
 		if ( $backend eq 'iris' ) {
 
+			my @classes = $result->classes;
+			if ( @classes == 0 ) {
+				$linetype = 'ext';
+			}
+			elsif ( grep { $_ eq 'S' } @classes ) {
+				$linetype = 'sbahn';
+			}
+			elsif ( grep { $_ eq 'F' } @classes ) {
+				$linetype = 'fern';
+			}
+
 			# ->time defaults to dep, so we only need to overwrite $time
 			# if we want arrival times
 			if ( $admode eq 'arr' ) {
@@ -1068,6 +1067,7 @@ sub handle_result {
 					is_cancelled           => $result->is_cancelled,
 					departure_is_cancelled => $result->departure_is_cancelled,
 					arrival_is_cancelled   => $result->arrival_is_cancelled,
+					linetype               => $linetype,
 					messages               => {
 						delay => [
 							map { { timestamp => $_->[0], text => $_->[1] } }
-- 
cgit v1.2.3