mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 18:59:33 +00:00
added valueFormat
git-svn-id: https://svn.fhem.de/fhem/trunk@3806 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
b6ef098110
commit
00b65536e8
@ -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
|
||||
|
@ -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($@)
|
||||
<li>valueStyle<br>
|
||||
Specify an HTML style for the reading values, e.g.:<br>
|
||||
<code>attr temperatures valueStyle style="text-align:right"</code></li>
|
||||
<li>valueFormat<br>
|
||||
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.:<br>
|
||||
<code>attr temperatures valueFormat %.1f °C"</code></li>
|
||||
<code>attr temperatures valueFormat { temperature => "%.1f °C", humidity => "%.1f %" }</code></li>
|
||||
<code>attr temperatures valueFormat { ($READING eq 'temperature')?"%.1f °C":undef }</code></li>
|
||||
</ul><br>
|
||||
|
||||
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.:<br>
|
||||
|
Loading…
Reference in New Issue
Block a user