2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-21 20:06:18 +00:00

UConv.pm: improved reading name detection

git-svn-id: https://svn.fhem.de/fhem/trunk@12502 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2016-11-04 14:51:37 +00:00
parent 67e8f401db
commit 36cf89afc2

View File

@ -1073,68 +1073,48 @@ sub UnitDetails ($;$) {
if ($lang) { if ($lang) {
$details{"lang"} = $l; $details{"lang"} = $l;
if ( $details{"txt_format"} ) { if ( $details{"txt_format"}
&& ref( $units{$u}{"txt_format"} ) eq "HASH"
&& $units{$u}{"txt_format"}{$l} )
{
delete $details{"txt_format"}; delete $details{"txt_format"};
if ( ref( $units{$u}{"txt_format"} ) eq "HASH" $details{"txt_format"} = $units{$u}{"txt_format"}{$l};
&& $units{$u}{"txt_format"}{$l} )
{
$details{"txt_format"} = $units{$u}{"txt_format"}{$l};
}
elsif ( ref( $units{$u}{"txt_format"} ) ne "HASH" ) {
$details{"txt_format"} = $units{$u}{"txt_format"};
}
} }
if ( $details{"txt_format_long"} ) { if ( $details{"txt_format_long"}
&& ref( $units{$u}{"txt_format_long"} ) eq "HASH"
&& $units{$u}{"txt_format_long"}{$l} )
{
delete $details{"txt_format_long"}; delete $details{"txt_format_long"};
if ( ref( $units{$u}{"txt_format_long"} ) eq "HASH" $details{"txt_format_long"} =
&& $units{$u}{"txt_format_long"}{$l} ) $units{$u}{"txt_format_long"}{$l};
{
$details{"txt_format_long"} =
$units{$u}{"txt_format_long"}{$l};
}
elsif ( ref( $units{$u}{"txt_format_long"} ) ne "HASH" ) {
$details{"txt_format_long"} = $units{$u}{"txt_format_long"};
}
} }
if ( $details{"txt_format_long_pl"} ) { if ( $details{"txt_format_long_pl"}
&& ref( $units{$u}{"txt_format_long_pl"} ) eq "HASH"
&& $units{$u}{"txt_format_long_pl"}{$l} )
{
delete $details{"txt_format_long_pl"}; delete $details{"txt_format_long_pl"};
if ( ref( $units{$u}{"txt_format_long_pl"} ) eq "HASH" $details{"txt_format_long_pl"} =
&& $units{$u}{"txt_format_long_pl"}{$l} ) $units{$u}{"txt_format_long_pl"}{$l};
{
$details{"txt_format_long_pl"} =
$units{$u}{"txt_format_long_pl"}{$l};
}
elsif ( ref( $units{$u}{"txt_format_long_pl"} ) ne "HASH" ) {
$details{"txt_format_long_pl"} =
$units{$u}{"txt_format_long_pl"};
}
} }
if ( $details{"unit_long"} ) { if ( $details{"unit_long"}
&& ref( $units{$u}{"unit_long"} ) eq "HASH"
&& $units{$u}{"unit_long"}{$l} )
{
delete $details{"unit_long"}; delete $details{"unit_long"};
if ( ref( $units{$u}{"unit_long"} ) eq "HASH" $details{"unit_long"} = $units{$u}{"unit_long"}{$l};
&& $units{$u}{"unit_long"}{$l} )
{
$details{"unit_long"} = $units{$u}{"unit_long"}{$l};
}
elsif ( ref( $units{$u}{"unit_long"} ) ne "HASH" ) {
$details{"unit_long"} = $units{$u}{"unit_long"};
}
} }
if ( $details{"unit_long_pl"} ) { if ( $details{"unit_long_pl"}
&& ref( $units{$u}{"unit_long_pl"} ) eq "HASH"
&& $units{$u}{"unit_long_pl"}{$l} )
{
delete $details{"unit_long_pl"}; delete $details{"unit_long_pl"};
if ( ref( $units{$u}{"unit_long_pl"} ) eq "HASH" $details{"unit_long_pl"} = $units{$u}{"unit_long_pl"}{$l};
&& $units{$u}{"unit_long_pl"}{$l} )
{
$details{"unit_long_pl"} = $units{$u}{"unit_long_pl"}{$l};
}
elsif ( ref( $units{$u}{"unit_long_pl"} ) ne "HASH" ) {
$details{"unit_long_pl"} = $units{$u}{"unit_long_pl"};
}
} }
} }
return \%details; return \%details;
@ -1632,11 +1612,26 @@ sub rname2rsname($) {
sub rname2unitDetails ($;$$) { sub rname2unitDetails ($;$$) {
my ( $reading, $lang, $value ) = @_; my ( $reading, $lang, $value ) = @_;
my $details; my $details;
my $r = lc($reading); my $r = $reading;
my $l = ( $lang ? lc($lang) : "en" ); my $l = ( $lang ? lc($lang) : "en" );
my $u; my $u;
my %return; my %return;
# remove some prefix or other values to
# flatten reading name
$r =~ s/^fc\d+_//;
$r =~ s/_(min|max|avg|sum|avg\d+m|sum\d+m)_/_/;
$r =~ s/_(min|max|avg|sum|avg\d+m|sum\d+m)$//;
$r =~ s/.*[-_](temp)$/$1/;
# rename capital letter containing readings
if ( !$weather_readings{ lc($r) } ) {
$r =~ s/^([A-Z])(.*)/\l$1$2/;
$r =~ s/([A-Z][a-z0-9]*)[\/\|\-_]?/_$1/g;
}
$r = lc($r);
# known alias reading names # known alias reading names
if ( $weather_readings{$r}{"unified"} ) { if ( $weather_readings{$r}{"unified"} ) {
my $dr = $weather_readings{$r}{"unified"}; my $dr = $weather_readings{$r}{"unified"};
@ -1651,7 +1646,7 @@ sub rname2unitDetails ($;$$) {
# known standard reading names # known standard reading names
elsif ( $weather_readings{$r}{"short"} ) { elsif ( $weather_readings{$r}{"short"} ) {
$return{"unified"} = $r; $return{"unified"} = $reading;
$return{"short"} = $weather_readings{$r}{"short"}; $return{"short"} = $weather_readings{$r}{"short"};
$u = ( $u = (
$weather_readings{$r}{"unit"} $weather_readings{$r}{"unit"}
@ -1662,7 +1657,7 @@ sub rname2unitDetails ($;$$) {
# just guessing the unit from reading name # just guessing the unit from reading name
elsif ( $r =~ /_([a-z]+)$/ ) { elsif ( $r =~ /_([a-z]+)$/ ) {
$u = $1; $u = lc($1);
$return{"value"} = $value if ( defined($value) ); $return{"value"} = $value if ( defined($value) );
} }
@ -1671,6 +1666,8 @@ sub rname2unitDetails ($;$$) {
my $unitDetails = UnitDetails( $u, $l ); my $unitDetails = UnitDetails( $u, $l );
$return{"unified"} = $reading if ( !$return{"unified"} );
if ( ref($unitDetails) eq "HASH" ) { if ( ref($unitDetails) eq "HASH" ) {
$return{"unit_guess"} = "1" if ( !$return{"short"} ); $return{"unit_guess"} = "1" if ( !$return{"short"} );
foreach my $k ( keys %{$unitDetails} ) { foreach my $k ( keys %{$unitDetails} ) {