diff --git a/fhem/CHANGED b/fhem/CHANGED index ab886942e..d7c208ccf 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. - SVN + - change: readingsGroup added valueFormat - feature: new modules JeeLink and PCA301 and for the ELV PCA 301 power meter with a JeeLabs JeeLink as RF modem. The matching JeeNode sketch can be found in .../contrib/36_PCA301-pcaSerial.zip diff --git a/fhem/FHEM/33_readingsGroup.pm b/fhem/FHEM/33_readingsGroup.pm index e448caea0..86df5b72b 100644 --- a/fhem/FHEM/33_readingsGroup.pm +++ b/fhem/FHEM/33_readingsGroup.pm @@ -17,7 +17,7 @@ sub readingsGroup_Initialize($) $hash->{UndefFn} = "readingsGroup_Undefine"; #$hash->{SetFn} = "readingsGroup_Set"; $hash->{GetFn} = "readingsGroup_Get"; - $hash->{AttrList} = "mapping separator style nameStyle valueStyle timestampStyle noheading:1 notime:1 nostate:1"; + $hash->{AttrList} = "mapping separator style nameStyle valueStyle valueFormat timestampStyle noheading:1 notime:1 nostate:1"; $hash->{FW_detailFn} = "readingsGroup_detailFn"; $hash->{FW_summaryFn} = "readingsGroup_detailFn"; @@ -123,6 +123,12 @@ readingsGroup_2html($) my $value_style = AttrVal( $d, "valueStyle", "" ); my $timestamp_style = AttrVal( $d, "timestampStyle", "" ); + my $value_format = AttrVal( $d, "valueFormat", "" ); + if( $value_format =~ m/^{.*}$/ ) { + my $vf = eval $value_format; + $value_format = $vf if( $vf ); + } + my $mapping = AttrVal( $d, "mapping", ""); $mapping = eval $mapping if( $mapping =~ m/^{.*}$/ ); #$mapping = undef if( ref($mapping) ne 'HASH' ); @@ -177,6 +183,19 @@ readingsGroup_2html($) $value_style = "" if( !$value_style ); } + if( $value_format ) { + my $value_format = $value_format; + if( ref($value_format) eq 'HASH' ) { + $value_format = $value_format->{$n}; + } elsif( $value_format =~ m/^{.*}$/) { + my $DEVICE = $name; + my $READING = $n; + my $VALUE = $v; + $value_format = eval $value_format; + } + $v = sprintf( $value_format, $v ) if( $value_format ); + } + my $a = AttrVal($name, "alias", $name); my $m = "$a$separator$n"; @@ -228,6 +247,19 @@ readingsGroup_2html($) $value_style = "" if( !$value_style ); } + if( $value_format ) { + my $value_format = $value_format; + if( ref($value_format) eq 'HASH' ) { + $value_format = $value_format->{$n}; + } elsif( $value_format =~ m/^{.*}$/) { + my $DEVICE = $name; + my $READING = $n; + my $VALUE = $v; + $value_format = eval $value_format; + } + $v = sprintf( $value_format, $v ) if( $value_format ); + } + my $a = AttrVal($name, "alias", $name); my $m = "$a$separator$n"; @@ -445,6 +477,12 @@ readingsGroup_Get($@)
  • valueStyle
    Specify an HTML style for the reading values, e.g.:
    attr temperatures valueStyle style="text-align:right"
  • +
  • valueFormat
    + Specify an sprintf style format string used to display the reading values. Can be given as a string, + a perl expression returninga hash or a perl expression returning a string, e.g.:
    + attr temperatures valueFormat %.1f °C"
  • + attr temperatures valueFormat { temperature => "%.1f °C", humidity => "%.1f %" } + attr temperatures valueFormat { ($READING eq 'temperature')?"%.1f °C":undef }
    The nameStyle and valueStyle attributes can also contain a perl expression enclosed in {} that returns the style string to use. The perl code can use $DEVICE,$READING and $VALUE, e.g.: