########################################################################## # $Id$ # # copyright ################################################################### # # 98_RandomTimer.pm # # written by Dietmar Ortmann # Maintained by Beta-User since 11-2019 # # This file is part of FHEM. # # FHEM is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # FHEM is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with FHEM. If not, see . # packages #################################################################### package FHEM::RandomTimer; ## no critic 'Package declaration' use strict; use warnings; use utf8; use Time::HiRes qw(gettimeofday); use Time::Local qw(timelocal_nocheck); use List::Util qw(max); use POSIX qw(strftime); use GPUtils qw(GP_Import); ## 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 IsDisabled Log3 InternalTimer RemoveInternalTimer CommandDeleteAttr AnalyzeCommandChain AnalyzePerlCommand perlSyntaxCheck SemicolonEscape FmtDateTime GetTimeSpec CommandDelete stacktrace ) ); } sub ::RandomTimer_Initialize { goto &Initialize } # initialize ################################################################## sub Initialize { 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; } # regular Functions ################################################################## sub Define { my $hash = shift; my $def = shift // return; 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 ); my ( $rel, $rep, $tspec ); if ( $timespec_start =~ m{\A(\+)?(\*)?(.*)\z}ixms ) { $rel = $1; $rep = $2; $tspec = $3; } else { return qq{ "Wrong timespec_start <$timespec_start>, use "[+][*]