From cef7607065b75cc1cd735dbee5743aacd99db36a Mon Sep 17 00:00:00 2001 From: Beta-User <> Date: Thu, 21 May 2020 04:12:35 +0000 Subject: [PATCH] 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 --- fhem/CHANGED | 1 + fhem/FHEM/98_RandomTimer.pm | 976 +++++++++++++++++++----------------- 2 files changed, 529 insertions(+), 448 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index ee7b0f62e..092c77ee9 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -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 diff --git a/fhem/FHEM/98_RandomTimer.pm b/fhem/FHEM/98_RandomTimer.pm index cea2204e0..9a58180d3 100644 --- a/fhem/FHEM/98_RandomTimer.pm +++ b/fhem/FHEM/98_RandomTimer.pm @@ -24,13 +24,13 @@ # along with FHEM. If not, see . # packages #################################################################### -package FHEM::RandomTimer; ## no critic 'Package declaration' +package FHEM::RandomTimer; ## no critic 'Package declaration' 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); @@ -41,621 +41,701 @@ BEGIN { # Import from main context GP_Import( qw( - defs - modules - attr - featurelevel - readingFnAttributes - readingsSingleUpdate - readingsBulkUpdate - readingsBeginUpdate - readingsEndUpdate - AttrVal - ReadingsVal - Value - IsDisabled - Log3 - InternalTimer - RemoveInternalTimer - CommandDeleteAttr - AnalyzeCommandChain - AnalyzePerlCommand - SemicolonEscape - FmtDateTime - strftime - GetTimeSpec - stacktrace ) + defs + modules + attr + featurelevel + readingFnAttributes + readingsSingleUpdate + readingsBulkUpdate + readingsBeginUpdate + readingsEndUpdate + AttrVal + ReadingsVal + Value + IsDisabled + Log3 + InternalTimer + RemoveInternalTimer + CommandDeleteAttr + AnalyzeCommandChain + AnalyzePerlCommand + perlSyntaxCheck + SemicolonEscape + FmtDateTime + strftime + GetTimeSpec + stacktrace ) ); } -#-- 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; - 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; + return; } # regular Functions ################################################################## sub Define { - my $hash = shift; - my $def = shift // return; + my $hash = shift; + my $def = shift // return; - RemoveInternalTimer($hash); - my ($name, $type, $timespec_start, $device, $timespec_stop, $timeToSwitch, $variation) = - split m{\s+}xms, $def; + RemoveInternalTimer($hash); + my ( $name, $type, $timespec_start, $device, $timespec_stop, $timeToSwitch, + $variation ) + = split m{\s+}xms, $def; - return "wrong syntax: define RandomTimer []" - if(!defined $timeToSwitch); + return "wrong syntax: define RandomTimer []" + if ( !defined $timeToSwitch ); - my ($rel, $rep, $tspec); - if ($timespec_start =~ m{^(\+)?(\*)?(.*)$}ixms) { - $rel = $1; - $rep = $2; - $tspec = $3; - } else { - return qq{"Wrong timespec_start <$timespec_start>, use "[+][*]