mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-19 12:46:03 +00:00
UConv.pm: fallback for undefined unit
git-svn-id: https://svn.fhem.de/fhem/trunk@12497 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
f4b237ebf1
commit
50887e4845
@ -132,8 +132,8 @@ my %units = (
|
|||||||
|
|
||||||
# percent
|
# percent
|
||||||
"pct" => {
|
"pct" => {
|
||||||
"unit_symbol" => "%",
|
"unit" => "%",
|
||||||
"unit_long" => {
|
"unit_long" => {
|
||||||
"de" => "Prozent",
|
"de" => "Prozent",
|
||||||
"en" => "percent",
|
"en" => "percent",
|
||||||
"fr" => "percent",
|
"fr" => "percent",
|
||||||
@ -1062,6 +1062,8 @@ sub UnitDetails ($;$) {
|
|||||||
my $l = ( $lang ? lc($lang) : "en" );
|
my $l = ( $lang ? lc($lang) : "en" );
|
||||||
my %details;
|
my %details;
|
||||||
|
|
||||||
|
return {} if ( !$unit || $unit eq "" );
|
||||||
|
|
||||||
if ( defined( $units{$u} ) ) {
|
if ( defined( $units{$u} ) ) {
|
||||||
foreach my $k ( keys %{ $units{$u} } ) {
|
foreach my $k ( keys %{ $units{$u} } ) {
|
||||||
$details{$k} = $units{$u}{$k};
|
$details{$k} = $units{$u}{$k};
|
||||||
@ -1640,15 +1642,22 @@ sub rname2unitDetails ($;$$) {
|
|||||||
my $dr = $weather_readings{$r}{"unified"};
|
my $dr = $weather_readings{$r}{"unified"};
|
||||||
$return{"unified"} = $dr;
|
$return{"unified"} = $dr;
|
||||||
$return{"short"} = $weather_readings{$dr}{"short"};
|
$return{"short"} = $weather_readings{$dr}{"short"};
|
||||||
$u = $weather_readings{$dr}{"unit"}
|
$u = (
|
||||||
if ( $weather_readings{$dr}{"unit"} );
|
$weather_readings{$dr}{"unit"}
|
||||||
|
? $weather_readings{$dr}{"unit"}
|
||||||
|
: "-"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
# known standard reading names
|
# known standard reading names
|
||||||
elsif ( $weather_readings{$r}{"short"} ) {
|
elsif ( $weather_readings{$r}{"short"} ) {
|
||||||
$return{"unified"} = $r;
|
$return{"unified"} = $r;
|
||||||
$return{"short"} = $weather_readings{$r}{"short"};
|
$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
|
# just guessing the unit from reading name
|
||||||
@ -1684,6 +1693,11 @@ sub rname2unitDetails ($;$$) {
|
|||||||
$return{"value_unit"} = $txt;
|
$return{"value_unit"} = $txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# fallback
|
||||||
|
else {
|
||||||
|
$return{"value_unit"} = $value;
|
||||||
|
}
|
||||||
|
|
||||||
# plural
|
# plural
|
||||||
if ( Scalar::Util::looks_like_number($value)
|
if ( Scalar::Util::looks_like_number($value)
|
||||||
&& $value > 1
|
&& $value > 1
|
||||||
@ -1711,6 +1725,11 @@ sub rname2unitDetails ($;$$) {
|
|||||||
|
|
||||||
$return{"value_unit_long"} = $txt;
|
$return{"value_unit_long"} = $txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# fallback
|
||||||
|
else {
|
||||||
|
$return{"value_unit_long"} = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return \%return;
|
return \%return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user