2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-08 13:24:56 +00:00

SetExtensions.pm: Fix SetExtensionsCancel (Forum #59117)

git-svn-id: https://svn.fhem.de/fhem/trunk@12688 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2016-11-29 20:40:24 +00:00
parent 144f6df236
commit 8d7d815c60
5 changed files with 47 additions and 44 deletions

View File

@ -98,6 +98,7 @@ FBDECT_SetHttp($@)
my $cmdList = join(" ", map { "$_:$cmd{$_}" } sort keys %cmd);
return SetExtensions($hash, $cmdList, @a)
}
SetExtensionsCancel($hash);
my $cmd = $a[1];
my $name = $hash->{NAME};
@ -138,6 +139,7 @@ FBDECT_Set($@)
my $usage = join(" ", sort keys %sets);
return SetExtensions($hash, $usage, @a);
}
SetExtensionsCancel($hash);
my $name = $hash->{NAME};
Log3 $name, 3, "FBDECT set $name $cmd";

View File

@ -210,8 +210,8 @@ FS20_Set($@)
$list = (join(" ", sort keys %fs20_c2b) . " dim:slider,0,6.25,100")
if(!defined($list));
return SetExtensions($hash, $list, @a);
}
SetExtensionsCancel($hash);
return "Bad time spec" if($na == 3 && $a[2] !~ m/^\d*\.?\d+$/);

View File

@ -889,6 +889,7 @@ ZWave_Cmd($$@)
}
}
SetExtensionsCancel($hash) if($type eq "set");
return ZWave_neighborList($hash) if($cmd eq "neighborList");

View File

@ -34,6 +34,7 @@ dummy_Set($@)
unshift @a, $name;
return SetExtensions($hash, $setList, @a)
}
SetExtensionsCancel($hash);
} else {
return "Unknown argument ?, choose one of $setList" if($a[0] eq "?");
}

View File

