mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-16 04:36:02 +00:00
91_watchdog.pm: add $DEV/$EVENT (Forum #121598)
git-svn-id: https://svn.fhem.de/fhem/trunk@24648 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
efd8c7319d
commit
078e57d7e6
@ -46,7 +46,7 @@ watchdog_Initialize($)
|
||||
($tTime && $tTime gt $aTime) ||
|
||||
time_str2num($aTime)+$wh->{TO} <= $now);
|
||||
my $remaining = time_str2num($aTime)+$wh->{TO};
|
||||
watchdog_Activate($wh, $remaining);
|
||||
watchdog_Activate($wh, undef, undef, $remaining);
|
||||
}
|
||||
}, 1) if(!$init_done);
|
||||
}
|
||||
@ -57,6 +57,10 @@ watchdog_reset($)
|
||||
my ($watchdog) = @_;
|
||||
$watchdog->{STATE} = "defined";
|
||||
setReadingsVal($watchdog, "Reset", "reset", TimeNow());
|
||||
if($watchdog->{READINGS}) {
|
||||
delete($watchdog->{READINGS}{triggeredByDev}) ;
|
||||
delete($watchdog->{READINGS}{triggeredByEvent}) ;
|
||||
}
|
||||
}
|
||||
|
||||
#####################################
|
||||
@ -99,7 +103,7 @@ watchdog_Define($$)
|
||||
$watchdog->{CMD} = $cmd;
|
||||
|
||||
if($re1 eq ".") {
|
||||
watchdog_Activate($watchdog)
|
||||
watchdog_Activate($watchdog);
|
||||
|
||||
} else {
|
||||
$watchdog->{STATE} = "defined"; # do not set the reading
|
||||
@ -154,7 +158,7 @@ watchdog_Notify($$)
|
||||
RemoveInternalTimer($watchdog);
|
||||
|
||||
if($re1 eq $re2 || $re1 eq "." || $re2act) {
|
||||
watchdog_Activate($watchdog);
|
||||
watchdog_Activate($watchdog, $n, $s);
|
||||
return "";
|
||||
|
||||
} else {
|
||||
@ -163,13 +167,13 @@ watchdog_Notify($$)
|
||||
}
|
||||
|
||||
} elsif($n =~ m/^$re1$/ || "$n:$s" =~ m/^$re1$/) {
|
||||
watchdog_Activate($watchdog) if(!$dontReAct);
|
||||
watchdog_Activate($watchdog, $n, $s) if(!$dontReAct);
|
||||
|
||||
}
|
||||
|
||||
} elsif($watchdog->{STATE} eq "defined") {
|
||||
if($dotTrigger || ($n =~ m/^$re1$/ || "$n:$s" =~ m/^$re1$/)) {
|
||||
watchdog_Activate($watchdog)
|
||||
watchdog_Activate($watchdog, $n, $s)
|
||||
}
|
||||
|
||||
} elsif($dotTrigger) {
|
||||
@ -193,11 +197,15 @@ watchdog_Trigger($)
|
||||
}
|
||||
|
||||
Log3 $name, 3, "Watchdog $name triggered";
|
||||
my $exec = SemicolonEscape($watchdog->{CMD});
|
||||
my %specials= (
|
||||
"%NAME" => ReadingsVal($name, "triggeredByDev", ""),
|
||||
"%EVENT" => ReadingsVal($name, "triggeredByEvent", "")
|
||||
);
|
||||
my $exec = EvalSpecials($watchdog->{CMD}, %specials);
|
||||
$watchdog->{STATE} = "triggered";
|
||||
|
||||
|
||||
setReadingsVal($watchdog, "Triggered", "triggered", TimeNow());
|
||||
|
||||
|
||||
my $ret = AnalyzeCommandChain(undef, $exec);
|
||||
Log3 $name, 3, $ret if($ret);
|
||||
|
||||
@ -207,14 +215,19 @@ watchdog_Trigger($)
|
||||
}
|
||||
|
||||
sub
|
||||
watchdog_Activate($;$)
|
||||
watchdog_Activate($;$$$)
|
||||
{
|
||||
my ($watchdog, $remaining) = @_;
|
||||
my $nt = ($remaining ? $remaining : gettimeofday() + $watchdog->{TO});
|
||||
my ($watchdog, $dev, $event, $remaining) = @_;
|
||||
my $now = gettimeofday();
|
||||
my $nt = ($remaining ? $remaining : $now + $watchdog->{TO});
|
||||
$watchdog->{STATE} = "Next: " . FmtTime($nt);
|
||||
RemoveInternalTimer($watchdog);
|
||||
InternalTimer($nt, "watchdog_Trigger", $watchdog, 0);
|
||||
|
||||
my $fmtNow = FmtDateTime($now);
|
||||
setReadingsVal($watchdog, "triggeredByDev", $dev, $fmtNow) if($dev);
|
||||
setReadingsVal($watchdog, "triggeredByEvent", $event, $fmtNow) if($event);
|
||||
|
||||
my $eor = AttrVal($watchdog->{NAME}, "execOnReactivate", undef);
|
||||
if($eor) {
|
||||
my $wName = $watchdog->{NAME};
|
||||
@ -346,6 +359,8 @@ watchdog_Set($@)
|
||||
currently not possible.</li>
|
||||
<li>with modify all parameters are optional, and will not be changed if
|
||||
not specified.</li>
|
||||
<li>the device and the event triggering the watchdog is available as $DEV
|
||||
and $EVENT in the executable.</li>
|
||||
</ul>
|
||||
|
||||
<br>
|
||||
@ -487,6 +502,9 @@ watchdog_Set($@)
|
||||
<li>Bei modify sind alle Parameter optional, und werden nicht geaendert,
|
||||
falls nicht spezifiziert.</li>
|
||||
|
||||
<li>Das aktivierende Gerät und Event sind al $DEV und $EVENT im
|
||||
ausführenden Teil verfügbar.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<br>
|
||||
|
Loading…
x
Reference in New Issue
Block a user