mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
91_sequence: add delay and omit name options (by Petr, Forum #75925)
git-svn-id: https://svn.fhem.de/fhem/trunk@14996 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a2c31e2202
commit
41665439f8
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- feature: 91_sequence: add delay and omit name options (Forum #75925)
|
||||||
- bugfix: 74_AMADDevice: fix a lot of Bugs
|
- bugfix: 74_AMADDevice: fix a lot of Bugs
|
||||||
- feature: 93_Log2Syslog: V3.1.0, get certinfo added
|
- feature: 93_Log2Syslog: V3.1.0, get certinfo added
|
||||||
- bugfix: 73_AMADCommBridge: fix doubble set Command at Bridge
|
- bugfix: 73_AMADCommBridge: fix doubble set Command at Bridge
|
||||||
|
@ -40,14 +40,15 @@ sequence_Define($$)
|
|||||||
my $to = $def[$i+1];
|
my $to = $def[$i+1];
|
||||||
eval { "Hallo" =~ m/^$re$/ };
|
eval { "Hallo" =~ m/^$re$/ };
|
||||||
return "Bad regexp 1: $@" if($@);
|
return "Bad regexp 1: $@" if($@);
|
||||||
return "Bad timeout spec $to"
|
return "Bad timeout spec $to" # timeout or delay:timeout
|
||||||
if(defined($to) && $to !~ m/^\d*.?\d$/);
|
if (defined($to) && $to !~ m/^(\d+(\.\d+)?:)?\d+(\.\d+)?$/);
|
||||||
}
|
}
|
||||||
|
|
||||||
$hash->{RE} = $def[0];
|
$hash->{RE} = $def[0];
|
||||||
$hash->{IDX} = 0;
|
$hash->{IDX} = 0;
|
||||||
$hash->{MAX} = int(@def);
|
$hash->{MAX} = int(@def);
|
||||||
$hash->{STATE} = "active";
|
$hash->{STATE} = "active";
|
||||||
|
$hash->{TS} = 0;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +71,12 @@ sequence_Notify($$)
|
|||||||
next if($n !~ m/^$re$/ && "$n:$s" !~ m/^$re$/);
|
next if($n !~ m/^$re$/ && "$n:$s" !~ m/^$re$/);
|
||||||
|
|
||||||
RemoveInternalTimer($ln);
|
RemoveInternalTimer($ln);
|
||||||
|
|
||||||
|
if($hash->{TS} > gettimeofday()) { # the delay stuff
|
||||||
|
sequence_Trigger($ln, "abort");
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
my $idx = $hash->{IDX} + 2;
|
my $idx = $hash->{IDX} + 2;
|
||||||
Log3 $ln, 5, "sequence $ln matched $idx";
|
Log3 $ln, 5, "sequence $ln matched $idx";
|
||||||
my @d = split("[ \t]+", $hash->{DEF});
|
my @d = split("[ \t]+", $hash->{DEF});
|
||||||
@ -86,33 +93,37 @@ sequence_Notify($$)
|
|||||||
setReadingsVal($hash, "state", "active", TimeNow());
|
setReadingsVal($hash, "state", "active", TimeNow());
|
||||||
DoTrigger($ln, $tt);
|
DoTrigger($ln, $tt);
|
||||||
$idx = 0;
|
$idx = 0;
|
||||||
|
$hash->{TS} = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$hash->{RE} = $d[$idx];
|
my ($delay, $nt) = split(':', $d[$idx - 1]);
|
||||||
my $nt = gettimeofday() + $d[$idx-1];
|
$hash->{TS} = gettimeofday() + $delay if (defined($nt) && $delay > 0);
|
||||||
|
$nt += gettimeofday() + $delay;
|
||||||
InternalTimer($nt, "sequence_Trigger", $ln, 0);
|
InternalTimer($nt, "sequence_Trigger", $ln, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$hash->{IDX} = $idx;
|
$hash->{IDX} = $idx;
|
||||||
$hash->{RE} = $d[$idx];
|
$hash->{RE} = substr($d[$idx], 0, 1) eq ':' ? $n . $d[$idx] : $d[$idx];
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
sequence_Trigger($)
|
sequence_Trigger($$)
|
||||||
{
|
{
|
||||||
my ($ln) = @_;
|
my ($ln, $arg) = @_;
|
||||||
my $hash = $defs{$ln};
|
my $hash = $defs{$ln};
|
||||||
my @d = split("[ \t]+", $hash->{DEF});
|
my @d = split("[ \t]+", $hash->{DEF});
|
||||||
$hash->{RE} = $d[0];
|
$hash->{RE} = $d[0];
|
||||||
my $idx = $hash->{IDX}/2;
|
my $idx = $hash->{IDX}/2;
|
||||||
$hash->{IDX} = 0;
|
$hash->{IDX} = 0;
|
||||||
|
$hash->{TS} = 0;
|
||||||
my $tt = "partial_$idx";
|
my $tt = "partial_$idx";
|
||||||
Log3 $ln, 5, "sequence $ln timeout on $idx ($tt)";
|
$arg = "timeout" if(!$arg);
|
||||||
|
Log3 $ln, 5, "sequence $ln $arg on $idx ($tt)";
|
||||||
$tt .= $hash->{EVENTS} if(AttrVal($ln, "reportEvents", undef));
|
$tt .= $hash->{EVENTS} if(AttrVal($ln, "reportEvents", undef));
|
||||||
delete($hash->{EVENTS});
|
delete($hash->{EVENTS});
|
||||||
|
|
||||||
@ -158,6 +169,28 @@ sequence_Undef($$)
|
|||||||
define lampon notify lampseq:trigger set lamp on
|
define lampon notify lampseq:trigger set lamp on
|
||||||
</code>
|
</code>
|
||||||
</ul>
|
</ul>
|
||||||
|
<br>
|
||||||
|
Subsequent patterns can be specified without device name as
|
||||||
|
<code>:<re2></code>. This will reuse the device name which triggered
|
||||||
|
the previous sequence step:
|
||||||
|
<br>
|
||||||
|
<ul>
|
||||||
|
<code>
|
||||||
|
define lampseq sequence Btn.:on 0.5 :off<br>
|
||||||
|
</code>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
You can specify timeout as <code><delay>:<timeout></code>,
|
||||||
|
where "delay" sets time during which the next event shall not be received,
|
||||||
|
otherwise the sequence will be aborted. This can be used to capture press
|
||||||
|
and hold of a button. Example:<br>
|
||||||
|
<ul>
|
||||||
|
<code>
|
||||||
|
define lampseq sequence Btn1:on 2:3 Btn1:off<br>
|
||||||
|
</code>
|
||||||
|
</ul>
|
||||||
|
sequence will be triggerred if Btn1 is pressed for 2 to 5 seconds.
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@ -226,6 +259,27 @@ sequence_Undef($$)
|
|||||||
define lampon notify lampseq:trigger set lamp on
|
define lampon notify lampseq:trigger set lamp on
|
||||||
</code>
|
</code>
|
||||||
</ul>
|
</ul>
|
||||||
|
Nachfolgende Regexps können den Namen des Gerätes weglassen, in
|
||||||
|
diesem Fall werden nur die Events des beim ersten Event eingetroffenen
|
||||||
|
Gerätes beachtet:
|
||||||
|
<br>
|
||||||
|
<ul>
|
||||||
|
<code>
|
||||||
|
define lampseq sequence Btn.:on 0.5 :off<br>
|
||||||
|
</code>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
Timeout kann als <code><delay>:<timeout></code> spezifiziert
|
||||||
|
werden, dabei setzt delay die Zeit, wo kein passendes Event empfangen
|
||||||
|
werden darf, ansonsten wird sequence abgebrochen. Das kann verwendet
|
||||||
|
werden, um "press and hold" auszuwerten. Folgendes
|
||||||
|
<ul>
|
||||||
|
<code>
|
||||||
|
define lampseq sequence Btn1:on 2:3 :off<br>
|
||||||
|
</code>
|
||||||
|
</ul>
|
||||||
|
ist nur erfolgreich, falls Btn1 zwischen 2 und 5 Sekunden lang gedrückt
|
||||||
|
wurde.
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user