From 2caa81f38c30d70ac4fe7b5cd2282afb45742866 Mon Sep 17 00:00:00 2001 From: loredo Date: Thu, 3 Nov 2016 23:28:36 +0000 Subject: [PATCH] UConv.pm: fallback for undefined unit git-svn-id: https://svn.fhem.de/fhem/trunk@12497 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/UConv.pm | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/fhem/FHEM/UConv.pm b/fhem/FHEM/UConv.pm index 5c38406d8..3de2be755 100644 --- a/fhem/FHEM/UConv.pm +++ b/fhem/FHEM/UConv.pm @@ -132,8 +132,8 @@ my %units = ( # percent "pct" => { - "unit_symbol" => "%", - "unit_long" => { + "unit" => "%", + "unit_long" => { "de" => "Prozent", "en" => "percent", "fr" => "percent", @@ -1062,6 +1062,8 @@ sub UnitDetails ($;$) { my $l = ( $lang ? lc($lang) : "en" ); my %details; + return {} if ( !$unit || $unit eq "" ); + if ( defined( $units{$u} ) ) { foreach my $k ( keys %{ $units{$u} } ) { $details{$k} = $units{$u}{$k}; @@ -1640,15 +1642,22 @@ sub rname2unitDetails ($;$$) { my $dr = $weather_readings{$r}{"unified"}; $return{"unified"} = $dr; $return{"short"} = $weather_readings{$dr}{"short"}; - $u = $weather_readings{$dr}{"unit"} - if ( $weather_readings{$dr}{"unit"} ); + $u = ( + $weather_readings{$dr}{"unit"} + ? $weather_readings{$dr}{"unit"} + : "-" + ); } # known standard reading names elsif ( $weather_readings{$r}{"short"} ) { $return{"unified"} = $r; $return{"short"} = $weather_readings{$r}{"short"}; - $u = $weather_readings{$r}{"unit"} if ( $weather_readings{$r}{"unit"} ); + $u = ( + $weather_readings{$r}{"unit"} + ? $weather_readings{$r}{"unit"} + : "-" + ); } # just guessing the unit from reading name @@ -1684,6 +1693,11 @@ sub rname2unitDetails ($;$$) { $return{"value_unit"} = $txt; } + # fallback + else { + $return{"value_unit"} = $value; + } + # plural if ( Scalar::Util::looks_like_number($value) && $value > 1 @@ -1711,6 +1725,11 @@ sub rname2unitDetails ($;$$) { $return{"value_unit_long"} = $txt; } + + # fallback + else { + $return{"value_unit_long"} = $value; + } } return \%return;