2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

98_WeekdayTimer.pm: add syntax check in DEF

git-svn-id: https://svn.fhem.de/fhem/trunk@22816 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Beta-User 2020-09-21 17:46:04 +00:00
parent 0a0e3b7c2a
commit 4b1ab42ecf

View File

@ -87,7 +87,8 @@ sub WeekdayTimer_Define {
addToDevAttrList($name, "weekprofile") if $def =~ m{weekprofile}xms; addToDevAttrList($name, "weekprofile") if $def =~ m{weekprofile}xms;
return InternalTimer(time(), "WeekdayTimer_Start",$hash,0); return InternalTimer(time(), "WeekdayTimer_Start",$hash,0) if !$init_done;
return WeekdayTimer_Start($hash);
} }
################################################################################ ################################################################################
@ -119,13 +120,17 @@ sub WeekdayTimer_Start {
my @switchingtimes = WeekdayTimer_gatherSwitchingTimes ($hash, \@arr); my @switchingtimes = WeekdayTimer_gatherSwitchingTimes ($hash, \@arr);
my $conditionOrCommand = join (" ", @arr); my $conditionOrCommand = join (" ", @arr);
my @errors;
# test if device is defined # test if device is defined
Log3( $hash, 3, "[$name] device <$device> in fhem not defined, but accepted") if(!$defs{$device} ); if(!$defs{$device} ) {
Log3( $hash, 3, "[$name] device <$device> in fhem not defined, but accepted") ;
if($init_done) { push @errors, qq(device <$device> in fhem not defined) };
}
# wenn keine switchintime angegeben ist, dann Fehler # wenn keine switchintime angegeben ist, dann Fehler
Log3( $hash, 3, "[$name] no valid Switchingtime found in <$conditionOrCommand>, check first parameter" ) if (@switchingtimes == 0); if (@switchingtimes == 0) {
Log3( $hash, 3, "[$name] no valid Switchingtime found in <$conditionOrCommand>, check parameters or make sure weekprofile device exists and returns valid data." ) ;
if($init_done) { push @errors, qq(no valid switchingtime found in <$conditionOrCommand>, check parameters or make sure weekprofile device exists and returns valid data.) };
}
$hash->{STILLDONETIME} = 0; $hash->{STILLDONETIME} = 0;
$hash->{SWITCHINGTIMES} = \@switchingtimes; $hash->{SWITCHINGTIMES} = \@switchingtimes;
$attr{$name}{verbose} = 5 if (!defined $attr{$name}{verbose} && $name =~ m{\Atst.*}xms ); $attr{$name}{verbose} = 5 if (!defined $attr{$name}{verbose} && $name =~ m{\Atst.*}xms );
@ -135,6 +140,12 @@ sub WeekdayTimer_Start {
if($conditionOrCommand =~ m{\A\(.*\)\z}xms) { #condition (*) if($conditionOrCommand =~ m{\A\(.*\)\z}xms) { #condition (*)
$hash->{CONDITION} = $conditionOrCommand; $hash->{CONDITION} = $conditionOrCommand;
my %specials = ( "%NAME" => $hash->{DEVICE}, "%EVENT" => "0");
my $r = perlSyntaxCheck(qq({$conditionOrCommand}),%specials);
if ($r) {
Log3( $hash, 2, "[$name] check syntax of CONDITION <$conditionOrCommand>" ) ;
if($init_done) { push @errors, qq(check syntax of CONDITION <$conditionOrCommand>: $r) };
}
} elsif(length($conditionOrCommand) > 0 ) { } elsif(length($conditionOrCommand) > 0 ) {
$hash->{COMMAND} = $conditionOrCommand; $hash->{COMMAND} = $conditionOrCommand;
} }
@ -146,7 +157,12 @@ sub WeekdayTimer_Start {
$attr{$name}{commandTemplate} = $attr{$name}{commandTemplate} =
'set $NAME '. WeekdayTimer_isHeizung($hash) .' $EVENT' if (!defined $attr{$name}{commandTemplate}); 'set $NAME '. WeekdayTimer_isHeizung($hash) .' $EVENT' if (!defined $attr{$name}{commandTemplate});
return WeekdayTimer_SetTimerOfDay({ HASH => $hash}); WeekdayTimer_SetTimerOfDay({ HASH => $hash});
return if !$init_done;
return join("\n", @errors) if(@errors);
return;
} }
################################################################################ ################################################################################
@ -764,13 +780,11 @@ sub WeekdayTimer_SetTimer {
my $para = $hash->{profil}{$idx}{PARA}; my $para = $hash->{profil}{$idx}{PARA};
my $overrulewday = $hash->{profil}{$idx}{WE_Override}; my $overrulewday = $hash->{profil}{$idx}{WE_Override};
my $secondsToSwitch = $timToSwitch - $now;
my $isActiveTimer = WeekdayTimer_isAnActiveTimer ($hash, $tage, $para, $overrulewday); my $isActiveTimer = WeekdayTimer_isAnActiveTimer ($hash, $tage, $para, $overrulewday);
readingsSingleUpdate ($hash, "state", "active", 1) readingsSingleUpdate ($hash, "state", "active", 1)
if (!defined $hash->{SETTIMERATMIDNIGHT} && $isActiveTimer); if (!defined $hash->{SETTIMERATMIDNIGHT} && $isActiveTimer);
if ($secondsToSwitch>-5 || defined $hash->{SETTIMERATMIDNIGHT} ) { if ( $timToSwitch - $now > -5 || defined $hash->{SETTIMERATMIDNIGHT} ) {
if($isActiveTimer) { if($isActiveTimer) {
Log3( $hash, 4, "[$name] setTimer - timer seems to be active today: ".join("",@$tage)."|$time|$para" ); Log3( $hash, 4, "[$name] setTimer - timer seems to be active today: ".join("",@$tage)."|$time|$para" );
WeekdayTimer_RemoveInternalTimer("$idx", $hash); WeekdayTimer_RemoveInternalTimer("$idx", $hash);
@ -794,9 +808,11 @@ sub WeekdayTimer_SetTimer {
Log3( $hash, 3, "[$name] can not compute past switching time" ); Log3( $hash, 3, "[$name] can not compute past switching time" );
} }
readingsSingleUpdate ($hash, "nextUpdate", FmtDateTime($nextTime), 1); readingsBeginUpdate($hash);
readingsSingleUpdate ($hash, "nextValue", $nextParameter, 1); readingsBulkUpdate ($hash, "nextUpdate", FmtDateTime($nextTime));
readingsSingleUpdate ($hash, "currValue", $aktParameter, 1); # HB readingsBulkUpdate ($hash, "nextValue", $nextParameter);
readingsBulkUpdate ($hash, "currValue", $aktParameter);
readingsEndUpdate ($hash, 1);
if ($switchInThePast && defined $aktTime) { if ($switchInThePast && defined $aktTime) {
# Fensterkontakte abfragen - wenn einer im Status closed, dann Schaltung um 60 Sekunden verzögern # Fensterkontakte abfragen - wenn einer im Status closed, dann Schaltung um 60 Sekunden verzögern
@ -970,7 +986,7 @@ sub WeekdayTimer_Update {
readingsBulkUpdate ($hash, "nextValue", $nextParameter); readingsBulkUpdate ($hash, "nextValue", $nextParameter);
readingsBulkUpdate ($hash, "currValue", $aktParameter); # HB readingsBulkUpdate ($hash, "currValue", $aktParameter); # HB
readingsBulkUpdate ($hash, "state", $newParam ) if($activeTimerState); readingsBulkUpdate ($hash, "state", $newParam ) if($activeTimerState);
readingsEndUpdate ($hash, defined($hash->{LOCAL} ? 0 : 1)); readingsEndUpdate ($hash, 1);
return 1; return 1;
@ -985,7 +1001,7 @@ sub WeekdayTimer_isAnActiveTimer {
my $condition = WeekdayTimer_Condition ($hash, $tage, $overrulewday); my $condition = WeekdayTimer_Condition ($hash, $tage, $overrulewday);
my $tageAsHash = WeekdayTimer_tageAsHash($hash, $tage); my $tageAsHash = WeekdayTimer_tageAsHash($hash, $tage);
my $xPression = "{".$tageAsHash.";;".$condition ."}"; my $xPression = qq( { $tageAsHash ;; $condition } );
$xPression = EvalSpecials($xPression, %specials); $xPression = EvalSpecials($xPression, %specials);
Log3( $hash, 5, "[$name] condition: $xPression" ); Log3( $hash, 5, "[$name] condition: $xPression" );
@ -1588,7 +1604,9 @@ sub WeekdayTimer_GetWeekprofileReadingTriplett {
}, },
"keywords" : [ "keywords" : [
"heating", "heating",
"Heizung" "Heizung",
"timer",
"weekprofile"
], ],
"prereqs" : { "prereqs" : {
"runtime" : { "runtime" : {