diff --git a/fhem/CHANGED b/fhem/CHANGED index fc8e41991..a2db57826 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. # Do not insert empty lines here, update check depends on it. + - feature: readingsGroup: allow grouping of similar readings from one device 14_SD_WS09.pm WH1080 CRC-Berechung angepaßt--> automatische Modelauswahl - feature: 00_SIGNALduino: nonblocking communication, improved init and keepalive, fixed manchester related stuff, Supports diff --git a/fhem/FHEM/33_readingsGroup.pm b/fhem/FHEM/33_readingsGroup.pm index b2deae63d..1a36c8c08 100644 --- a/fhem/FHEM/33_readingsGroup.pm +++ b/fhem/FHEM/33_readingsGroup.pm @@ -42,7 +42,7 @@ sub readingsGroup_Initialize($) $hash->{SetFn} = "readingsGroup_Set"; $hash->{GetFn} = "readingsGroup_Get"; $hash->{AttrFn} = "readingsGroup_Attr"; - $hash->{AttrList} = "disable:1,2,3 style timestampStyle ". join( " ", @mapping_attrs ) ." separator nolinks:1 noheading:1 nonames:1 notime:1 nostate:1 firstCalcRow:1,2,3,4 alwaysTrigger:1,2 sortDevices:1 visibility:hidden,hideable,collapsed,collapsible setList setFn:textField-long"; + $hash->{AttrList} = "disable:1,2,3 style timestampStyle ". join( " ", @mapping_attrs ) ." separator nolinks:1 noheading:1 nonames:1 notime:1 nostate:1 firstCalcRow:1,2,3,4 alwaysTrigger:1,2 sortDevices:1 sortFn visibility:hidden,hideable,collapsed,collapsible setList setFn:textField-long"; $hash->{FW_detailFn} = "readingsGroup_detailFn"; $hash->{FW_summaryFn} = "readingsGroup_detailFn"; @@ -175,11 +175,11 @@ readingsGroup_updateDevices($;$) if( $regex =~ m/^<.*>$/ ) { } elsif( $regex !~ m/^\$/ && $regex =~ m/(.*)@(.*)/ ) { $regex = $1; + my $name = $2; next if( $regex && $regex =~ m/^\+(.*)/ ); next if( $regex && $regex =~ m/^\?(.*)/ ); - my $name = $2; if( $name =~ m/^{(.*)}$/s ) { my $DEVICE = $device->[0]; $name = eval $name; @@ -751,6 +751,52 @@ readingsGroup_2html($;$) my @list = (undef); @list = split(",",$regex) if( $regex ); + + delete $hash->{groupedList}; + if( @list && $list[0] =~ m/^@(.*)/ ) { + my $index = $1; + my $regex = $list[$index]; + + my @l; + foreach my $n (keys %{$h->{READINGS}}) { + eval { $n =~ m/^$regex$/ }; + if( $@ ) { + Log3 $name, 3, $name .": ". $regex .": ". $@; + last; + } + next if( $n !~ m/^$regex$/); + push @l, [$n, $1, $2, $3, $4]; + } + + if( my $sortFn = AttrVal($d, "sortFn", '') ) { + sub rgSortIP { + return inet_aton(@{$a}[1]) cmp inet_aton(@{$b}[1]); + }; + @l = eval "sort { $sortFn } \@l"; + if( $@ ) { + $txt = ""; + Log3 $d, 3, $d .": ". $regex .": ". $@; + next; + } + } else { + sub rgSort { + return @{$a}[1] cmp @{$b}[1]; + }; + @l = sort rgSort @l; + } + + $hash->{groupedList} = (); + foreach my $n (@l) { + my $cg1 = @{$n}[1]; my $cg2 = @{$n}[2]; my $cg3 = @{$n}[3]; my $cg4 = @{$n}[4]; + my @l = @list[1..@list-1]; + $l[$index-1] = @{$n}[0]; + s/#1/$cg1/ for @l; s/#2/$cg2/ for @l; s/#3/$cg3/ for @l; s/#4/$cg4/ for @l; + push @{$hash->{groupedList}}, '' if( $hash->{groupedList} ); + push @{$hash->{groupedList}}, @l; + } + @list = @{$hash->{groupedList}}; + } + my $first = 1; my $multi = @list; my $cell_column = 1; @@ -801,9 +847,10 @@ readingsGroup_2html($;$) } } - if( $txt eq 'br' ) { + $row++ if( $txt eq 'br2' ); + if( $txt eq 'br' || $txt eq 'br2' ) { $ret .= sprintf("", ($row-1&1)?"odd":"even"); - $ret .= "
"; + $ret .= "
" if( $show_names ); $first = 0; ++$cell_row; $cell_column = 1; @@ -1034,8 +1081,8 @@ readingsGroup_2html($;$) } $txt = "
$txt
" if( !$show_links ); - $txt = "$txt" if( $show_links ); - $ret .= "
$txt
"; + $txt = "$txt" if( defined($txt) && $show_links ); + $ret .= "
$txt
" if( defined($txt) ); } } @@ -1181,6 +1228,11 @@ readingsGroup_Notify($$) my $regex = @{$device}[1]; my @list = (undef); @list = split(",",$regex) if( $regex ); + + if( $hash->{groupedList} ) { + @list = @{$hash->{groupedList}}; + } + for( my $i = 0; $i <= $#list; ++$i ) { my $regex = $list[$i]; while ($regex @@ -1582,6 +1634,10 @@ readingsGroup_Attr($$$;$)
  • if STRING is of the form %ICON[%CMD] ICON will be used as the name of an icon instead of a text and CMD as the command to be executed if the icon is clicked. also see the commands attribute.
  • if readings is given the perl expression will be reevaluated during longpoll updates. +
  • If the first regex is '@<index>' it gives the index of the following regex by which the readings + are to be grouped. if capture groups are used they can be refferenced by #<number>. eg:
      + <IP-Adress><Hostname><MAC><Vendor>
      + nmap:@2,<#1>,(.*)_hostname,#1_macAddress,#1_macVendor
  • For internal values and attributes longpoll update is not possible. Refresh the page to update the values.
  • the <{perl}> expression is limited to expressions without a space. it is best just to call a small sub in 99_myUtils.pm instead of having a compex expression in the define.
  • @@ -1780,7 +1836,8 @@ readingsGroup_Attr($$$;$) the font-... and background attributes do work.

    Calculation: to be written...
    - eg: define rg readingsGroup .*:temperature rg:$avg + eg: define rg readingsGroup .*:temperature rg:$avg
    + please see a description in the wiki =end html