New Modul *BETA*
git-svn-id: https://svn.fhem.de/fhem/trunk@898 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
# 95 VIEW
|
# 95 VIEW
|
||||||
# Feedback: http://groups.google.com/group/fhem-users
|
# Feedback: http://groups.google.com/group/fhem-users
|
||||||
# Define Custom View
|
# Define Custom View
|
||||||
@@ -20,21 +20,7 @@
|
|||||||
# Show all Warnings of ALL Devices
|
# Show all Warnings of ALL Devices
|
||||||
# attr MyFHT ViewRegExType * or NotSet
|
# attr MyFHT ViewRegExType * or NotSet
|
||||||
# attr MyFHT ViewRegExName * or NotSet
|
# attr MyFHT ViewRegExName * or NotSet
|
||||||
# attr MyFHT ViewRegExReading Warning
|
# attr MyFHT ViewRegExReading warnings
|
||||||
#
|
|
||||||
# Ausgabe
|
|
||||||
# <Device-Name> <Device-Type>
|
|
||||||
# <READING-Name> <Reading-Value> <Reading-Time>
|
|
||||||
# Reihenfolge
|
|
||||||
# foreach $d (sort keys %defs){
|
|
||||||
# if($defs{$defs{$d}{TYPE}}{TYPE} =~ m/$attr{$d}{Type}/ && $d =~ m/$attr{<NAME>}{NAME}/){
|
|
||||||
# foreach $r (sort keys %{$defs{$d}{READINGS}}) {
|
|
||||||
# if($r =~ m/$attr{$d}{Reading}/) {
|
|
||||||
# print $d . ": " $r;
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
################################################################################
|
################################################################################
|
||||||
package main;
|
package main;
|
||||||
use strict;
|
use strict;
|
||||||
@@ -46,13 +32,16 @@ sub VIEW_Initialize($)
|
|||||||
{
|
{
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
$hash->{DefFn} = "VIEW_Define";
|
$hash->{DefFn} = "VIEW_Define";
|
||||||
$hash->{AttrList} = "ViewRegExType ViewRegExName ViewRegExReading loglevel:0,5";
|
$hash->{AttrList} = "ViewRegExType ViewRegExName ViewRegExReading ViewRegExReadingStringCompare loglevel:0,5";
|
||||||
# CGI
|
# CGI
|
||||||
my $name = "MyVIEWS";
|
my $name = "MyVIEWS";
|
||||||
my $fhem_url = "/" . $name ;
|
my $fhem_url = "/" . $name ;
|
||||||
$data{FWEXT}{$fhem_url}{FUNC} = "VIEW_CGI";
|
$data{FWEXT}{$fhem_url}{FUNC} = "VIEW_CGI";
|
||||||
$data{FWEXT}{$fhem_url}{LINK} = $name;
|
$data{FWEXT}{$fhem_url}{LINK} = $name;
|
||||||
$data{FWEXT}{$fhem_url}{NAME} = $name;
|
$data{FWEXT}{$fhem_url}{NAME} = $name;
|
||||||
|
# Global-Config for CSS
|
||||||
|
# $attr{global}{VIEW_CSS} = "";
|
||||||
|
$modules{_internal_}{AttrList} .= " VIEW_CSS";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
@@ -66,7 +55,7 @@ sub VIEW_CGI(){
|
|||||||
my ($htmlarg) = @_;
|
my ($htmlarg) = @_;
|
||||||
# Remove trailing slash
|
# Remove trailing slash
|
||||||
$htmlarg =~ s/^\///;
|
$htmlarg =~ s/^\///;
|
||||||
Log 0,"VIEW: htmlarg: " . $htmlarg ."\n";
|
# Log 0,"VIEW: htmlarg: " . $htmlarg ."\n";
|
||||||
# URL: http(s)://[FHEM:xxxx]/fhem/MyVIEWS/<View-Name>
|
# URL: http(s)://[FHEM:xxxx]/fhem/MyVIEWS/<View-Name>
|
||||||
my @params = split(/\//,$htmlarg);
|
my @params = split(/\//,$htmlarg);
|
||||||
my $ret_html;
|
my $ret_html;
|
||||||
@@ -81,13 +70,14 @@ sub VIEW_CGI(){
|
|||||||
return ("text/plain; charset=ISO-8859-1", $ret_html);
|
return ("text/plain; charset=ISO-8859-1", $ret_html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$ret_html .= "VIEW: $view\n";
|
$ret_html = "<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01\/\/EN\" \"http:\/\/www.w3.org\/TR\/html4\/strict.dtd\">\n";
|
||||||
$ret_html = "<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01\/\/EN\" \"http:\/\/www.w3.org\/TR\/html4\/strict.dtd\">\n";
|
|
||||||
$ret_html .= "<html>\n";
|
$ret_html .= "<html>\n";
|
||||||
$ret_html .= "<head>\n";
|
$ret_html .= "<head>\n";
|
||||||
$ret_html .= &VIEW_CGI_CSS();
|
# Select CSS-Style-Sheet
|
||||||
$ret_html .= "<title>FHEM GROUPS<\/title>\n";
|
my $css = $attr{global}{VIEW_CSS};
|
||||||
$ret_html .= "<link href=\"$FW_ME/style.css\" rel=\"stylesheet\"/>\n";
|
if($css eq ""){$ret_html .= "<link href=\"$FW_ME/style.css\" rel=\"stylesheet\"/>\n";}
|
||||||
|
else {$ret_html .= "<link href=\"$FW_ME/$css\" rel=\"stylesheet\"/>\n";}
|
||||||
|
$ret_html .= "<title>FHEM VIEWS<\/title>\n";
|
||||||
$ret_html .= "<\/head>\n";
|
$ret_html .= "<\/head>\n";
|
||||||
$ret_html .= "<body>\n";
|
$ret_html .= "<body>\n";
|
||||||
# DIV HDR
|
# DIV HDR
|
||||||
@@ -95,24 +85,17 @@ sub VIEW_CGI(){
|
|||||||
# DIV LEFT
|
# DIV LEFT
|
||||||
$ret_html .= &VIEW_CGI_LEFT();
|
$ret_html .= &VIEW_CGI_LEFT();
|
||||||
# DIV RIGHT
|
# DIV RIGHT
|
||||||
$ret_html .= &VIEW_CGI_RIGHT($view);
|
if($view) {
|
||||||
|
$ret_html .= &VIEW_CGI_RIGHT($view);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$ret_html .= "<div id=\"content\">\n";
|
||||||
|
$ret_html .= "</div>\n";
|
||||||
|
}
|
||||||
# HTML
|
# HTML
|
||||||
$ret_html .= "</body>\n";
|
$ret_html .= "</body>\n";
|
||||||
$ret_html .= "</html>\n";
|
$ret_html .= "</html>\n";
|
||||||
return ("text/html; charset=ISO-8859-1", $ret_html);
|
return ("text/html; charset=ISO-8859-1", $ret_html);
|
||||||
# return ("text/plain; charset=ISO-8859-1", $ret_html);
|
|
||||||
}
|
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
sub VIEW_CGI_CSS() {
|
|
||||||
my $css;
|
|
||||||
$css = "<style type=\"text/css\"><!--\n";
|
|
||||||
$css .= "\#left {float: left; width: 15%; height:100%;}\n";
|
|
||||||
$css .= "table.VIEW { border:thin solid; background: #E0E0E0; text-align:left;}\n";
|
|
||||||
$css .= "table.VIEW tr.odd { background: #F0F0F0;}\n";
|
|
||||||
$css .= "table.VIEW td.odd { background: #F0F0F0;}\n";
|
|
||||||
$css .= "table.VIEW td {nowrap;}";
|
|
||||||
$css .= "\/\/--><\/style>";
|
|
||||||
return $css;
|
|
||||||
}
|
}
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
sub VIEW_CGI_TOP($) {
|
sub VIEW_CGI_TOP($) {
|
||||||
@@ -123,7 +106,12 @@ sub VIEW_CGI_TOP($) {
|
|||||||
$rh .= "<form method=\"get\" action=\"" . $FW_ME . "\">\n";
|
$rh .= "<form method=\"get\" action=\"" . $FW_ME . "\">\n";
|
||||||
$rh .= "<table WIDTH=\"100%\">\n";
|
$rh .= "<table WIDTH=\"100%\">\n";
|
||||||
$rh .= "<tr>";
|
$rh .= "<tr>";
|
||||||
$rh .= "<td><a href=\"" . $FW_ME . "\">FHEM:</a>$v</td>";
|
if($v) {
|
||||||
|
$rh .= "<td><a href=\"" . $FW_ME . "\">FHEM:</a>$v</td>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$rh .= "<td><a href=\"" . $FW_ME . "\">FHEM:</a></td>";
|
||||||
|
}
|
||||||
$rh .= "<td><input type=\"text\" name=\"cmd\" size=\"30\"/></td>";
|
$rh .= "<td><input type=\"text\" name=\"cmd\" size=\"30\"/></td>";
|
||||||
$rh .= "</tr>\n";
|
$rh .= "</tr>\n";
|
||||||
$rh .= "</table>\n";
|
$rh .= "</table>\n";
|
||||||
@@ -136,7 +124,6 @@ sub VIEW_CGI_TOP($) {
|
|||||||
sub VIEW_CGI_LEFT(){
|
sub VIEW_CGI_LEFT(){
|
||||||
# rh = return-Html
|
# rh = return-Html
|
||||||
my $rh;
|
my $rh;
|
||||||
# $rh = "<div id=\"left\">\n";
|
|
||||||
$rh = "<div id=\"logo\"><img src=\"" . $FW_ME . "/fhem.png\"></div>";
|
$rh = "<div id=\"logo\"><img src=\"" . $FW_ME . "/fhem.png\"></div>";
|
||||||
$rh .= "<div id=\"menu\">\n";
|
$rh .= "<div id=\"menu\">\n";
|
||||||
# Print VIEWS
|
# Print VIEWS
|
||||||
@@ -169,60 +156,119 @@ sub VIEW_CGI_RIGHT(){
|
|||||||
if(defined($attr{$v}{ViewRegExReading})) {
|
if(defined($attr{$v}{ViewRegExReading})) {
|
||||||
$f_reading = $attr{$v}{ViewRegExReading};
|
$f_reading = $attr{$v}{ViewRegExReading};
|
||||||
}
|
}
|
||||||
|
my $f_reading_val = ".*";
|
||||||
|
if(defined($attr{$v}{ViewRegExReadingStringCompare})) {
|
||||||
|
$f_reading_val = $attr{$v}{ViewRegExReadingStringCompare};
|
||||||
|
}
|
||||||
my $row = 1;
|
my $row = 1;
|
||||||
$rh = "<div id=\"content\">\n";
|
$rh = "<div id=\"content\">\n";
|
||||||
$rh .= "<hr>\n";
|
$rh .= "<hr>\n";
|
||||||
$rh .= "[RegEx] Type: \"$f_type\" Name: \"$f_name\" Reading: \"$f_reading\"\n";
|
$rh .= "[RegEx] Type: \"$f_type\" Name: \"$f_name\" Reading: \"$f_reading\" Value:\"$f_reading_val\"\n";
|
||||||
$rh .= "<hr>\n";
|
$rh .= "<hr>\n";
|
||||||
my ($d,$r,$tr_class);
|
my ($d,$r,$tr_class);
|
||||||
my $th = undef;
|
my $th = undef;
|
||||||
# Get Devices and Readings
|
# Get Devices and Readings
|
||||||
# $rh .= "<table class=\"VIEW\" WIDTH=\"85%\">\n";
|
|
||||||
foreach $d (sort keys %defs){
|
foreach $d (sort keys %defs){
|
||||||
if($defs{$d}{TYPE} =~ m/$f_type/ && $d =~ m/$f_name/){
|
if($defs{$d}{TYPE} =~ m/$f_type/ && $d =~ m/$f_name/){
|
||||||
# Weblink
|
# Log 0,"VIEW-RIGHT: Device-Match $d";
|
||||||
if($defs{$d}{TYPE} eq "weblink") {
|
# Weblink
|
||||||
$rh .= "<table class=\"VIEW\">\n";
|
my $web_rt;
|
||||||
$rh .= FW_showWeblink($d, $defs{$d}{LINK}, $defs{$d}{WLTYPE});
|
if($defs{$d}{TYPE} eq "weblink" && $f_reading eq ".*" && $f_reading_val eq ".*") {
|
||||||
$rh .= "</table>\n";
|
$rh .= "<table class=\"block\">\n";
|
||||||
}
|
$rh .="<tr><td>WEBLINK: $d</td></tr>\n";
|
||||||
else {
|
# $rh .= FW_showWeblink($d, $defs{$d}{LINK}, $defs{$d}{WLTYPE});
|
||||||
foreach $r (sort keys %{$defs{$d}{READINGS}}) {
|
$rh .= VIEW_showWeblink($d, $defs{$d}{LINK}, $defs{$d}{WLTYPE});
|
||||||
if($r =~ m/$f_reading/) {
|
# Log 0,"VIEW-RIGHT: FW_showWeblink \n $web_rt\n";
|
||||||
$tr_class = $row?"odd":"even";
|
# FW_showWeblink($d, $defs{$d}{LINK}, $defs{$d}{WLTYPE});
|
||||||
if(!$th) {
|
# Log 0,"VIEW-RIGHT: Render-Weblink $d";
|
||||||
$rh .= "<br>\n";
|
$rh .= "</table>\n";
|
||||||
$rh .= "<table class=\"VIEW\">\n";
|
}
|
||||||
# $rh .= "<table class=\"VIEW\" WIDTH=\"85%\">\n";
|
else {
|
||||||
$rh .= "<tr class=\"" . $tr_class . "\">";
|
foreach $r (sort keys %{$defs{$d}{READINGS}}) {
|
||||||
$rh .= "<td align=\"left\"><a href=\"$FW_ME?detail=$d\">$d</a></td>";
|
if($r =~ m/$f_reading/) {
|
||||||
$rh .= "<td></td>";
|
# ViewRegExReadingStringCompare
|
||||||
$rh .= "<td>" . $defs{$d}{TYPE} . "</td>";
|
if($defs{$d}{READINGS}{$r}{VAL} =~ m/$f_reading_val/){
|
||||||
$rh .= "<td>" . $defs{$d}{STATE} . "</td>";
|
$tr_class = $row?"odd":"even";
|
||||||
$rh .= "</tr>\n";
|
if(!$th) {
|
||||||
$th = 1;
|
$rh .= "<br>\n";
|
||||||
$row = ($row+1)%2;
|
$rh .= "<table class=\"block\" id=\"" . $defs{$d}{TYPE} . "\" >\n";
|
||||||
$tr_class = $row?"odd":"even";
|
$rh .= "<tr class=\"" . $tr_class . "\">";
|
||||||
}
|
$rh .= "<td align=\"left\"><a href=\"$FW_ME?detail=$d\">$d</a></td>";
|
||||||
$rh .= "<tr class=\"" . $tr_class . "\">";
|
if(defined($attr{$d}{comment})) {
|
||||||
$rh .= "<td></td>";
|
$rh .= "<td>" . $attr{$d}{comment} . "</td>";
|
||||||
$rh .= "<td>$r</td>";
|
}
|
||||||
$rh .= "<td>" . $defs{$d}{READINGS}{$r}{VAL} . "</td>";
|
else {
|
||||||
$rh .= "<td>" . $defs{$d}{READINGS}{$r}{TIME} . "</td>";
|
$rh .= "<td>" . $defs{$d}{TYPE} . "</td>";
|
||||||
$rh .= "</tr>\n";
|
}
|
||||||
$row = ($row+1)%2;
|
$rh .= "<td>" . $defs{$d}{STATE} . "</td>";
|
||||||
}
|
$rh .= "</tr>\n";
|
||||||
|
$th = 1;
|
||||||
|
$row = ($row+1)%2;
|
||||||
|
$tr_class = $row?"odd":"even";
|
||||||
|
}
|
||||||
|
$rh .= "<tr class=\"" . $tr_class . "\">";
|
||||||
|
$rh .= "<td>$r</td>";
|
||||||
|
$rh .= "<td>" . $defs{$d}{READINGS}{$r}{VAL} . "</td>";
|
||||||
|
$rh .= "<td>" . $defs{$d}{READINGS}{$r}{TIME} . "</td>";
|
||||||
|
$rh .= "</tr>\n";
|
||||||
|
$row = ($row+1)%2;
|
||||||
|
# ViewRegExReadingStringCompare
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$rh .= "</table>\n";
|
||||||
}
|
}
|
||||||
$rh .= "</table>\n";
|
|
||||||
# $rh .= "<br>\n";
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$th = undef;
|
$th = undef;
|
||||||
|
|
||||||
}
|
}
|
||||||
# $rh .= "</table>\n";
|
|
||||||
$rh .= "</div>\n";
|
$rh .= "</div>\n";
|
||||||
return $rh;
|
return $rh;
|
||||||
}
|
}
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
sub VIEW_showWeblink($$$)
|
||||||
|
{
|
||||||
|
# Customized Function from 01_FHEMWEB.pm
|
||||||
|
my $FW_plotmode = "gnuplot-scroll";
|
||||||
|
my $FW_plotsize = "800,225";
|
||||||
|
my ($d, $v, $t) = @_;
|
||||||
|
my $rh;
|
||||||
|
if($t eq "link") {
|
||||||
|
$rh .= "<td><a href=\"$v\">$d</a></td>\n"; # no pH, want to open extra browser
|
||||||
|
}
|
||||||
|
elsif($t eq "image") {
|
||||||
|
$rh .= "<td><img src=\"$v\"><br>";
|
||||||
|
$rh .= "<a href=\"$FW_ME?detail=$d\">$d</a>";
|
||||||
|
$rh .= "</td>\n";
|
||||||
|
}
|
||||||
|
elsif($t eq "fileplot") {
|
||||||
|
my @va = split(":", $v, 3);
|
||||||
|
if(@va != 3 || !$defs{$va[0]} || !$defs{$va[0]}{currentlogfile}) {
|
||||||
|
$rh .= "<td>Broken definition: $v</td>\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if($va[2] eq "CURRENT") {
|
||||||
|
$defs{$va[0]}{currentlogfile} =~ m,([^/]*)$,;
|
||||||
|
$va[2] = $1;
|
||||||
|
}
|
||||||
|
$rh .= "<table><tr><td>";
|
||||||
|
my $wl = "&pos=";
|
||||||
|
my $arg="$FW_ME?cmd=showlog $d $va[0] $va[1] $va[2]$wl";
|
||||||
|
if(AttrVal($d,"plotmode",$FW_plotmode) eq "SVG") {
|
||||||
|
my ($w, $h) = split(",", AttrVal($d,"plotsize",$FW_plotsize));
|
||||||
|
$rh .= "<embed src=\"$arg\" type=\"image/svg+xml\"" .
|
||||||
|
"width=\"$w\" height=\"$h\" name=\"$d\"/>\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$rh .= "<img src=\"$arg\"/>";
|
||||||
|
}
|
||||||
|
$rh .= "</td>\n";
|
||||||
|
$rh .= "<td><a href=\"$FW_ME?detail=$d\">$d</a></td>\n";
|
||||||
|
$rh .= "</tr></table>";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
1;
|
1;
|
||||||
|
|||||||
Reference in New Issue
Block a user