mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +00:00
98_RandomTimer.pm: Add perl syntax check to disableCond attribute; remove unused function; perltidy patch
git-svn-id: https://svn.fhem.de/fhem/trunk@21983 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a885bfe86d
commit
cef7607065
@ -1,5 +1,6 @@
|
||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||
# Do not insert empty lines here, update check depends on it.
|
||||
- feature: 98_RandomTimer: Add perlSyntaxCheck to condition attribute
|
||||
- bugfix: dashboard.js: Dashboard no longer requires dummy readingsgroup
|
||||
- feature: 72_XiaomiDevice: new device SmartFan1X, S5 Max vacuum water box
|
||||
- feature: 48_BlinkCamera: Support for BlinkMini - en/disable + thumbnail
|
||||
|
@ -30,7 +30,7 @@ use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
use Time::Local 'timelocal_nocheck';
|
||||
use Time::Local qw(timelocal_nocheck);
|
||||
use List::Util qw(max);
|
||||
use GPUtils qw(GP_Import GP_Export);
|
||||
|
||||
@ -60,6 +60,7 @@ BEGIN {
|
||||
CommandDeleteAttr
|
||||
AnalyzeCommandChain
|
||||
AnalyzePerlCommand
|
||||
perlSyntaxCheck
|
||||
SemicolonEscape
|
||||
FmtDateTime
|
||||
strftime
|
||||
@ -68,25 +69,19 @@ BEGIN {
|
||||
);
|
||||
}
|
||||
|
||||
#-- Export to main context with different name
|
||||
# use this feature with care!
|
||||
GP_Export(
|
||||
qw(
|
||||
Initialize
|
||||
)
|
||||
);
|
||||
sub main::RandomTimer_Initialize { goto &Initialize }
|
||||
|
||||
# initialize ##################################################################
|
||||
sub Initialize {
|
||||
my $hash = shift;
|
||||
my $hash = shift // return;
|
||||
|
||||
$hash->{DefFn} = \&Define;
|
||||
$hash->{UndefFn} = \&Undef;
|
||||
$hash->{SetFn} = \&Set;
|
||||
$hash->{AttrFn} = \&Attr;
|
||||
$hash->{AttrList} = "onCmd offCmd switchmode disable:0,1 disableCond disableCondCmd:none,offCmd,onCmd offState ".
|
||||
"runonce:0,1 keepDeviceAlive:0,1 forceStoptimeSameDay:0,1 disabledForIntervals ".
|
||||
$readingFnAttributes;
|
||||
$hash->{AttrList} = "onCmd offCmd switchmode disable:0,1 disableCond disableCondCmd:none,offCmd,onCmd offState "
|
||||
. "runonce:0,1 keepDeviceAlive:0,1 forceStoptimeSameDay:0,1 disabledForIntervals "
|
||||
. $readingFnAttributes;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -96,8 +91,9 @@ sub Define {
|
||||
my $def = shift // return;
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
my ($name, $type, $timespec_start, $device, $timespec_stop, $timeToSwitch, $variation) =
|
||||
split m{\s+}xms, $def;
|
||||
my ( $name, $type, $timespec_start, $device, $timespec_stop, $timeToSwitch,
|
||||
$variation )
|
||||
= split m{\s+}xms, $def;
|
||||
|
||||
return "wrong syntax: define <name> RandomTimer <timespec_start> <device> <timespec_stop> <timeToSwitch> [<variations>]"
|
||||
if ( !defined $timeToSwitch );
|
||||
@ -107,7 +103,8 @@ sub Define {
|
||||
$rel = $1;
|
||||
$rep = $2;
|
||||
$tspec = $3;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return qq{ "Wrong timespec_start <$timespec_start>, use "[+][*]<time or func>" };
|
||||
}
|
||||
|
||||
@ -122,8 +119,10 @@ sub Define {
|
||||
$srel = $1;
|
||||
$srep = $2;
|
||||
$stspec = $3;
|
||||
} else {
|
||||
return qq{"Wrong timespec_stop <$timespec_stop>, use "[+][*]<time or func>"};
|
||||
}
|
||||
else {
|
||||
return
|
||||
qq{"Wrong timespec_stop <$timespec_stop>, use "[+][*]<time or func>"};
|
||||
}
|
||||
|
||||
my ( $e, $h, $m, $s, $f ) = GetTimeSpec($stspec);
|
||||
@ -138,7 +137,8 @@ sub Define {
|
||||
$variation =~ m{^([\d]+)}xms ? $varDuration = $1 : undef;
|
||||
$variation =~ m{[:]([\d]+)}xms ? $varStart = $1 : undef;
|
||||
}
|
||||
setSwitchmode ($hash, "800/200") if (!defined $hash->{helper}{SWITCHMODE});
|
||||
setSwitchmode( $hash, "800/200" )
|
||||
if ( !defined $hash->{helper}{SWITCHMODE} );
|
||||
|
||||
$hash->{NAME} = $name;
|
||||
$hash->{DEVICE} = $device;
|
||||
@ -158,9 +158,9 @@ sub Define {
|
||||
$hash->{helper}{offRegex} = "off";
|
||||
$hash->{helper}{offReading} = "state";
|
||||
}
|
||||
#$attr{$name}{verbose} = 4;
|
||||
|
||||
readingsSingleUpdate ($hash, "TimeToSwitch", $hash->{helper}{TIMETOSWITCH}, 1);
|
||||
readingsSingleUpdate( $hash, "TimeToSwitch", $hash->{helper}{TIMETOSWITCH},
|
||||
1 );
|
||||
|
||||
RmInternalTimer( "SetTimer", $hash );
|
||||
MkInternalTimer( "SetTimer", time(), \&SetTimer, $hash, 0 );
|
||||
@ -188,6 +188,7 @@ sub Attr {
|
||||
}
|
||||
|
||||
if ( $attrName =~ m{\A disable(Cond)? \z}xms ) {
|
||||
|
||||
# Immediately execute next switch check
|
||||
RmInternalTimer( "Exec", $hash );
|
||||
MkInternalTimer( "Exec", time() + 1, \&Exec, $hash, 0 );
|
||||
@ -199,15 +200,22 @@ sub Attr {
|
||||
$hash->{helper}{offReading} = $offReading // 'state';
|
||||
}
|
||||
|
||||
return;
|
||||
if ( $attrName eq 'disableCond' ) {
|
||||
if( $cmd eq "set" ) {
|
||||
my $err = perlSyntaxCheck($attrVal);
|
||||
return $err if ( $err );
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Set {
|
||||
my ( $hash, @a ) = @_;
|
||||
|
||||
return "no set value specified" if ( int(@a) < 2 );
|
||||
return "Unknown argument $a[1], choose one of execNow:noArg active:noArg inactive:noArg" if($a[1] eq "?");
|
||||
return "Unknown argument $a[1], choose one of execNow:noArg active:noArg inactive:noArg"
|
||||
if ( $a[1] eq "?" );
|
||||
|
||||
my $name = shift @a;
|
||||
my $v = join( " ", @a );
|
||||
@ -216,7 +224,8 @@ sub Set {
|
||||
Log3( $hash, 3, "[$name] set $name $v" );
|
||||
if ( AttrVal( $name, "disable", 0 ) ) {
|
||||
Log3( $hash, 3, "[$name] is disabled, set execNow not possible" );
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
RmInternalTimer( "Exec", $hash );
|
||||
MkInternalTimer( "Exec", time() + 1, \&Exec, $hash, 0 );
|
||||
}
|
||||
@ -236,7 +245,6 @@ sub Set {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
# module Fn ###################################################################
|
||||
sub addDays {
|
||||
my $now = shift;
|
||||
@ -256,16 +264,18 @@ sub device_switch {
|
||||
my $command = "set @ $hash->{COMMAND}";
|
||||
if ( $hash->{COMMAND} eq "on" ) {
|
||||
$command = AttrVal( $hash->{NAME}, "onCmd", $command );
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$command = AttrVal( $hash->{NAME}, "offCmd", $command );
|
||||
}
|
||||
$command =~ s/@/$hash->{DEVICE}/gxms;
|
||||
$command = SemicolonEscape($command);
|
||||
readingsSingleUpdate( $hash, 'LastCommand', $command, 1 );
|
||||
Log3 $hash, 4, "[".$hash->{NAME}. "]"." command: $command";
|
||||
Log3( $hash, 4, "[" . $hash->{NAME} . "]" . " command: $command" );
|
||||
|
||||
my $ret = AnalyzeCommandChain( undef, $command );
|
||||
Log3 ($hash, 3, "[$hash->{NAME}] ERROR: " . $ret . " SENDING " . $command) if($ret);
|
||||
Log3( $hash, 3, "[$hash->{NAME}] ERROR: " . $ret . " SENDING " . $command )
|
||||
if ($ret);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -273,29 +283,34 @@ sub device_switch {
|
||||
sub device_toggle {
|
||||
my $hash = shift // return;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
#my $attrOffState = AttrVal($name,"offState",undef);
|
||||
my $status = Value( $hash->{DEVICE} );
|
||||
|
||||
if ( defined $hash->{helper}{offRegex} ) {
|
||||
$status = ReadingsVal($hash->{DEVICE},$hash->{helper}{offReading},"off");
|
||||
$status =
|
||||
ReadingsVal( $hash->{DEVICE}, $hash->{helper}{offReading}, "off" );
|
||||
my $attrOffState = $hash->{helper}{offRegex};
|
||||
$status = $status =~ m{^$attrOffState$}xms ? "off" : lc($status);
|
||||
$status = $status =~ m{off}xms ? "off" : "on";
|
||||
}
|
||||
if ( $status ne "on" && $status ne "off" ) {
|
||||
if ( $hash->{helper}{offRegex} ) {
|
||||
Log3 $hash, 3, "[$name] result of function ReadingsVal($hash->{DEVICE},\"<offReading>\",undef) must be 'on' or 'off' or set attribute offState accordingly";
|
||||
} else {
|
||||
Log3 $hash, 3, "[$name] result of function Value($hash->{DEVICE}) must be 'on' or 'off'";;
|
||||
Log3( $hash, 3, "[$name] result of function ReadingsVal($hash->{DEVICE},\"<offReading>\",undef) must be 'on' or 'off' or set attribute offState accordingly" );
|
||||
}
|
||||
else {
|
||||
Log3 ( $hash, 3, "[$name] result of function Value($hash->{DEVICE}) must be 'on' or 'off'" );
|
||||
}
|
||||
}
|
||||
|
||||
my $sigma = ($status eq "on")
|
||||
my $sigma =
|
||||
( $status eq "on" )
|
||||
? $hash->{helper}{SIGMAWHENON}
|
||||
: $hash->{helper}{SIGMAWHENOFF};
|
||||
|
||||
my $zufall = int( rand(1000) );
|
||||
Log3 $hash, 4, "[$name] IstZustand:$status sigmaWhen-$status:$sigma random:$zufall<$sigma=>" . (($zufall < $sigma)?"true":"false");
|
||||
Log3( $hash, 4, "[$name] IstZustand:$status sigmaWhen-$status:$sigma random:$zufall<$sigma=>"
|
||||
. ( ( $zufall < $sigma ) ? "true" : "false" ) );
|
||||
|
||||
if ( $zufall < $sigma ) {
|
||||
$hash->{COMMAND} = ( $status eq "on" ) ? "off" : "on";
|
||||
@ -309,24 +324,37 @@ sub disableDown {
|
||||
my $disableCondCmd = AttrVal( $hash->{NAME}, "disableCondCmd", 0 );
|
||||
|
||||
if ( $disableCondCmd ne "none" ) {
|
||||
Log3 $hash, 4, "[".$hash->{NAME}."]"." setting requested disableCondCmd on $hash->{DEVICE}: ";
|
||||
$hash->{COMMAND} = AttrVal($hash->{NAME}, "disableCondCmd", 0) eq "onCmd" ? "on" : "off";
|
||||
Log3( $hash, 4,
|
||||
"["
|
||||
. $hash->{NAME} . "]"
|
||||
. " setting requested disableCondCmd on $hash->{DEVICE}: " );
|
||||
$hash->{COMMAND} =
|
||||
AttrVal( $hash->{NAME}, "disableCondCmd", 0 ) eq "onCmd"
|
||||
? "on"
|
||||
: "off";
|
||||
device_switch($hash);
|
||||
} else {
|
||||
Log3 $hash, 4, "[".$hash->{NAME}."]"." no action requested on $hash->{DEVICE}: ";
|
||||
}
|
||||
else {
|
||||
Log3( $hash, 4,
|
||||
"["
|
||||
. $hash->{NAME} . "]"
|
||||
. " no action requested on $hash->{DEVICE}: " );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub down {
|
||||
my $hash = shift // return;
|
||||
Log3 $hash, 4, "[".$hash->{NAME}."]"." setting requested keepDeviceAlive on $hash->{DEVICE}: ";
|
||||
$hash->{COMMAND} = AttrVal($hash->{NAME}, "keepDeviceAlive", 0) ? "on" : "off";
|
||||
Log3( $hash, 4,
|
||||
"["
|
||||
. $hash->{NAME} . "]"
|
||||
. " setting requested keepDeviceAlive on $hash->{DEVICE}: " );
|
||||
$hash->{COMMAND} =
|
||||
AttrVal( $hash->{NAME}, "keepDeviceAlive", 0 ) ? "on" : "off";
|
||||
device_switch($hash);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sub Exec {
|
||||
my $myHash = shift // return;
|
||||
|
||||
@ -341,61 +369,95 @@ sub Exec {
|
||||
my $stopTimeReached = stopTimeReached($hash);
|
||||
|
||||
if ($active) {
|
||||
|
||||
# wenn temporär ausgeschaltet
|
||||
if ($disabled) {
|
||||
Log3 $hash, 3, "[".$hash->{NAME}."]"." disabled before stop-time , ending RandomTimer on $hash->{DEVICE}: "
|
||||
. strftime("%H:%M:%S(%d)",localtime($hash->{helper}{startTime})) . " - "
|
||||
. strftime("%H:%M:%S(%d)",localtime($hash->{helper}{stopTime}));
|
||||
Log3( $hash, 3,
|
||||
"["
|
||||
. $hash->{NAME} . "]"
|
||||
. " disabled before stop-time , ending RandomTimer on $hash->{DEVICE}: "
|
||||
. strftime( "%H:%M:%S(%d)",
|
||||
localtime( $hash->{helper}{startTime} ) )
|
||||
. " - "
|
||||
. strftime( "%H:%M:%S(%d)",
|
||||
localtime( $hash->{helper}{stopTime} ) ) );
|
||||
disableDown($hash);
|
||||
setActive( $hash, 0 );
|
||||
setState($hash);
|
||||
}
|
||||
|
||||
# Wenn aktiv und Abschaltzeit erreicht, dann Gerät ausschalten, Meldung ausgeben und Timer schließen
|
||||
if ($stopTimeReached) {
|
||||
Log3 $hash, 3, "[".$hash->{NAME}."]"." stop-time reached, ending RandomTimer on $hash->{DEVICE}: "
|
||||
. strftime("%H:%M:%S(%d)",localtime($hash->{helper}{startTime})) . " - "
|
||||
. strftime("%H:%M:%S(%d)",localtime($hash->{helper}{stopTime}));
|
||||
Log3( $hash, 3,
|
||||
"["
|
||||
. $hash->{NAME} . "]"
|
||||
. " stop-time reached, ending RandomTimer on $hash->{DEVICE}: "
|
||||
. strftime( "%H:%M:%S(%d)",
|
||||
localtime( $hash->{helper}{startTime} ) )
|
||||
. " - "
|
||||
. strftime( "%H:%M:%S(%d)",
|
||||
localtime( $hash->{helper}{stopTime} ) ) );
|
||||
down($hash);
|
||||
setActive( $hash, 0 );
|
||||
if ( AttrVal( $hash->{NAME}, "runonce", -1 ) eq "1" ) {
|
||||
Log3 $hash, 3, "[".$hash->{NAME}. "]" ."runonceMode";
|
||||
Log3( $hash, 3, "[" . $hash->{NAME} . "]" . "runonceMode" );
|
||||
fhem("delete $hash->{NAME}");
|
||||
}
|
||||
setState($hash);
|
||||
return;
|
||||
}
|
||||
} else { # !active
|
||||
}
|
||||
else { # !active
|
||||
if ($disabled) {
|
||||
Log3 $hash, 4, "[".$hash->{NAME}. "] RandomTimer on $hash->{DEVICE} timer disabled - no switch";
|
||||
Log3( $hash, 4,
|
||||
"["
|
||||
. $hash->{NAME}
|
||||
. "] RandomTimer on $hash->{DEVICE} timer disabled - no switch" );
|
||||
setState($hash);
|
||||
setActive( $hash, 0 );
|
||||
}
|
||||
if ($stopTimeReached) {
|
||||
Log3 $hash, 4, "[".$hash->{NAME}."]"." definition RandomTimer on $hash->{DEVICE}: "
|
||||
. strftime("%H:%M:%S(%d)",localtime($hash->{helper}{startTime})) . " - "
|
||||
. strftime("%H:%M:%S(%d)",localtime($hash->{helper}{stopTime}));
|
||||
Log3( $hash, 4,
|
||||
"["
|
||||
. $hash->{NAME} . "]"
|
||||
. " definition RandomTimer on $hash->{DEVICE}: "
|
||||
. strftime( "%H:%M:%S(%d)",
|
||||
localtime( $hash->{helper}{startTime} ) )
|
||||
. " - "
|
||||
. strftime( "%H:%M:%S(%d)",
|
||||
localtime( $hash->{helper}{stopTime} ) ) );
|
||||
setState($hash);
|
||||
setActive( $hash, 0 );
|
||||
return;
|
||||
}
|
||||
if ( !$disabled ) {
|
||||
if ($now>$hash->{helper}{startTime} && $now<$hash->{helper}{stopTime}) {
|
||||
Log3 $hash, 3, "[".$hash->{NAME}."]"." starting RandomTimer on $hash->{DEVICE}: "
|
||||
. strftime("%H:%M:%S(%d)",localtime($hash->{helper}{startTime})) . " - "
|
||||
. strftime("%H:%M:%S(%d)",localtime($hash->{helper}{stopTime}));
|
||||
if ( $now > $hash->{helper}{startTime}
|
||||
&& $now < $hash->{helper}{stopTime} )
|
||||
{
|
||||
Log3( $hash, 3,
|
||||
"["
|
||||
. $hash->{NAME} . "]"
|
||||
. " starting RandomTimer on $hash->{DEVICE}: "
|
||||
. strftime( "%H:%M:%S(%d)",
|
||||
localtime( $hash->{helper}{startTime} ) )
|
||||
. " - "
|
||||
. strftime( "%H:%M:%S(%d)",
|
||||
localtime( $hash->{helper}{stopTime} ) ) );
|
||||
setActive( $hash, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setState($hash);
|
||||
if ($now>$hash->{helper}{startTime} && $now<$hash->{helper}{stopTime}) {
|
||||
if ( $now > $hash->{helper}{startTime} && $now < $hash->{helper}{stopTime} )
|
||||
{
|
||||
device_toggle($hash) if ( !$disabled );
|
||||
}
|
||||
|
||||
my $nextSwitch = time() + getSecsToNextAbschaltTest($hash);
|
||||
RmInternalTimer( "Exec", $hash );
|
||||
$hash->{helper}{NEXT_CHECK} = strftime("%d.%m.%Y %H:%M:%S",localtime($nextSwitch));
|
||||
$hash->{helper}{NEXT_CHECK} =
|
||||
strftime( "%d.%m.%Y %H:%M:%S", localtime($nextSwitch) );
|
||||
MkInternalTimer( "Exec", $nextSwitch, \&Exec, $hash, 0 );
|
||||
return;
|
||||
}
|
||||
@ -421,7 +483,8 @@ sub isAktive {
|
||||
sub isDisabled {
|
||||
my $hash = shift // return;
|
||||
|
||||
my $disable = IsDisabled($hash->{NAME}); #AttrVal($hash->{NAME}, "disable", 0 );
|
||||
my $disable =
|
||||
IsDisabled( $hash->{NAME} ); #AttrVal($hash->{NAME}, "disable", 0 );
|
||||
return $disable if ($disable);
|
||||
|
||||
my $disableCond = AttrVal( $hash->{NAME}, "disableCond", "nf" );
|
||||
@ -438,10 +501,13 @@ sub schaltZeitenErmitteln {
|
||||
stopZeitErmitteln( $hash, $now );
|
||||
|
||||
readingsBeginUpdate($hash);
|
||||
|
||||
# readingsBulkUpdate ($hash, "Startzeit", FmtDateTime($hash->{helper}{startTime}));
|
||||
# readingsBulkUpdate ($hash, "Stoppzeit", FmtDateTime($hash->{helper}{stopTime}));
|
||||
readingsBulkUpdate ($hash, "StartTime", FmtDateTime($hash->{helper}{startTime}));
|
||||
readingsBulkUpdate ($hash, "StopTime", FmtDateTime($hash->{helper}{stopTime}));
|
||||
readingsBulkUpdate( $hash, "StartTime",
|
||||
FmtDateTime( $hash->{helper}{startTime} ) );
|
||||
readingsBulkUpdate( $hash, "StopTime",
|
||||
FmtDateTime( $hash->{helper}{stopTime} ) );
|
||||
readingsEndUpdate( $hash, defined( $hash->{LOCAL} ? 0 : 1 ) );
|
||||
return;
|
||||
}
|
||||
@ -460,10 +526,14 @@ sub setState {
|
||||
|
||||
if ( isDisabled($hash) ) {
|
||||
if ( ReadingsVal( $hash->{NAME}, "state", "" ) ne "inactive" ) {
|
||||
my $dotrigger = ReadingsVal($hash->{NAME},"state","none") ne "disabled" ? 1 : 0;
|
||||
my $dotrigger =
|
||||
ReadingsVal( $hash->{NAME}, "state", "none" ) ne "disabled"
|
||||
? 1
|
||||
: 0;
|
||||
readingsSingleUpdate( $hash, "state", "disabled", $dotrigger );
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
my $state = $hash->{helper}{active} ? "on" : "off";
|
||||
readingsSingleUpdate( $hash, "state", $state, 1 );
|
||||
}
|
||||
@ -476,10 +546,10 @@ sub setSwitchmode {
|
||||
my $attrVal = shift // return;
|
||||
my $mod = "[" . $hash->{NAME} . "] ";
|
||||
|
||||
|
||||
if ( !( $attrVal =~ m/^([0-9]{1,3})\/([0-9]{1,3})$/ixms ) ) {
|
||||
Log3 undef, 3, $mod . "invalid switchMode <$attrVal>, use 999/999";
|
||||
} else {
|
||||
Log3( undef, 3, $mod . "invalid switchMode <$attrVal>, use 999/999");
|
||||
}
|
||||
else {
|
||||
my ( $sigmaWhenOff, $sigmaWhenOn ) = ( $1, $2 );
|
||||
$hash->{helper}{SWITCHMODE} = $attrVal;
|
||||
$hash->{helper}{SIGMAWHENON} = $sigmaWhenOn;
|
||||
@ -495,15 +565,20 @@ sub SetTimer {
|
||||
return if ( !defined($hash) );
|
||||
|
||||
my $now = time();
|
||||
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($now);
|
||||
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
|
||||
localtime($now);
|
||||
|
||||
setActive( $hash, 0 );
|
||||
schaltZeitenErmitteln( $hash, $now );
|
||||
setState($hash);
|
||||
|
||||
Log3 $hash, 4, "[".$hash->{NAME}."]" . " timings RandomTimer on $hash->{DEVICE}: "
|
||||
. strftime("%H:%M:%S(%d)",localtime($hash->{helper}{startTime})) . " - "
|
||||
. strftime("%H:%M:%S(%d)",localtime($hash->{helper}{stopTime}));
|
||||
Log3( $hash, 4,
|
||||
"["
|
||||
. $hash->{NAME} . "]"
|
||||
. " timings RandomTimer on $hash->{DEVICE}: "
|
||||
. strftime( "%H:%M:%S(%d)", localtime( $hash->{helper}{startTime} ) )
|
||||
. " - "
|
||||
. strftime( "%H:%M:%S(%d)", localtime( $hash->{helper}{stopTime} ) ) );
|
||||
|
||||
my $secToMidnight = 24 * 3600 - ( 3600 * $hour + 60 * $min + $sec );
|
||||
|
||||
@ -512,8 +587,9 @@ sub SetTimer {
|
||||
MkInternalTimer( "Exec", $setExecTime, \&Exec, $hash, 0 );
|
||||
|
||||
if ( $hash->{helper}{REP} gt "" ) {
|
||||
my $setTimerTime = max($now+$secToMidnight + 15,
|
||||
$hash->{helper}{stopTime}) + $hash->{helper}{TIMETOSWITCH}+15;
|
||||
my $setTimerTime =
|
||||
max( $now + $secToMidnight + 15, $hash->{helper}{stopTime} ) +
|
||||
$hash->{helper}{TIMETOSWITCH} + 15;
|
||||
RmInternalTimer( "SetTimer", $hash );
|
||||
MkInternalTimer( "SetTimer", $setTimerTime, \&SetTimer, $hash, 0 );
|
||||
}
|
||||
@ -531,8 +607,10 @@ sub startZeitErmitteln {
|
||||
$rel = $1;
|
||||
$rep = $2;
|
||||
$tspec = $3;
|
||||
} else {
|
||||
return "Wrong timespec_start <$timespec_start>, use \"[+][*]<time or func>\"";
|
||||
}
|
||||
else {
|
||||
return
|
||||
"Wrong timespec_start <$timespec_start>, use \"[+][*]<time or func>\"";
|
||||
}
|
||||
|
||||
my ( $err, $hour, $min, $sec, $fn ) = GetTimeSpec($tspec);
|
||||
@ -541,14 +619,16 @@ sub startZeitErmitteln {
|
||||
my $startTime;
|
||||
if ($rel) {
|
||||
$startTime = $now + 3600 * $hour + 60 * $min + $sec;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$startTime = zeitBerechnen( $now, $hour, $min, $sec );
|
||||
}
|
||||
my $varStart = $hash->{helper}{VAR_START};
|
||||
$startTime += int( rand($varStart) );
|
||||
|
||||
$hash->{helper}{startTime} = $startTime;
|
||||
$hash->{helper}{STARTTIME} = strftime("%d.%m.%Y %H:%M:%S",localtime($startTime));
|
||||
$hash->{helper}{STARTTIME} =
|
||||
strftime( "%d.%m.%Y %H:%M:%S", localtime($startTime) );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -568,8 +648,10 @@ sub stopZeitErmitteln {
|
||||
$rel = $1;
|
||||
$rep = $2;
|
||||
$tspec = $3;
|
||||
} else {
|
||||
return "Wrong timespec_stop <$timespec_stop>, use \"[+][*]<time or func>\"";
|
||||
}
|
||||
else {
|
||||
return
|
||||
"Wrong timespec_stop <$timespec_stop>, use \"[+][*]<time or func>\"";
|
||||
}
|
||||
|
||||
my ( $err, $hour, $min, $sec, $fn ) = GetTimeSpec($tspec);
|
||||
@ -577,8 +659,10 @@ sub stopZeitErmitteln {
|
||||
|
||||
my $stopTime;
|
||||
if ($rel) {
|
||||
$stopTime = $hash->{helper}{startTime} + 3600* $hour + 60* $min + $sec;
|
||||
} else {
|
||||
$stopTime =
|
||||
$hash->{helper}{startTime} + 3600 * $hour + 60 * $min + $sec;
|
||||
}
|
||||
else {
|
||||
$stopTime = zeitBerechnen( $now, $hour, $min, $sec );
|
||||
}
|
||||
|
||||
@ -588,21 +672,8 @@ sub stopZeitErmitteln {
|
||||
}
|
||||
}
|
||||
$hash->{helper}{stopTime} = $stopTime;
|
||||
$hash->{helper}{STOPTIME} = strftime("%d.%m.%Y %H:%M:%S",localtime($stopTime));
|
||||
return;
|
||||
}
|
||||
|
||||
sub Wakeup {
|
||||
|
||||
for my $hc ( sort keys %{$modules{RandomTimer}{defptr}} ) {
|
||||
my $hash = $modules{RandomTimer}{defptr}{$hc};
|
||||
|
||||
my $myHash->{HASH}=$hash;
|
||||
SetTimer($myHash);
|
||||
Log3 undef, 3, "RandomTimer::Wakeup() for $hash->{NAME} done!";
|
||||
}
|
||||
|
||||
Log3 undef, 3, "RandomTimer::Wakeup() done!";
|
||||
$hash->{helper}{STOPTIME} =
|
||||
strftime( "%d.%m.%Y %H:%M:%S", localtime($stopTime) );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -610,8 +681,11 @@ sub zeitBerechnen {
|
||||
my ( $now, $hour, $min, $sec ) = @_;
|
||||
|
||||
my @jetzt_arr = localtime($now);
|
||||
|
||||
#Stunden Minuten Sekunden
|
||||
$jetzt_arr[2] = $hour; $jetzt_arr[1] = $min; $jetzt_arr[0] = $sec;
|
||||
$jetzt_arr[2] = $hour;
|
||||
$jetzt_arr[1] = $min;
|
||||
$jetzt_arr[0] = $sec;
|
||||
my $next = timelocal_nocheck(@jetzt_arr);
|
||||
return $next;
|
||||
}
|
||||
@ -620,15 +694,21 @@ sub MkInternalTimer {
|
||||
my ( $modifier, $tim, $callback, $hash, $waitIfInitNotDone ) = @_;
|
||||
|
||||
my $timerName = "$hash->{NAME}_$modifier";
|
||||
my $mHash = { HASH=>$hash, NAME=>"$hash->{NAME}_$modifier", MODIFIER=>$modifier};
|
||||
my $mHash = {
|
||||
HASH => $hash,
|
||||
NAME => "$hash->{NAME}_$modifier",
|
||||
MODIFIER => $modifier
|
||||
};
|
||||
if ( defined( $hash->{TIMER}{$timerName} ) ) {
|
||||
Log3 $hash, 1, "[$hash->{NAME}] possible overwriting of timer $timerName - please delete first";
|
||||
Log3( $hash, 1, "[$hash->{NAME}] possible overwriting of timer $timerName - please delete first" );
|
||||
stacktrace();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$hash->{TIMER}{$timerName} = $mHash;
|
||||
}
|
||||
|
||||
Log3 $hash, 5, "[$hash->{NAME}] setting Timer: $timerName " . FmtDateTime($tim);
|
||||
Log3( $hash, 5,
|
||||
"[$hash->{NAME}] setting Timer: $timerName " . FmtDateTime($tim) );
|
||||
InternalTimer( $tim, $callback, $mHash, $waitIfInitNotDone );
|
||||
return $mHash;
|
||||
}
|
||||
@ -641,7 +721,7 @@ sub RmInternalTimer {
|
||||
my $myHash = $hash->{TIMER}{$timerName};
|
||||
if ( defined($myHash) ) {
|
||||
delete $hash->{TIMER}{$timerName};
|
||||
Log3 $hash, 5, "[$hash->{NAME}] removing Timer: $timerName";
|
||||
Log3( $hash, 5, "[$hash->{NAME}] removing Timer: $timerName" );
|
||||
RemoveInternalTimer($myHash);
|
||||
}
|
||||
return;
|
||||
@ -652,9 +732,9 @@ sub GetHashIndirekt {
|
||||
my $function = shift // return;
|
||||
|
||||
if ( !defined( $myHash->{HASH} ) ) {
|
||||
Log3 $myHash, 3, "[$function] myHash not valid";
|
||||
Log3( $myHash, 3, "[$function] myHash not valid" );
|
||||
return;
|
||||
};
|
||||
}
|
||||
return $myHash->{HASH};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user