2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

notify/FileLog/FHEMWEB/watchdog/eventTypes: addStateEvent attribute added

git-svn-id: https://svn.fhem.de/fhem/trunk@5452 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2014-04-06 06:24:47 +00:00
parent c18ec5b14c
commit 047fa6a9f6
6 changed files with 87 additions and 26 deletions

View File

@ -121,6 +121,7 @@ FHEMWEB_Initialize($)
HTTPS:1,0
JavaScripts
SVGcache:1,0
addStateEvent
allowedCommands
allowfrom
basicAuth
@ -2062,6 +2063,8 @@ FW_Notify($$)
my @data;
my %extPage;
my $isRaw = ($h->{type} =~ m/raw/);
my $events = deviceEvents($dev, AttrVal($FW_wname, "addStateEvent",!$isRaw));
if($h->{type} =~ m/status/) {
# Why is saving this stuff needed? FLOORPLAN?
@ -2084,31 +2087,31 @@ FW_Notify($$)
push @data, "$dn<<$dev->{STATE}<<$txt";
#Add READINGS
if($dev->{CHANGED}) { # It gets deleted sometimes (?)
if($events) { # It gets deleted sometimes (?)
my $tn = TimeNow();
my $max = int(@{$dev->{CHANGED}});
my $max = int(@{$events});
for(my $i = 0; $i < $max; $i++) {
if( $dev->{CHANGED}[$i] !~ /: /) {
if( $events->[$i] !~ /: /) {
next; #ignore 'set' commands
}
my ($readingName,$readingVal) = split(": ",$dev->{CHANGED}[$i],2);
my ($readingName,$readingVal) = split(": ",$events->[$i],2);
push @data, "$dn-$readingName<<$readingVal<<$readingVal";
push @data, "$dn-$readingName-ts<<$tn<<$tn";
}
}
}
if($h->{type} =~ m/raw/) {
if($dev->{CHANGED}) { # It gets deleted sometimes (?)
if($isRaw) {
if($events) { # It gets deleted sometimes (?)
my $tn = TimeNow();
if($attr{global}{mseclog}) {
my ($seconds, $microseconds) = gettimeofday();
$tn .= sprintf(".%03d", $microseconds/1000);
}
my $max = int(@{$dev->{CHANGED}});
my $max = int(@{$events});
my $dt = $dev->{TYPE};
for(my $i = 0; $i < $max; $i++) {
push @data,("$tn $dt $dn ".$dev->{CHANGED}[$i]."<br>");
push @data,("$tn $dt $dn ".$events->[$i]."<br>");
}
}
}
@ -2618,6 +2621,8 @@ FW_ActivateInform()
<br>
</li>
<li><a href="#addStateEvent">addStateEvent</a></li>
<a name="allowedCommands"></a>
<li>allowedCommands<br>
A comma separated list of commands allowed from this FHEMWEB
@ -3123,6 +3128,8 @@ FW_ActivateInform()
<br>
</li>
<li><a href="#addStateEvent">addStateEvent</a></li>
<a name="allowedCommands"></a>
<li>allowedCommands<br>
Eine Komma getrennte Liste der erlaubten Befehle. Bei einer leeren

View File

@ -66,14 +66,15 @@ eventTypes_Notify($$)
my $ln = $me->{NAME};
return "" if($attr{$ln} && $attr{$ln}{disable});
return if(!$eventSrc->{CHANGED});
my $events = deviceEvents($eventSrc, 1);
return if(!$events);
my $t = $eventSrc->{TYPE};
my $n = $eventSrc->{NAME};
return if(!defined($n) || !defined($t) || $n eq "global");
my $ret = "";
foreach my $oe (@{$eventSrc->{CHANGED}}) {
foreach my $oe (@{$events}) {
$oe = "" if(!defined($oe));
next if($oe =~ m/ CULHM (SND|RCV) /);
next if($oe =~ m/ UNKNOWNCODE /);

View File

@ -14,7 +14,7 @@ notify_Initialize($)
$hash->{DefFn} = "notify_Define";
$hash->{NotifyFn} = "notify_Exec";
$hash->{AttrFn} = "notify_Attr";
$hash->{AttrList} = "disable:0,1 disabledForIntervals forwardReturnValue:0,1 showTriggerTime:0,1";
$hash->{AttrList} = "disable:0,1 disabledForIntervals forwardReturnValue:0,1 showTriggerTime:0,1 addStateEvent:0,1";
}
@ -56,13 +56,14 @@ notify_Exec($$)
my $n = $dev->{NAME};
my $re = $ntfy->{REGEXP};
return if(!$dev->{CHANGED}); # Some previous notify deleted the array.
my $max = int(@{$dev->{CHANGED}});
my $events = deviceEvents($dev, AttrVal($ln, "addStateEvent", 0));
return if(!$events); # Some previous notify deleted the array.
my $max = int(@{$events});
my $t = $dev->{TYPE};
my $ret = "";
for (my $i = 0; $i < $max; $i++) {
my $s = $dev->{CHANGED}[$i];
my $s = $events->[$i];
$s = "" if(!defined($s));
my $found = ($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/);
if(!$found && AttrVal($n, "eventMap", undef)) {
@ -239,6 +240,21 @@ notify_Attr(@)
Show the timestamp of the last execution as the status (STATE) of the
notify instance. Default is 1 (on).
</li>
<a name="addStateEvent"></a>
<li>addStateEvent<br>
The event associated with the state Reading is special, as the "state: "
string is stripped, i.e $EVENT is not "state: on" but just "on". In some
circumstances it is desireable to get an additional event where "state: "
is not stripped. In such a case the addStateEvent attribute should be
set to 1 (default is 0, i.e. do not generate an additional event).<br>
Note 1: you have to set this attribute for the event "receiver", i.e.
notify, FileLog, etc.<br>
Note 2: this attribute will only work for events generated by devices
supporting the <a href="#readingFnAttributes">readingFnAttributes</a>.
</li>
</ul>
<br>

View File

@ -16,7 +16,7 @@ watchdog_Initialize($)
$hash->{UndefFn} = "watchdog_Undef";
$hash->{NotifyFn} = "watchdog_Notify";
$hash->{AttrList} = "disable:0,1 disabledForIntervals ".
"regexp1WontReactivate:0,1";
"regexp1WontReactivate:0,1 addStateEvent:0,1";
}
@ -72,10 +72,12 @@ watchdog_Notify($$)
my $n = $dev->{NAME};
my $re1 = $watchdog->{RE1};
my $re2 = $watchdog->{RE2};
my $max = int(@{$dev->{CHANGED}});
my $events = deviceEvents($dev, AttrVal($ln, "addStateEvent", 0));
my $max = int(@{$events});
for (my $i = 0; $i < $max; $i++) {
my $s = $dev->{CHANGED}[$i];
my $s = $events->[$i];
$s = "" if(!defined($s));
my $dotTrigger = ($ln eq $n && $s eq "."); # trigger w .
@ -324,8 +326,9 @@ watchdog_Undef($$)
<b>Get</b> <ul>N/A</ul><br>
<a name="watchdogattr"></a>
<b>Attributes</b>
<b>Attribute</b>
<ul>
<li><a href="#addStateEvent">addStateEvent</a></li>
<li><a href="#disable">disable</a></li>
<li><a href="#disabledForIntervals">disabledForIntervals</a></li>
<li><a name="regexp1WontReactivate">regexp1WontReactivate</a><br>

View File

@ -37,7 +37,8 @@ FileLog_Initialize($)
$hash->{NotifyFn} = "FileLog_Log";
$hash->{AttrFn} = "FileLog_Attr";
# logtype is used by the frontend
$hash->{AttrList} = "disable:0,1 logtype nrarchive archivedir archivecmd";
$hash->{AttrList} = "disable:0,1 logtype ".
"nrarchive archivedir archivecmd addStateEvent:0,1";
$hash->{FW_summaryFn} = "FileLog_fhemwebFn";
$hash->{FW_detailFn} = "FileLog_fhemwebFn";
@ -129,18 +130,19 @@ FileLog_Log($$)
my $ln = $log->{NAME};
return if($attr{$ln} && $attr{$ln}{disable});
return if(!$dev || !defined($dev->{CHANGED}));
my $events = deviceEvents($dev, AttrVal($ln, "addStateEvent", 0));
return if(!$events);
my $n = $dev->{NAME};
my $re = $log->{REGEXP};
my $max = int(@{$dev->{CHANGED}});
my $max = int(@{$events});
my $tn = $dev->{NTFY_TRIGGERTIME};
my $ct = $dev->{CHANGETIME};
my $fh;
my $switched;
for (my $i = 0; $i < $max; $i++) {
my $s = $dev->{CHANGED}[$i];
my $s = $events->[$i];
$s = "" if(!defined($s));
my $t = (($ct && $ct->[$i]) ? $ct->[$i] : $tn);
if($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/ || "$t:$n:$s" =~ m/^$re$/) {
@ -1397,6 +1399,7 @@ FileLog_sampleDataFn($$$$$)
</li><br>
<li><a href="#disable">disable</a></li>
<li><a href="#addStateEvent">addStateEvent</a></li>
<a name="logtype"></a>
<li>logtype<br>
@ -1439,6 +1442,7 @@ FileLog_sampleDataFn($$$$$)
Text).Eine gnuplot-Definition ist nicht notwendig. </li> </ul>
Beispiel:<br> attr ks300log1 logtype
temp4rain10:Temp/Rain,hum6wind8:Hum/Wind,text:Raw-data </li><br>
</ul>
<br>
</ul>

View File

@ -495,7 +495,7 @@ $fhem_started = time;
$attr{global}{motd} .= "Running with root privileges."
if($^O !~ m/Win/ && $<==0 && $attr{global}{motd} =~ m/^$sc_text/);
$attr{global}{motd} .=
"\nRestart fhem for a new check if the problem is fixed,\n".
"\nRestart FHEM for a new check if the problem is fixed,\n".
"or set the global attribute motd to none to supress this message.\n"
if($attr{global}{motd} =~ m/^$sc_text\n\n./);
my $motd = $attr{global}{motd};
@ -2651,6 +2651,27 @@ GetTimeSpec($)
}
sub
deviceEvents($$)
{
my ($hash, $withState) = @_;
return undef if(!$hash || !$hash->{CHANGED});
if($withState) {
my $cws = $hash->{CHANGEDWITHSTATE};
if(defined($cws)){
if(int(@{$cws}) == 0) {
@{$cws} = @{$hash->{CHANGED}};
push @{$cws}, "state: $hash->{READINGS}{state}{VAL}"
if($hash->{READINGS} && $hash->{READINGS}{state});
}
return $cws;
}
}
return $hash->{CHANGED};
}
#####################################
# Do the notification
sub
@ -2739,7 +2760,10 @@ DoTrigger($$@)
$oldvalue{$dev}{TIME} = TimeNow();
$oldvalue{$dev}{VAL} = $hash->{STATE};
delete($hash->{CHANGED}) if(!defined($hash->{INTRIGGER}));
if(!defined($hash->{INTRIGGER})) {
delete($hash->{CHANGED});
delete($hash->{CHANGEDWITHSTATE});
}
Log 3, "NTFY return: $ret" if($ret);
@ -3559,7 +3583,10 @@ readingsEndUpdate($$)
if($dotrigger && $init_done) {
DoTrigger($name, undef, 0) if(!$readingsUpdateDelayTrigger);
} else {
delete($hash->{CHANGED}) if(!defined($hash->{INTRIGGER}));
if(!defined($hash->{INTRIGGER})) {
delete($hash->{CHANGED});
delete($hash->{CHANGEDWITHSTATE})
}
}
return undef;
@ -3636,7 +3663,10 @@ readingsBulkUpdate($$$@)
my $rv = "$reading: $value";
if($changed) {
$rv = "$value" if($reading eq "state");
if($reading eq "state") {
$rv = "$value";
$hash->{CHANGEDWITHSTATE} = [];
}
addEvent($hash, $rv);
}
return $rv;