From ba6165fd1f435863e76ca4944db34245b163c4cf Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sat, 6 Jul 2013 09:45:31 +0000 Subject: [PATCH] readings type added to weblink (justme1968) git-svn-id: https://svn.fhem.de/fhem/trunk@3388 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/98_weblink.pm | 101 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 98 insertions(+), 4 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 2fc6a9348..f5a4ee568 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII - SVN + - feature: readings type added to weblink (justme1968) - feature: offset and monotonic added to userReadings modifier (justme1968) - feature: HUEDevice: support SVG icons for LWB001 living whites bulb - feature: HUEDevice: support more than one bridge diff --git a/fhem/FHEM/98_weblink.pm b/fhem/FHEM/98_weblink.pm index e028f0c79..8b2624458 100755 --- a/fhem/FHEM/98_weblink.pm +++ b/fhem/FHEM/98_weblink.pm @@ -38,7 +38,7 @@ weblink_Define($$) { my ($hash, $def) = @_; my ($type, $name, $wltype, $link) = split("[ \t]+", $def, 4); - my %thash = ( link=>1, fileplot=>1, dbplot=>1, image=>1, iframe=>1, htmlCode=>1, cmdList=>1 ); + my %thash = ( link=>1, fileplot=>1, dbplot=>1, image=>1, iframe=>1, htmlCode=>1, cmdList=>1, readings=>1 ); if(!$link || !$thash{$wltype}) { return "Usage: define weblink [" . @@ -141,9 +141,9 @@ weblink_FwFn($$$$) } elsif($wltype eq "cmdList") { my @lines = split(" ", $link); - my $row = 0; + my $row = 1; my $ret = ""; - $ret .= ""; + $ret .= ""; $ret .= "
"; foreach my $line (@lines) { my @args = split(":", $line, 3); @@ -157,6 +157,82 @@ weblink_FwFn($$$$) return $ret; + } elsif($wltype eq "readings") { + my @params = split(" ", $link); + + my @devices; + my $mapping; + my $show_heading = 1; + my $show_state = 1; + my $show_time = 1; + + while (@params) { + my $param = shift(@params); + + if( $param eq '*noheading' ) { + $show_heading = 0; + }elsif( $param eq '*notime' ) { + $show_time = 0; + } + elsif( $param eq '*nostate' ) { + $show_state = 0; + }elsif( $param =~ m/^{/) { + $mapping = eval $param ." ". join( " ", @params ); + last; + } else { + my @device = split(":", $param); + + if( defined($defs{$device[0]}) ) { + push @devices, [@device]; + } else { + foreach my $d (sort keys %defs) { + next if( $d !~ m/$device[0]/); + push @devices, [$d,$device[1]]; + } + } + } + } + + my $row = 1; + my $ret = ""; + $ret .= "
"; + $ret .= "" if( $show_heading ); + $ret .= ""; + $ret .= "
"; + foreach my $device (@devices) { + my $h = $defs{@{$device}[0]}; + my $regex = @{$device}[1]; + my $name = $h->{NAME}; + next if( !$h ); + foreach my $n (sort keys %{$h->{READINGS}}) { + next if( $n =~ m/^\./); + next if( $n eq "state" && !$show_state ); + next if( defined($regex) && $n !~ m/$regex/); + my $val = $h->{READINGS}->{$n}; + + if(ref($val)) { + my ($v, $t) = ($val->{VAL}, $val->{TIME}); + $v = FW_htmlEscape($v); + $t = "" if(!$t); + + $ret .= sprintf("", ($row&1)?"odd":"even"); + $row++; + + my $m = $n; + $m = $mapping->{$n} if( defined($mapping) && defined($mapping->{$n}) ); + $m = $mapping->{$name.".".$n} if( defined($mapping) && defined($mapping->{$name.".".$n}) ); + $m =~ s/\$NAME/$name/g; + $ret .= "";; + $ret .= ""; + $ret .= "" if( $show_time ); + } + } + } + $ret .= "
$v
$t
"; + $ret .= "
"; + + return $ret; + } elsif($wltype eq "fileplot" || $wltype eq "dbplot" ) { # plots navigation buttons @@ -453,7 +529,7 @@ weblink_WriteGplot($) Define
    - define <name> weblink [link|fileplot|dbplot|image|iframe|htmlCode|cmdList] + define <name> weblink [link|fileplot|dbplot|image|iframe|htmlCode|cmdList|readings] <argument>

    This is a placeholder used with webpgm2 to be able to integrate links @@ -470,6 +546,8 @@ weblink_WriteGplot($) define MyPlot weblink fileplot <logdevice>:<gnuplot-file>:<logfile>
    define MyPlot weblink dbplot <logdevice>:<gnuplot-file>
    define systemCommands weblink cmdList pair:Pair:set+cul2+hmPairForSec+60 restart:Restart:shutdown+restart update:UpdateCheck:update+check
    + define wl_SystemStatus weblink readings sysstat *nostate *notime {{ 'load' => 'Systemauslastung in %', 'temperature' => 'Systemtemperatur in &deg;;C'}} + define wlHeizung weblink readings t1:temperature t2:temperature t3:temperature *notime {{ 't1.temperature' => 'Vorlauf', 't2.temperature' => 'R&uuml;;cklauf', 't3.temperature' => 'Zirkulation'}}

@@ -483,6 +561,21 @@ weblink_WriteGplot($) file, even if its name changes regularly (and not the one you originally specified).
  • For cmdList <argument> consist of a list of space separated icon:label:cmd triples.
  • +
  • For redings <argument> consist of one or more <device>[:regex] pairs, + zero or more of the modifiers *noheading, *notime and *nostate and as the last argument an optional {} expression that should return + a perl hash to map reading names to display names. +
      +
    • <device>
      + the device(s) from which the readings should be taken
    • +
    • regex
      + an optional regex to select the readings that should be displayed.
    • +
    • *noheading
      don't display the table heading
    • +
    • *notime
      don't display the reading timestamp
    • +
    • *nostate
      don't include the state reading, other readings can be excluded with a regex of the form:^((?!reading).)*$
    • +
    • {...}
      + a perl expression that returns a hash that maps the reading name to the display name. keys can be either the name of the reading or <device>.<reading>. $NAME is replaced by the device name
    • + +