2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 19:04:20 +00:00

Rename wont stop the timer

git-svn-id: https://svn.fhem.de/fhem/trunk@1892 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2012-09-27 07:08:41 +00:00
parent 1826e71fe5
commit 7c98c18027

View File

@ -32,7 +32,7 @@ at_Define($$)
if(!$command) { if(!$command) {
if($hash->{OLDDEF}) { # Called from modify, where command is optional if($hash->{OLDDEF}) { # Called from modify, where command is optional
RemoveInternalTimer($name); RemoveInternalTimer($hash);
(undef, $command) = split("[ \t]+", $hash->{OLDDEF}, 2); (undef, $command) = split("[ \t]+", $hash->{OLDDEF}, 2);
$hash->{DEF} = "$tm $command"; $hash->{DEF} = "$tm $command";
} else { } else {
@ -72,8 +72,8 @@ at_Define($$)
} }
$hash->{NTM} = $ntm if($rel eq "+" || $fn); $hash->{NTM} = $ntm if($rel eq "+" || $fn);
$hash->{TRIGGERTIME} = $nt; $hash->{TRIGGERTIME} = $nt;
RemoveInternalTimer($name); RemoveInternalTimer($hash);
InternalTimer($nt, "at_Exec", $name, 0); InternalTimer($nt, "at_Exec", $hash, 0);
$hash->{STATE} = ($oldattr && $oldattr->{disable} ? "disabled" : ("Next: ".FmtTime($nt))); $hash->{STATE} = ($oldattr && $oldattr->{disable} ? "disabled" : ("Next: ".FmtTime($nt)));
@ -84,18 +84,21 @@ sub
at_Undef($$) at_Undef($$)
{ {
my ($hash, $name) = @_; my ($hash, $name) = @_;
RemoveInternalTimer($name); $hash->{DELETED} = 1;
RemoveInternalTimer($hash);
return undef; return undef;
} }
sub sub
at_Exec($) at_Exec($)
{ {
my ($name) = @_; my ($hash) = @_;
my ($skip, $disable) = ("",""); my ($skip, $disable) = ("","");
return if(!$defs{$name}); # Just deleted return if($hash->{DELETED}); # Just deleted
Log GetLogLevel($name,5), "exec at command $name"; my $name = $hash->{NAME};
my $ll5 = GetLogLevel($name,5);
Log $ll5, "exec at command $name";
if(defined($attr{$name})) { if(defined($attr{$name})) {
$skip = 1 if($attr{$name} && $attr{$name}{skip_next}); $skip = 1 if($attr{$name} && $attr{$name}{skip_next});
@ -103,35 +106,35 @@ at_Exec($)
} }
delete $attr{$name}{skip_next} if($skip); delete $attr{$name}{skip_next} if($skip);
my (undef, $command) = split("[ \t]+", $defs{$name}{DEF}, 2); my (undef, $command) = split("[ \t]+", $hash->{DEF}, 2);
$command = SemicolonEscape($command); $command = SemicolonEscape($command);
my $ret = AnalyzeCommandChain(undef, $command) if(!$skip && !$disable); my $ret = AnalyzeCommandChain(undef, $command) if(!$skip && !$disable);
Log GetLogLevel($name,3), $ret if($ret); Log GetLogLevel($name,3), $ret if($ret);
return if(!$defs{$name}); # Deleted in the Command return if($hash->{DELETED}); # Deleted in the Command
my $count = $defs{$name}{REP}; my $count = $hash->{REP};
my $def = $defs{$name}{DEF}; my $def = $hash->{DEF};
$oldattr = $attr{$name}; # delete removes the attributes too $oldattr = $attr{$name}; # delete removes the attributes too
# Avoid drift when the timespec is relative # Avoid drift when the timespec is relative
$data{AT_TRIGGERTIME} = $defs{$name}{TRIGGERTIME} if($def =~ m/^\+/); $data{AT_TRIGGERTIME} = $hash->{TRIGGERTIME} if($def =~ m/^\+/);
my $oldCfgfn = $defs{$name}{CFGFN}; my $oldCfgfn = $hash->{CFGFN};
my $oldNr = $defs{$name}{NR}; my $oldNr = $hash->{NR};
CommandDelete(undef, $name); # Recreate ourselves CommandDelete(undef, $name); # Recreate ourselves
if($count) { if($count) {
$def =~ s/{\d+}/{$count}/ if($def =~ m/^\+?\*{\d+}/); # Replace the count $def =~ s/{\d+}/{$count}/ if($def =~ m/^\+?\*{\d+}/); # Replace the count
Log GetLogLevel($name,5), "redefine at command $name as $def"; Log $ll5, "redefine at command $name as $def";
$data{AT_RECOMPUTE} = 1; # Tell sunrise compute the next day $data{AT_RECOMPUTE} = 1; # Tell sunrise compute the next day
CommandDefine(undef, "$name at $def"); # Recompute the next TRIGGERTIME CommandDefine(undef, "$name at $def"); # Recompute the next TRIGGERTIME
delete($data{AT_RECOMPUTE}); delete($data{AT_RECOMPUTE});
$attr{$name} = $oldattr; $attr{$name} = $oldattr;
$defs{$name}{CFGFN} = $oldCfgfn if($oldCfgfn); $hash->{CFGFN} = $oldCfgfn if($oldCfgfn);
$defs{$name}{NR} = $oldNr; $hash->{NR} = $oldNr;
$oldattr = undef; $oldattr = undef;
} }
delete($data{AT_TRIGGERTIME}); delete($data{AT_TRIGGERTIME});
@ -143,12 +146,14 @@ at_Attr(@)
my ($cmd, $name, $attrName, $attrVal) = @_; my ($cmd, $name, $attrName, $attrVal) = @_;
my $do = 0; my $do = 0;
my $hash = $defs{$name};
if($cmd eq "set" && $attrName eq "alignTime") { if($cmd eq "set" && $attrName eq "alignTime") {
return "alignTime needs a list of timespec parameters" if(!$attrVal); return "alignTime needs a list of timespec parameters" if(!$attrVal);
my ($alErr, $alHr, $alMin, $alSec, undef) = GetTimeSpec($attrVal); my ($alErr, $alHr, $alMin, $alSec, undef) = GetTimeSpec($attrVal);
return "$name alignTime: $alErr" if($alErr); return "$name alignTime: $alErr" if($alErr);
my ($tm, $command) = split("[ \t]+", $defs{$name}{DEF}, 2); my ($tm, $command) = split("[ \t]+", $hash->{DEF}, 2);
$tm =~ m/^(\+)?(\*({\d+})?)?(.*)$/; $tm =~ m/^(\+)?(\*({\d+})?)?(.*)$/;
my ($rel, $rep, $cnt, $tspec) = ($1, $2, $3, $4); my ($rel, $rep, $cnt, $tspec) = ($1, $2, $3, $4);
return "startTimes: $name is not relative" if(!$rel); return "startTimes: $name is not relative" if(!$rel);
@ -156,7 +161,7 @@ at_Attr(@)
my $alTime = ($alHr*60+$alMin)*60+$alSec; my $alTime = ($alHr*60+$alMin)*60+$alSec;
my $step = ($hr*60+$min)*60+$sec; my $step = ($hr*60+$min)*60+$sec;
my $ttime = int($defs{$name}{TRIGGERTIME}); my $ttime = int($hash->{TRIGGERTIME});
my $off = ($ttime % 86400) - 86400; my $off = ($ttime % 86400) - 86400;
while($off < $alTime) { while($off < $alTime) {
$off += $step; $off += $step;
@ -164,10 +169,10 @@ at_Attr(@)
$ttime += ($alTime-$off); $ttime += ($alTime-$off);
$ttime += $step if($ttime < time()); $ttime += $step if($ttime < time());
RemoveInternalTimer($name); RemoveInternalTimer($hash);
InternalTimer($ttime, "at_Exec", $name, 0); InternalTimer($ttime, "at_Exec", $hash, 0);
$defs{$name}{TRIGGERTIME} = $ttime; $hash->{TRIGGERTIME} = $ttime;
$defs{$name}{STATE} = "Next: " . FmtTime($ttime); $hash->{STATE} = "Next: " . FmtTime($ttime);
} }
if($cmd eq "set" && $attrName eq "disable") { if($cmd eq "set" && $attrName eq "disable") {
@ -175,9 +180,9 @@ at_Attr(@)
} }
$do = 2 if($cmd eq "del" && (!$attrName || $attrName eq "disable")); $do = 2 if($cmd eq "del" && (!$attrName || $attrName eq "disable"));
return if(!$do); return if(!$do);
$defs{$name}{STATE} = ($do == 1 ? $hash->{STATE} = ($do == 1 ?
"disabled" : "disabled" :
"Next: " . FmtTime($defs{$name}{TRIGGERTIME})); "Next: " . FmtTime($hash->{TRIGGERTIME}));
return undef; return undef;
} }
@ -201,8 +206,8 @@ at_State($$$$)
return undef if($ntime > $then); return undef if($ntime > $then);
my $name = $hash->{NAME}; my $name = $hash->{NAME};
RemoveInternalTimer($name); RemoveInternalTimer($hash);
InternalTimer($now+$then-$ntime, "at_Exec", $name, 0); InternalTimer($now+$then-$ntime, "at_Exec", $hash, 0);
$hash->{NTM} = "$h:$m:$s"; $hash->{NTM} = "$h:$m:$s";
$hash->{STATE} = $val; $hash->{STATE} = $val;