mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-04 05:16:45 +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 %return;
|
||||
|
||||
# reading name exactly matches rtype
|
||||
return $reading if ( $rtypes->{$reading} && !wantarray );
|
||||
|
||||
# remove some prefix or other values to
|
||||
# flatten reading name
|
||||
$r =~ s/^fc\d+_//i;
|
||||
@ -2902,7 +2905,7 @@ sub rname2rtype ($$@) {
|
||||
$rt = (
|
||||
$readingsDB->{global}{$dr}{rtype}
|
||||
? $readingsDB->{global}{$dr}{rtype}
|
||||
: "-"
|
||||
: undef
|
||||
);
|
||||
}
|
||||
|
||||
@ -2913,7 +2916,7 @@ sub rname2rtype ($$@) {
|
||||
$rt = (
|
||||
$readingsDB->{global}{$r}{rtype}
|
||||
? $readingsDB->{global}{$r}{rtype}
|
||||
: "-"
|
||||
: undef
|
||||
);
|
||||
}
|
||||
|
||||
@ -2923,7 +2926,14 @@ sub rname2rtype ($$@) {
|
||||
$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 undef;
|
||||
}
|
||||
|
||||
######################################
|
||||
@ -3944,10 +3954,17 @@ sub formatValue($$$;$$$$) {
|
||||
# find desc for device:reading
|
||||
sub readingsDesc($;$) {
|
||||
my ( $device, $reading ) = @_;
|
||||
$device = "" unless ( defined($device) );
|
||||
my $desc = getCombinedKeyValAttr( $device, "readingsDesc", $reading );
|
||||
|
||||
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} ) ) {
|
||||
|
||||
@ -4178,14 +4195,18 @@ sub makeSTATE($;$$) {
|
||||
# get combined hash for settings from module, device, global and device attributes
|
||||
sub getCombinedKeyValAttr($;$$) {
|
||||
my ( $name, $attribute, $reading ) = @_;
|
||||
my $d = $defs{$name} if ( $defs{$name} );
|
||||
my $m = $modules{ $d->{TYPE} } if ( $d && $d->{TYPE} );
|
||||
my $d = $defs{$name} if ( $name && $defs{$name} );
|
||||
my $m = $modules{ $d->{TYPE} } if ( $d && $d->{TYPE} );
|
||||
my $g = $defs{"global"};
|
||||
|
||||
# join hashes until 3rd level
|
||||
|
||||
my $desc;
|
||||
if ( $m && $m->{$attribute} && ref( $m->{$attribute} ) eq "HASH" ) {
|
||||
if ( $m
|
||||
&& $attribute
|
||||
&& $m->{$attribute}
|
||||
&& ref( $m->{$attribute} ) eq "HASH" )
|
||||
{
|
||||
Log3( $name, 5,
|
||||
"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,
|
||||
"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,
|
||||
"getCombinedKeyValAttr $name $reading: including HASH from device attribute $attribute"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user