From f4d30c871aa35d8a228f9b1a7b21461d7bafd884 Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Sun, 8 May 2016 14:25:39 +0000 Subject: [PATCH] SetExtension.pm: Cancel from justme1968 (Forum #53137) git-svn-id: https://svn.fhem.de/fhem/trunk@11410 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/SetExtensions.pm | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/fhem/FHEM/SetExtensions.pm b/fhem/FHEM/SetExtensions.pm index 6d27f1631..ebefc4d4a 100644 --- a/fhem/FHEM/SetExtensions.pm +++ b/fhem/FHEM/SetExtensions.pm @@ -8,6 +8,25 @@ use warnings; sub SetExtensions($$@); sub SetExtensionsFn($); +sub +SetExtensionsCancel($) +{ + my ($hash) = @_; + $hash = $defs{$hash} if( ref($hash) ne 'ARRAY' ); + + return undef if( !$hash ); + my $name = $hash->{NAME}; + + return undef if( !$hash->{SetExtensionTimer} ); + my $cmd = $hash->{SetExtensionTimer}{CMD}; + + RemoveInternalTimer("SE $name $cmd"); + + delete $hash->{SetExtensionTimer}; + + return undef; +} + sub SetExtensions($$@) { @@ -61,10 +80,13 @@ SetExtensions($$@) my $param = $a[0]; if($cmd eq "on-for-timer" || $cmd eq "off-for-timer") { - RemoveInternalTimer("SE $name $cmd"); + SetExtensionsCancel($hash); return "$cmd requires a number as argument" if($param !~ m/^\d*\.?\d*$/); if($param) { + $hash->{SetExtensionTimer} = { + START=>time(), START_FMT=>TimeNow(), DURATION=>$param, CMD=>$cmd + }; DoSet($name, $cmd1); InternalTimer(gettimeofday()+$param,"SetExtensionsFn","SE $name $cmd",0); } @@ -150,8 +172,10 @@ sub SetExtensionsFn($) { my (undef, $name, $cmd) = split(" ", shift, 3); - return if(!defined($defs{$name})); + my $hash = $defs{$name}; + return if(!$hash); + delete $hash->{SetExtensionTimer}; if($cmd eq "on-for-timer") { DoSet($name, "off");