mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-21 20:06:18 +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) ||
|
($tTime && $tTime gt $aTime) ||
|
||||||
time_str2num($aTime)+$wh->{TO} <= $now);
|
time_str2num($aTime)+$wh->{TO} <= $now);
|
||||||
my $remaining = time_str2num($aTime)+$wh->{TO};
|
my $remaining = time_str2num($aTime)+$wh->{TO};
|
||||||
watchdog_Activate($wh, $remaining);
|
watchdog_Activate($wh, undef, undef, $remaining);
|
||||||
}
|
}
|
||||||
}, 1) if(!$init_done);
|
}, 1) if(!$init_done);
|
||||||
}
|
}
|
||||||
@ -57,6 +57,10 @@ watchdog_reset($)
|
|||||||
my ($watchdog) = @_;
|
my ($watchdog) = @_;
|
||||||
$watchdog->{STATE} = "defined";
|
$watchdog->{STATE} = "defined";
|
||||||
setReadingsVal($watchdog, "Reset", "reset", TimeNow());
|
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;
|
$watchdog->{CMD} = $cmd;
|
||||||
|
|
||||||
if($re1 eq ".") {
|
if($re1 eq ".") {
|
||||||
watchdog_Activate($watchdog)
|
watchdog_Activate($watchdog);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$watchdog->{STATE} = "defined"; # do not set the reading
|
$watchdog->{STATE} = "defined"; # do not set the reading
|
||||||
@ -154,7 +158,7 @@ watchdog_Notify($$)
|
|||||||
RemoveInternalTimer($watchdog);
|
RemoveInternalTimer($watchdog);
|
||||||
|
|
||||||
if($re1 eq $re2 || $re1 eq "." || $re2act) {
|
if($re1 eq $re2 || $re1 eq "." || $re2act) {
|
||||||
watchdog_Activate($watchdog);
|
watchdog_Activate($watchdog, $n, $s);
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -163,13 +167,13 @@ watchdog_Notify($$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} elsif($n =~ m/^$re1$/ || "$n:$s" =~ m/^$re1$/) {
|
} 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") {
|
} elsif($watchdog->{STATE} eq "defined") {
|
||||||
if($dotTrigger || ($n =~ m/^$re1$/ || "$n:$s" =~ m/^$re1$/)) {
|
if($dotTrigger || ($n =~ m/^$re1$/ || "$n:$s" =~ m/^$re1$/)) {
|
||||||
watchdog_Activate($watchdog)
|
watchdog_Activate($watchdog, $n, $s)
|
||||||
}
|
}
|
||||||
|
|
||||||
} elsif($dotTrigger) {
|
} elsif($dotTrigger) {
|
||||||
@ -193,7 +197,11 @@ watchdog_Trigger($)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log3 $name, 3, "Watchdog $name triggered";
|
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";
|
$watchdog->{STATE} = "triggered";
|
||||||
|
|
||||||
setReadingsVal($watchdog, "Triggered", "triggered", TimeNow());
|
setReadingsVal($watchdog, "Triggered", "triggered", TimeNow());
|
||||||
@ -207,14 +215,19 @@ watchdog_Trigger($)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
watchdog_Activate($;$)
|
watchdog_Activate($;$$$)
|
||||||
{
|
{
|
||||||
my ($watchdog, $remaining) = @_;
|
my ($watchdog, $dev, $event, $remaining) = @_;
|
||||||
my $nt = ($remaining ? $remaining : gettimeofday() + $watchdog->{TO});
|
my $now = gettimeofday();
|
||||||
|
my $nt = ($remaining ? $remaining : $now + $watchdog->{TO});
|
||||||
$watchdog->{STATE} = "Next: " . FmtTime($nt);
|
$watchdog->{STATE} = "Next: " . FmtTime($nt);
|
||||||
RemoveInternalTimer($watchdog);
|
RemoveInternalTimer($watchdog);
|
||||||
InternalTimer($nt, "watchdog_Trigger", $watchdog, 0);
|
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);
|
my $eor = AttrVal($watchdog->{NAME}, "execOnReactivate", undef);
|
||||||
if($eor) {
|
if($eor) {
|
||||||
my $wName = $watchdog->{NAME};
|
my $wName = $watchdog->{NAME};
|
||||||
@ -346,6 +359,8 @@ watchdog_Set($@)
|
|||||||
currently not possible.</li>
|
currently not possible.</li>
|
||||||
<li>with modify all parameters are optional, and will not be changed if
|
<li>with modify all parameters are optional, and will not be changed if
|
||||||
not specified.</li>
|
not specified.</li>
|
||||||
|
<li>the device and the event triggering the watchdog is available as $DEV
|
||||||
|
and $EVENT in the executable.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
@ -487,6 +502,9 @@ watchdog_Set($@)
|
|||||||
<li>Bei modify sind alle Parameter optional, und werden nicht geaendert,
|
<li>Bei modify sind alle Parameter optional, und werden nicht geaendert,
|
||||||
falls nicht spezifiziert.</li>
|
falls nicht spezifiziert.</li>
|
||||||
|
|
||||||
|
<li>Das aktivierende Gerät und Event sind al $DEV und $EVENT im
|
||||||
|
ausführenden Teil verfügbar.</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user