@ -15,18 +15,30 @@ SetExtensionsCancel($)
$hash = $defs{$hash} if( ref($hash) ne 'HASH' );
return undef if( !$hash );
return undef if( $hash->{InSetExtensions} );
my $name = $hash->{NAME};
return undef if( !$hash->{TIMED_OnOff} );
my $cmd = $hash->{TIMED_OnOff}{CMD};
RemoveInternalTimer("SE $name $cmd");
delete $hash->{TIMED_OnOff};
if($hash->{TIMED_OnOff}) { # on-for-timer, blink
my $cmd = $hash->{TIMED_OnOff}{CMD};
RemoveInternalTimer("SE $name $cmd");
delete $hash->{TIMED_OnOff};
}
for my $sfx ("_till", "_intervalFrom", "_intervalNext") {
CommandDelete(undef, $name.$sfx) if($defs{$name.$sfx});
}
return undef;
}
sub
SE_DoSet(@)
{
my $hash = $defs{$_[0]};
$hash->{InSetExtensions} = 1;
DoSet(@_);
delete $hash->{InSetExtensions};
}
sub
SetExtensions($$@)
{
@ -41,7 +53,7 @@ SetExtensions($$@)
"off-till" => 1,
"on-till-overnight" => 1,
"off-till-overnight"=> 1,
"blink" => 2,
"blink" => 0,
"intervals" => 0,
"toggle" => 0
);
@ -75,19 +87,21 @@ SetExtensions($$@)
return "$cmd requires $se_list{$cmd} parameter";
}
SetExtensionsCancel($hash);
my $cmd1 = ($cmd =~ m/^on.*/ ? "on" : "off");
my $cmd2 = ($cmd =~ m/^on.*/ ? "off" : "on");
my $param = $a[0];
if($cmd eq "on-for-timer" || $cmd eq "off-for-timer") {
SetExtensionsCancel($hash);
return "$cmd requires a number as argument" if($param !~ m/^\d*\.?\d*$/);
if($param) {
$hash->{TIMED_OnOff} = {
START=>time(), START_FMT=>TimeNow(), DURATION=>$param, CMD=>$cmd
START=>time(), START_FMT=>TimeNow(), DURATION=>$param,
CMD=>$cmd, NEXTCMD=>$cmd2
};
DoSet($name, $cmd1);
SE_DoSet($name, $cmd1);
InternalTimer(gettimeofday()+$param,"SetExtensionsFn","SE $name $cmd",0);
}
@ -95,9 +109,6 @@ SetExtensions($$@)
my ($err, $hr, $min, $sec, $fn) = GetTimeSpec($param);
return "$cmd: $err" if($err);
my $at = $name . "_till";
CommandDelete(undef, $at) if($defs{$at});
my $hms_till = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
if($cmd =~ m/-till$/) {
my @lt = localtime;
@ -108,31 +119,27 @@ SetExtensions($$@)
return "";
}
}
DoSet($name, $cmd1);
CommandDefine(undef, "$at at $hms_till set $name $cmd2");
SE_DoSet($name, $cmd1);
CommandDefine(undef, "${name}_till at $hms_till set $name $cmd2");
} elsif($cmd eq "blink") {
my $p2 = $a[1];
delete($hash->{SE_BLINKPARAM});
return "$cmd requires 2 numbers as argument"
if($param !~ m/^\d+$/ || $p2 !~ m/^\d*\d?\d*$/);
if($param !~ m/^\d+$/ || $p2 !~ m/^\d*\.?\d*$/);
if($param) {
DoSet($name, "on-for-timer", $p2);
$param--;
SE_DoSet($name, $a[2] ? "off" : "on");
$param-- if($a[2]);
if($param) {
$hash->{SE_BLINKPARAM} = "$param $p2";
InternalTimer(gettimeofday()+2*$p2,"SetExtensionsFn","SE $name $cmd",0);
$hash->{TIMED_OnOff} = {
START=>time(), START_FMT=>TimeNow(), DURATION=>$param,
CMD=>$cmd, NEXTCMD=>"$cmd $param $p2 ".($a[2] ? "0" : "1")
};
InternalTimer(gettimeofday()+$p2, "SetExtensionsFn","SE $name $cmd",0);
}
}
} elsif($cmd eq "intervals") {
my $at0 = "${name}_till";
my $at1 = "${name}_intervalFrom",
my $at2 = "${name}_intervalNext";
CommandDelete(undef, $at0) if($defs{$at0});
CommandDelete(undef, $at1) if($defs{$at1});
CommandDelete(undef, $at2) if($defs{$at2});
my $intSpec = shift(@a);
if($intSpec) {
@ -148,20 +155,22 @@ SetExtensions($$@)
SetExtensions($hash, $list, $name, "on-till", $till);
} else {
CommandDefine(undef, "$at1 at $from set $name on-till $till");
CommandDefine(undef,
"${name}_intervalFrom at $from set $name on-till $till");
}
if(@a) {
my $rest = join(" ", @a);
my ($from, $till) = split("-", shift @a);
CommandDefine(undef, "$at2 at $from set $name intervals $rest");
CommandDefine(undef,
"${name}_intervalNext at $from set $name intervals $rest");
}
}
} elsif($cmd eq "toggle") {
$value = ($1==0 ? "off" : "on") if($value =~ m/dim (\d+)/); # Forum #49391
DoSet($name, $value =~ m/^on/ ? "off" : "on");
SE_DoSet($name, $value =~ m/^on/ ? "off" : "on");
}
@ -173,21 +182,11 @@ SetExtensionsFn($)
{
my (undef, $name, $cmd) = split(" ", shift, 3);
my $hash = $defs{$name};
return if(!$hash);
return if(!$hash || !$hash->{TIMED_OnOff});
my $nextcmd = $hash->{TIMED_OnOff}{NEXTCMD};
delete $hash->{TIMED_OnOff};
if($cmd eq "on-for-timer") {
DoSet($name, "off");
} elsif($cmd eq "off-for-timer") {
DoSet($name, "on");
} elsif($cmd eq "blink" && $defs{$name}{SE_BLINKPARAM}) {
DoSet($name, "blink", split(" ", $defs{$name}{SE_BLINKPARAM}, 2));
}
SE_DoSet($name, split(" ",$nextcmd));
}
1;