mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +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:
parent
bd7da62b39
commit
a2c31e2202
@ -208,24 +208,13 @@ at_adjustAlign($$)
|
||||
{
|
||||
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);
|
||||
$tm =~ m/^(\+)?(\*({\d+})?)?(.*)$/;
|
||||
my ($rel, $rep, $cnt, $tspec) = ($1, $2, $3, $4);
|
||||
return "startTimes: $hash->{NAME} is not relative" if(!$rel);
|
||||
my (undef, $hr, $min, $sec, undef) = GetTimeSpec($tspec);
|
||||
|
||||
my $now = time();
|
||||
my $alTime = ($alHr*60+$alMin)*60+$alSec-fhemTzOffset($now);
|
||||
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);
|
||||
my ($err, $ttime) = computeAlignTime($tspec, $attrVal,$hash->{TRIGGERTIME});
|
||||
return "$hash->{NAME} $err" if($err);
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer($ttime, "at_Exec", $hash, 0);
|
||||
|
23
fhem/fhem.pl
23
fhem/fhem.pl
@ -5161,5 +5161,28 @@ makeReadingName($) # Convert non-valid characters to _
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user