#############################################
# $Id$
#
# This file is part of fhem.
#
# Fhem is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# Fhem is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with fhem. If not, see .
#
###############################################
package main;
use strict;
use warnings;
use Time::Local;
use Color;
use vars qw(%FW_rooms %FW_groups);
sub DOIFtools_Initialize($);
sub DOIFtools_Set($@);
sub DOIFtools_Get($@);
sub DOIFtools_Undef;
sub DOIFtools_Define($$$);
sub DOIFtools_Attr(@);
sub DOIFtools_Notify($$);
sub DOIFtoolsRg;
sub DOIFtoolsNxTimer;
sub DOIFtoolsNextTimer;
sub DOIFtoolsGetAssocDev;
sub DOIFtoolsCheckDOIF;
sub DOIFtoolsCheckDOIFcoll;
sub DOIFtools_fhemwebFn($$$$);
sub DOIFtools_eM($$$$);
sub DOIFtools_dO ($$$$);
sub DOIFtoolsSetNotifyDev;
sub DOIFtools_logWrapper($);
sub DOIFtoolsCounterReset($);
sub DOIFtoolsDeleteStatReadings;
my @DOIFtools_we = (0,0,0,0,0,0,0,0,0);
my $DOIFtoolsJSfuncEM = <<'EOF';
EOF
my $DOIFtoolsJSfuncStart = <<'EOF';
EOF
#########################
sub DOIFtools_Initialize($)
{
my ($hash) = @_;
$hash->{DefFn} = "DOIFtools_Define";
$hash->{SetFn} = "DOIFtools_Set";
$hash->{GetFn} = "DOIFtools_Get";
$hash->{UndefFn} = "DOIFtools_Undef";
$hash->{AttrFn} = "DOIFtools_Attr";
$hash->{NotifyFn} = "DOIFtools_Notify";
$hash->{FW_detailFn} = "DOIFtools_fhemwebFn";
$data{FWEXT}{"/DOIFtools_logWrapper"}{CONTENTFUNC} = "DOIFtools_logWrapper";
my $oldAttr = "target_room:noArg target_group:noArg executeDefinition:noArg executeSave:noArg eventMonitorInDOIF:noArg readingsPrefix:noArg";
$hash->{AttrList} = "DOIFtoolsExecuteDefinition:1,0 DOIFtoolsTargetRoom DOIFtoolsTargetGroup DOIFtoolsExecuteSave:1,0 DOIFtoolsReadingsPrefix DOIFtoolsEventMonitorInDOIF:1,0 DOIFtoolsHideModulShortcuts:1,0 DOIFtoolsHideGetSet:1,0 DOIFtoolsMyShortcuts:textField-long DOIFtoolsMenuEntry:1,0 DOIFtoolsHideStatReadings:1,0 DOIFtoolsEventOnDeleted:1,0 DOIFtoolsEMbeforeReadings:1,0 DOIFtoolsNoLookUp:1,0 DOIFtoolsNoLookUpInDOIF:1,0 DOIFtoolsLogDir disabledForIntervals ".$oldAttr; #DOIFtoolsForceGet:true
}
sub DOIFtools_dO ($$$$){
return "";}
# FW_detailFn for DOIF injecting event monitor
sub DOIFtools_eM($$$$) {
my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
my @dtn = devspec2array("TYPE=DOIFtools");
my $lang = AttrVal("global","language","EN");
my $ret = "";
# call DOIF_detailFn
no strict "refs";
my $retfn = &{ReadingsVal($dtn[0],".DOIF_detailFn","")}($FW_wname, $d, $room, $pageHash) if (ReadingsVal($dtn[0],".DOIF_detailFn",""));
$ret .= $retfn if ($retfn);
use strict "refs";
if (!$room) {
# LookUp in probably associated with
$ret .= $DOIFtoolsJSfuncStart if (!AttrVal($dtn[0],"DOIFtoolsNoLookUpInDOIF",""));
# Event Monitor
if (AttrVal($dtn[0],"DOIFtoolsEventMonitorInDOIF","")) {
my $a0 = ReadingsVal($d,".eM", "off") eq "on" ? "off" : "on";
$ret .= "
" if (ReadingsVal($dtn[0],".DOIF_detailFn",""));
$ret .= "
Event monitor: toggle ";
$ret .= " | ";
$ret .= "
";
my $a = "";
if (ReadingsVal($d,".eM","off") eq "on") {
$ret .= "";
my $filter = $a ? ($a eq "log" ? "global" : $a) : ".*";
$ret .= "";
$ret .= $DOIFtoolsJSfuncEM;
}
}
}
return $ret ? $ret : undef;
}
######################
# Show the content of the log (plain text), or an image and offer a link
# to convert it to an SVG instance
# If text and no reverse required, try to return the data as a stream;
sub DOIFtools_logWrapper($) {
my ($cmd) = @_;
my $d = $FW_webArgs{dev};
my $type = $FW_webArgs{type};
my $file = $FW_webArgs{file};
my $ret = "";
if(!$d || !$type || !$file) {
FW_pO 'DOIFtools_logWrapper: bad arguments
';
return 0;
}
if(defined($type) && $type eq "text") {
$defs{$d}{logfile} =~ m,^(.*)/([^/]*)$,; # Dir and File
my $path = "$1/$file";
$path =~ s/%L/$attr{global}{logdir}/g
if($path =~ m/%/ && $attr{global}{logdir});
$path = AttrVal($d,"archivedir","") . "/$file" if(!-f $path);
FW_pO "";
my $reverseLogs = AttrVal($FW_wname, "reverseLogs", 0);
if(!$reverseLogs) {
$suffix .= "