2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-13 17:26:34 +00:00

Correct one-time relative at after reboot

git-svn-id: https://svn.fhem.de/fhem/trunk@1717 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2012-07-11 10:42:38 +00:00
parent 4f9946d45f
commit 5b651554ac
3 changed files with 39 additions and 3 deletions

View File

@ -53,6 +53,7 @@
- feature: motd with SecurityCheck added - feature: motd with SecurityCheck added
- feature: telnet module added, attr global port moved. allowfrom changed. - feature: telnet module added, attr global port moved. allowfrom changed.
- feature: FhemUtils/release.pm for the new update process added. (M. Fischer) - feature: FhemUtils/release.pm for the new update process added. (M. Fischer)
- bugfix: correct one-time relative at commands after reboot
- 2011-12-31 (5.2) - 2011-12-31 (5.2)
- bugfix: applying smallscreen attributes to firefox/opera - bugfix: applying smallscreen attributes to firefox/opera

View File

@ -15,6 +15,7 @@ at_Initialize($)
$hash->{DefFn} = "at_Define"; $hash->{DefFn} = "at_Define";
$hash->{UndefFn} = "at_Undef"; $hash->{UndefFn} = "at_Undef";
$hash->{AttrFn} = "at_Attr"; $hash->{AttrFn} = "at_Attr";
$hash->{StateFn} = "at_State";
$hash->{AttrList} = "disable:0,1 skip_next:0,1 loglevel:0,1,2,3,4,5,6 ". $hash->{AttrList} = "disable:0,1 skip_next:0,1 loglevel:0,1,2,3,4,5,6 ".
"alignTime"; "alignTime";
} }
@ -176,4 +177,31 @@ at_Attr(@)
return undef; return undef;
} }
#############
# Adjust one-time relative at's after reboot, the execution time is stored as
# state
sub
at_State($$$$)
{
my ($hash, $tim, $vt, $val) = @_;
return undef if($hash->{DEF} !~ m/^\+\d/ ||
$val !~ m/Next: (\d\d):(\d\d):(\d\d)/);
my ($h, $m, $s) = ($1, $2, $3);
my $then = ($h*60+$m)*60+$s;
my $now = time();
my @lt = localtime($now);
my $ntime = ($lt[2]*60+$lt[1])*60+$lt[0];
return undef if($ntime > $then);
my $name = $hash->{NAME};
RemoveInternalTimer($name);
InternalTimer($now+$then-$ntime, "at_Exec", $name, 0);
$hash->{NTM} = "$h:$m:$s";
$hash->{STATE} = $val;
return undef;
}
1; 1;

View File

@ -1746,7 +1746,6 @@ CommandSetstate($$)
my @a = split(" ", $param, 2); my @a = split(" ", $param, 2);
return "Usage: setstate <name> <state>\n$namedef" if(@a != 2); return "Usage: setstate <name> <state>\n$namedef" if(@a != 2);
my @rets; my @rets;
foreach my $sdev (devspec2array($a[0])) { foreach my $sdev (devspec2array($a[0])) {
if(!defined($defs{$sdev})) { if(!defined($defs{$sdev})) {
@ -1760,7 +1759,8 @@ CommandSetstate($$)
if($a[1] =~ m/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) +([^ ].*)$/) { if($a[1] =~ m/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) +([^ ].*)$/) {
my ($tim, $nameval) = ($1, $2); my ($tim, $nameval) = ($1, $2);
my ($sname, $sval) = split(" ", $nameval, 2); my ($sname, $sval) = split(" ", $nameval, 2);
(undef, $sval) = ReplaceEventMap($d, [$d, $sval], 0) if($attr{$d}{eventMap}); (undef, $sval) = ReplaceEventMap($sdev, [$sdev, $sval], 0)
if($attr{$sdev}{eventMap});
my $ret = CallFn($sdev, "StateFn", $d, $tim, $sname, $sval); my $ret = CallFn($sdev, "StateFn", $d, $tim, $sname, $sval);
if($ret) { if($ret) {
push @rets, $ret; push @rets, $ret;
@ -1779,9 +1779,16 @@ CommandSetstate($$)
# This time is not the correct one, but we do not store a timestamp for # This time is not the correct one, but we do not store a timestamp for
# this reading. # this reading.
$oldvalue{$sdev}{TIME} = TimeNow(); my $tn = TimeNow();
$oldvalue{$sdev}{TIME} = $tn;
$oldvalue{$sdev}{VAL} = $d->{STATE}; $oldvalue{$sdev}{VAL} = $d->{STATE};
my $ret = CallFn($sdev, "StateFn", $d, $tn, "STATE", $a[1]);
if($ret) {
push @rets, $ret;
next;
}
} }
} }
return join("\n", @rets); return join("\n", @rets);