2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

fhem.pl: add computeAlignTime (Forum #75976)

git-svn-id: https://svn.fhem.de/fhem/trunk@14995 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-09-03 14:23:14 +00:00
parent bd7da62b39
commit a2c31e2202
2 changed files with 25 additions and 13 deletions

View File

@ -208,24 +208,13 @@ at_adjustAlign($$)
{ {
my($hash, $attrVal) = @_; my($hash, $attrVal) = @_;
my ($alErr, $alHr, $alMin, $alSec, undef) = GetTimeSpec($attrVal);
return "$hash->{NAME} alignTime: $alErr" if($alErr);
my ($tm, $command) = split("[ \t]+", $hash->{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: $hash->{NAME} is not relative" if(!$rel); return "startTimes: $hash->{NAME} is not relative" if(!$rel);
my (undef, $hr, $min, $sec, undef) = GetTimeSpec($tspec);
my $now = time(); my ($err, $ttime) = computeAlignTime($tspec, $attrVal,$hash->{TRIGGERTIME});
my $alTime = ($alHr*60+$alMin)*60+$alSec-fhemTzOffset($now); return "$hash->{NAME} $err" if($err);
my $step = ($hr*60+$min)*60+$sec;
my $ttime = int($hash->{TRIGGERTIME});
my $off = ($ttime % 86400) - 86400;
while($off < $alTime) {
$off += $step;
}
$ttime += ($alTime-$off);
$ttime += $step if($ttime < $now);
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
InternalTimer($ttime, "at_Exec", $hash, 0); InternalTimer($ttime, "at_Exec", $hash, 0);

View File

@ -5161,5 +5161,28 @@ makeReadingName($) # Convert non-valid characters to _
return $name; return $name;
} }
sub
computeAlignTime($$@)
{
my ($timeSpec, $alignSpec, $triggertime) = @_; # triggertime is now if absent
my ($alErr, $alHr, $alMin, $alSec, undef) = GetTimeSpec($alignSpec);
return ("alignTime: $alErr", undef) if($alErr);
my ($tmErr, $hr, $min, $sec, undef) = GetTimeSpec($timeSpec);
return ("timeSpec: $tmErr", undef) if($alErr);
my $now = time();
my $alTime = ($alHr*60+$alMin)*60+$alSec-fhemTzOffset($now);
my $step = ($hr*60+$min)*60+$sec;
my $ttime = ($triggertime ? int($triggertime) : $now);
my $off = ($ttime % 86400) - 86400;
while($off < $alTime) {
$off += $step;
}
$ttime += ($alTime-$off);
$ttime += $step if($ttime < $now);
return (undef, $ttime);
}
1; 1;