mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-04 11:26:55 +00:00
Unit.pm: allow using formatValue without device name, determine unit by reading name
git-svn-id: https://svn.fhem.de/fhem/trunk@17874 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
58bc1af1bc
commit
b946976123
@ -2878,6 +2878,9 @@ sub rname2rtype ($$@) {
|
|||||||
my $guess;
|
my $guess;
|
||||||
my %return;
|
my %return;
|
||||||
|
|
||||||
|
# reading name exactly matches rtype
|
||||||
|
return $reading if ( $rtypes->{$reading} && !wantarray );
|
||||||
|
|
||||||
# remove some prefix or other values to
|
# remove some prefix or other values to
|
||||||
# flatten reading name
|
# flatten reading name
|
||||||
$r =~ s/^fc\d+_//i;
|
$r =~ s/^fc\d+_//i;
|
||||||
@ -2902,7 +2905,7 @@ sub rname2rtype ($$@) {
|
|||||||
$rt = (
|
$rt = (
|
||||||
$readingsDB->{global}{$dr}{rtype}
|
$readingsDB->{global}{$dr}{rtype}
|
||||||
? $readingsDB->{global}{$dr}{rtype}
|
? $readingsDB->{global}{$dr}{rtype}
|
||||||
: "-"
|
: undef
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2913,7 +2916,7 @@ sub rname2rtype ($$@) {
|
|||||||
$rt = (
|
$rt = (
|
||||||
$readingsDB->{global}{$r}{rtype}
|
$readingsDB->{global}{$r}{rtype}
|
||||||
? $readingsDB->{global}{$r}{rtype}
|
? $readingsDB->{global}{$r}{rtype}
|
||||||
: "-"
|
: undef
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2923,7 +2926,14 @@ sub rname2rtype ($$@) {
|
|||||||
$rt = $1;
|
$rt = $1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wantarray) {
|
||||||
|
return ( $reading, $return{aliasname}, $return{shortname},
|
||||||
|
$return{guess} )
|
||||||
|
if ( $rtypes->{$reading} );
|
||||||
|
return ( $rt, $return{aliasname}, $return{shortname}, $return{guess} );
|
||||||
|
}
|
||||||
return $rt if ( $rt && $rtypes->{$rt} );
|
return $rt if ( $rt && $rtypes->{$rt} );
|
||||||
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
@ -3944,10 +3954,17 @@ sub formatValue($$$;$$$$) {
|
|||||||
# find desc for device:reading
|
# find desc for device:reading
|
||||||
sub readingsDesc($;$) {
|
sub readingsDesc($;$) {
|
||||||
my ( $device, $reading ) = @_;
|
my ( $device, $reading ) = @_;
|
||||||
|
$device = "" unless ( defined($device) );
|
||||||
my $desc = getCombinedKeyValAttr( $device, "readingsDesc", $reading );
|
my $desc = getCombinedKeyValAttr( $device, "readingsDesc", $reading );
|
||||||
|
|
||||||
my $rtype;
|
my $rtype;
|
||||||
$rtype = $desc->{rtype} if ( $desc->{rtype} );
|
if ( $desc->{rtype} ) {
|
||||||
|
$rtype = $desc->{rtype};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$rtype = rname2rtype( $device, $reading );
|
||||||
|
$desc->{rtype} = $rtype;
|
||||||
|
}
|
||||||
|
|
||||||
if ( $rtype && defined( $rtypes->{$rtype} ) ) {
|
if ( $rtype && defined( $rtypes->{$rtype} ) ) {
|
||||||
|
|
||||||
@ -4178,14 +4195,18 @@ sub makeSTATE($;$$) {
|
|||||||
# get combined hash for settings from module, device, global and device attributes
|
# get combined hash for settings from module, device, global and device attributes
|
||||||
sub getCombinedKeyValAttr($;$$) {
|
sub getCombinedKeyValAttr($;$$) {
|
||||||
my ( $name, $attribute, $reading ) = @_;
|
my ( $name, $attribute, $reading ) = @_;
|
||||||
my $d = $defs{$name} if ( $defs{$name} );
|
my $d = $defs{$name} if ( $name && $defs{$name} );
|
||||||
my $m = $modules{ $d->{TYPE} } if ( $d && $d->{TYPE} );
|
my $m = $modules{ $d->{TYPE} } if ( $d && $d->{TYPE} );
|
||||||
my $g = $defs{"global"};
|
my $g = $defs{"global"};
|
||||||
|
|
||||||
# join hashes until 3rd level
|
# join hashes until 3rd level
|
||||||
|
|
||||||
my $desc;
|
my $desc;
|
||||||
if ( $m && $m->{$attribute} && ref( $m->{$attribute} ) eq "HASH" ) {
|
if ( $m
|
||||||
|
&& $attribute
|
||||||
|
&& $m->{$attribute}
|
||||||
|
&& ref( $m->{$attribute} ) eq "HASH" )
|
||||||
|
{
|
||||||
Log3( $name, 5,
|
Log3( $name, 5,
|
||||||
"getCombinedKeyValAttr $name $reading: including HASH from module X_Initialize() function"
|
"getCombinedKeyValAttr $name $reading: including HASH from module X_Initialize() function"
|
||||||
);
|
);
|
||||||
@ -4214,7 +4235,11 @@ sub getCombinedKeyValAttr($;$$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $g && $g->{$attribute} && ref( $g->{$attribute} ) eq "HASH" ) {
|
if ( $g
|
||||||
|
&& $attribute
|
||||||
|
&& $g->{$attribute}
|
||||||
|
&& ref( $g->{$attribute} ) eq "HASH" )
|
||||||
|
{
|
||||||
Log3( $name, 5,
|
Log3( $name, 5,
|
||||||
"getCombinedKeyValAttr $name $reading: including HASH from global attribute $attribute"
|
"getCombinedKeyValAttr $name $reading: including HASH from global attribute $attribute"
|
||||||
);
|
);
|
||||||
@ -4243,7 +4268,11 @@ sub getCombinedKeyValAttr($;$$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $d && $d->{$attribute} && ref( $d->{$attribute} ) eq "HASH" ) {
|
if ( $d
|
||||||
|
&& $attribute
|
||||||
|
&& $d->{$attribute}
|
||||||
|
&& ref( $d->{$attribute} ) eq "HASH" )
|
||||||
|
{
|
||||||
Log3( $name, 5,
|
Log3( $name, 5,
|
||||||
"getCombinedKeyValAttr $name $reading: including HASH from device attribute $attribute"
|
"getCombinedKeyValAttr $name $reading: including HASH from device attribute $attribute"
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user