mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-16 16:56:04 +00:00
91_watchdog.pm: add activateOnStart attribute (Forum #89173)
git-svn-id: https://svn.fhem.de/fhem/trunk@16960 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a3140390f8
commit
4b5bad61ad
@ -17,9 +17,35 @@ watchdog_Initialize($)
|
||||
$hash->{AttrFn} = "watchdog_Attr";
|
||||
$hash->{SetFn} = "watchdog_Set";
|
||||
$hash->{NotifyFn} = "watchdog_Notify";
|
||||
$hash->{AttrList} = "disable:0,1 disabledForIntervals execOnReactivate ".
|
||||
"regexp1WontReactivate:0,1 addStateEvent:0,1 ".
|
||||
"autoRestart:0,1";
|
||||
no warnings 'qw';
|
||||
my @attrList = qw(
|
||||
activateOnStart:0,1
|
||||
addStateEvent:0,1
|
||||
autoRestart:0,1
|
||||
disable:0,1
|
||||
disabledForIntervals
|
||||
execOnReactivate
|
||||
regexp1WontReactivate:0,1
|
||||
);
|
||||
use warnings 'qw';
|
||||
$hash->{AttrList} = join(" ", @attrList);
|
||||
|
||||
# acivateOnStart handling
|
||||
InternalTimer(1, sub() {
|
||||
my @arr = devspec2array("TYPE=watchdog");
|
||||
my $now = time();
|
||||
foreach my $wd (@arr) {
|
||||
next if(!AttrVal($wd, "activateOnStart", 0));
|
||||
my $wh = $defs{$wd};
|
||||
my $aTime = ReadingsTimestamp($wd, "Activated", undef);
|
||||
my $tTime = ReadingsTimestamp($wd, "Triggered", undef);
|
||||
next if(!$aTime ||
|
||||
($tTime && $tTime gt $aTime) ||
|
||||
time_str2num($aTime)+$wh->{TO} <= $now);
|
||||
my $remaining = time_str2num($aTime)+$wh->{TO};
|
||||
watchdog_Activate($wh, $remaining);
|
||||
}
|
||||
}, 1) if(!$init_done);
|
||||
}
|
||||
|
||||
|
||||
@ -169,10 +195,10 @@ watchdog_Trigger($)
|
||||
}
|
||||
|
||||
sub
|
||||
watchdog_Activate($)
|
||||
watchdog_Activate($;$)
|
||||
{
|
||||
my ($watchdog) = @_;
|
||||
my $nt = gettimeofday() + $watchdog->{TO};
|
||||
my ($watchdog, $remaining) = @_;
|
||||
my $nt = ($remaining ? $remaining : gettimeofday() + $watchdog->{TO});
|
||||
$watchdog->{STATE} = "Next: " . FmtTime($nt);
|
||||
RemoveInternalTimer($watchdog);
|
||||
InternalTimer($nt, "watchdog_Trigger", $watchdog, 0);
|
||||
@ -184,7 +210,7 @@ watchdog_Activate($)
|
||||
my $tTime = ReadingsTimestamp($wName, "Triggered", "");
|
||||
$eor = undef if(!$aTime || !$tTime || $aTime ge $tTime)
|
||||
}
|
||||
setReadingsVal($watchdog, "Activated", "activated", TimeNow());
|
||||
setReadingsVal($watchdog, "Activated","activated", TimeNow()) if(!$remaining);
|
||||
|
||||
AnalyzeCommandChain(undef, SemicolonEscape($eor)) if($eor);
|
||||
}
|
||||
@ -334,6 +360,14 @@ watchdog_Set($@)
|
||||
<a name="watchdogattr"></a>
|
||||
<b>Attributes</b>
|
||||
<ul>
|
||||
<li><a name="#activateOnStart">activateOnStart</a><br>
|
||||
if set, the watchdog will be activated after a FHEM start if appropriate,
|
||||
determined by the Timestamp of the Activated and the Triggered readings.
|
||||
Note: since between shutdown and startup events may be missed, this
|
||||
attribute is 0 (disabled) by default.
|
||||
</li>
|
||||
|
||||
<li><a href="#addStateEvent">addStateEvent</a></li>
|
||||
<li><a href="#disable">disable</a></li>
|
||||
<li><a href="#disabledForIntervals">disabledForIntervals</a></li>
|
||||
|
||||
@ -461,6 +495,14 @@ watchdog_Set($@)
|
||||
<a name="watchdogattr"></a>
|
||||
<b>Attribute</b>
|
||||
<ul>
|
||||
<li><a name="#activateOnStart">activateOnStart</a><br>
|
||||
Falls gesetzt, wird der Watchdog nach FHEM-Neustart aktiviert, je nach
|
||||
Zeitstempel der Activated und Triggered Readings. Da zwischen Shutdown
|
||||
und Neustart Events verlorengehen können, ist die Voreinstellung 0
|
||||
(deaktiviert).
|
||||
</li>
|
||||
|
||||
|
||||
<li><a href="#addStateEvent">addStateEvent</a></li>
|
||||
<li><a href="#disable">disable</a></li>
|
||||
<li><a href="#disabledForIntervals">disabledForIntervals</a></li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user