diff --git a/fhem/FHEM/98_RandomTimer.pm b/fhem/FHEM/98_RandomTimer.pm index 452b680da..8098c5e94 100644 --- a/fhem/FHEM/98_RandomTimer.pm +++ b/fhem/FHEM/98_RandomTimer.pm @@ -24,28 +24,71 @@ # along with FHEM. If not, see . # packages #################################################################### -package main; - use strict; - use warnings; - no if $] >= 5.017011, warnings => 'experimental::smartmatch'; - use Time::HiRes qw(gettimeofday); - use Time::Local 'timelocal_nocheck'; +package FHEM::RandomTimer; ## no critic 'Package declaration' + +use strict; +use warnings; +use Time::HiRes qw(gettimeofday); +use Time::Local 'timelocal_nocheck'; +use GPUtils qw(GP_Import GP_Export); + +## Import der FHEM Funktionen +#-- Run before package compilation +BEGIN { + + # Import from main context + GP_Import( + qw( + defs + modules + attr + featurelevel + readingFnAttributes + readingsSingleUpdate + readingsBulkUpdate + readingsBeginUpdate + readingsEndUpdate + AttrVal + ReadingsVal + Value + Log3 + InternalTimer + RemoveInternalTimer + AnalyzeCommandChain + AnalyzePerlCommand + SemicolonEscape + FmtDateTime + strftime + GetTimeSpec + maxNum + stacktrace ) + ); +} + +#-- Export to main context with different name +# use this feature with care! +GP_Export( + qw( + Initialize + ) +); # initialize ################################################################## -sub RandomTimer_Initialize($) { - my ($hash) = @_; +sub Initialize { + my $hash = shift; - $hash->{DefFn} = "RandomTimer_Define"; - $hash->{UndefFn} = "RandomTimer_Undef"; - $hash->{SetFn} = "RandomTimer_Set"; - $hash->{AttrFn} = "RandomTimer_Attr"; + $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 ". $readingFnAttributes; + return; } -# regular Fn ################################################################## -sub RandomTimer_Define($$) { +# regular Functions ################################################################## +sub Define { my ($hash, $def) = @_; RemoveInternalTimer($hash); @@ -55,33 +98,43 @@ sub RandomTimer_Define($$) { return "wrong syntax: define RandomTimer []" if(!defined $timeToSwitch); - return "Wrong timespec_start <$timespec_start>, use \"[+][*]