2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-19 18:56:03 +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); my $cmdList = join(" ", map { "$_:$cmd{$_}" } sort keys %cmd);
return SetExtensions($hash, $cmdList, @a) return SetExtensions($hash, $cmdList, @a)
} }
SetExtensionsCancel($hash);
my $cmd = $a[1]; my $cmd = $a[1];
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -138,6 +139,7 @@ FBDECT_Set($@)
my $usage = join(" ", sort keys %sets); my $usage = join(" ", sort keys %sets);
return SetExtensions($hash, $usage, @a); return SetExtensions($hash, $usage, @a);
} }
SetExtensionsCancel($hash);
my $name = $hash->{NAME}; my $name = $hash->{NAME};
Log3 $name, 3, "FBDECT set $name $cmd"; 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") $list = (join(" ", sort keys %fs20_c2b) . " dim:slider,0,6.25,100")
if(!defined($list)); if(!defined($list));
return SetExtensions($hash, $list, @a); return SetExtensions($hash, $list, @a);
} }
SetExtensionsCancel($hash);
return "Bad time spec" if($na == 3 && $a[2] !~ m/^\d*\.?\d+$/); 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"); return ZWave_neighborList($hash) if($cmd eq "neighborList");

View File

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