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

SetExtension.pm: Cancel from justme1968 (Forum #53137)

git-svn-id: https://svn.fhem.de/fhem/trunk@11410 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2016-05-08 14:25:39 +00:00
parent e51122d425
commit e8dbb5634e

View File

@ -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");