90_at.pm: implement setList (Forum #137380)

git-svn-id: https://svn.fhem.de/fhem/trunk@28610 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2024-03-07 09:53:25 +00:00
parent 1d4a8cb3f8
commit 8ad7c244cf
2 changed files with 68 additions and 22 deletions

View File

@@ -17,8 +17,17 @@ at_Initialize($)
$hash->{SetFn} = "at_Set"; $hash->{SetFn} = "at_Set";
$hash->{AttrFn} = "at_Attr"; $hash->{AttrFn} = "at_Attr";
$hash->{StateFn} = "at_State"; $hash->{StateFn} = "at_State";
$hash->{AttrList} = "disable:0,1 disabledForIntervals $readingFnAttributes ". no warnings 'qw';
"skip_next:0,1 alignTime computeAfterInit"; my @attrList = qw(
alignTime
computeAfterInit
disable:0,1
disabledForIntervals
setList
skip_next:0,1
);
use warnings 'qw';
$hash->{AttrList} = join(" ", @attrList)." $readingFnAttributes";
$hash->{FW_detailFn} = "at_fhemwebFn"; $hash->{FW_detailFn} = "at_fhemwebFn";
} }
@@ -255,16 +264,33 @@ sub
at_Set($@) at_Set($@)
{ {
my ($hash, @a) = @_; my ($hash, @a) = @_;
my $me = $hash->{NAME};
my %sets =(modifyTimeSpec=>1,inactive=>0,active=>0,execNow=>0,"skip_next"=>0);
my $cmd = join(" ", sort keys %sets);
$cmd =~ s/modifyTimeSpec/modifyTimeSpec:time/ if($at_detailFnCalled);
$at_detailFnCalled = 0;
return "no set argument specified" if(int(@a) < 2); return "no set argument specified" if(int(@a) < 2);
return "Unknown argument $a[1], choose one of $cmd" my $cmd = $a[1];
if(!defined($sets{$a[1]}));
if($a[1] eq "modifyTimeSpec") { my %sets = ( active => ":noArg",
execNow => ":noArg",
inactive => ":noArg",
modifyTimeSpec => "",
skip_next => ":noArg" );
my $cmdList = join(" ", map { "$_$sets{$_}" } keys %sets);
$cmdList =~ s/modifyTimeSpec/modifyTimeSpec:time/ if($at_detailFnCalled);
$at_detailFnCalled = 0;
my $setList = AttrVal($me, "setList", "");
my %usrSets = map { $_ =~ s/:.*//; $_ => 1 } split(" ", $setList);
if(!defined($sets{$cmd}) && !defined($usrSets{$cmd})) {
return "Unknown argument $cmd, choose one of $cmdList $setList";
}
if($usrSets{$cmd}) {
readingsSingleUpdate($hash, $cmd, join(" ",@a[2..$#a]), 1);
return;
}
if($cmd eq "modifyTimeSpec") {
my ($err, undef) = GetTimeSpec($a[2]); my ($err, undef) = GetTimeSpec($a[2]);
return $err if($err); return $err if($err);
@@ -272,26 +298,25 @@ at_Set($@)
($hash->{PERIODIC} eq "yes" ? "*":""). ($hash->{PERIODIC} eq "yes" ? "*":"").
$a[2]; $a[2];
$hash->{OLDDEF} = $hash->{DEF}; $hash->{OLDDEF} = $hash->{DEF};
my $ret = at_Define($hash, "$hash->{NAME} at $def"); my $ret = at_Define($hash, "$me at $def");
delete $hash->{OLDDEF}; delete $hash->{OLDDEF};
return $ret; return $ret;
} elsif($a[1] eq "inactive") { } elsif($cmd eq "inactive") {
readingsSingleUpdate($hash, "state", "inactive", 1); readingsSingleUpdate($hash, "state", "inactive", 1);
return undef; return undef;
} elsif($a[1] eq "active") { } elsif($cmd eq "active") {
readingsSingleUpdate($hash,"state","Next: ".FmtTime($hash->{TRIGGERTIME}),1) readingsSingleUpdate($hash,"state","Next: ".FmtTime($hash->{TRIGGERTIME}),1)
if(!AttrVal($hash->{NAME}, "disable", undef)); if(!AttrVal($me, "disable", undef));
return undef; return undef;
} elsif($a[1] eq "execNow") { } elsif($cmd eq "execNow") {
my $name = $hash->{NAME}; my %sp = ( "%SELF" => $me );
my %sp = ( "%SELF" => $name );
my $ret = AnalyzeCommandChain(undef, EvalSpecials($hash->{"COMMAND"}, %sp)); my $ret = AnalyzeCommandChain(undef, EvalSpecials($hash->{"COMMAND"}, %sp));
Log3 $name, 3, "$name: $ret" if($ret); Log3 $me, 3, "$me: $ret" if($ret);
} elsif($a[1] eq "skip_next") { } elsif($cmd eq "skip_next") {
setReadingsVal($hash, $a[1], 1, TimeNow()); setReadingsVal($hash, $a[1], 1, TimeNow());
return undef; return undef;
@@ -577,6 +602,18 @@ at_ultimo(;$$$)
skip the next execution. Just like the attribute with the same name, skip the next execution. Just like the attribute with the same name,
but better suited for webCmd. but better suited for webCmd.
</li> </li>
<a id="at-attr-setList"></a>
<li>setList<br>
space separated list of user-defined commands. When executing such a
command, a reading with the same name is set to the arguments of the
command.<br>
Can be used in scenarios like:
<ul><code>
define wakeUp at *07:30 set Light on-for-timer [$SELF:duration]<br>
attr wakeUp setList duration:60,120,180
</code></ul>
</li>
</ul><br> </ul><br>
@@ -616,7 +653,16 @@ at_ultimo(;$$$)
Used for at commands: skip the execution of the command the next Used for at commands: skip the execution of the command the next
time.</li><br> time.</li><br>
<li><a href="#perlSyntaxCheck">perlSyntaxCheck</a></li> <a id="at-attr-setList"></a>
<li>setList<br>
Leerzeichen getrennte Liste von benutzerdefinierten Befehlen. Beim
ausf&uuml;ren solcher Befehle wird ein gleichnamiges Reading auf dem
Wert des Befehls gesetzt. Kann z.Bsp. wie folgt verwendet werden:
<ul><code>
define wecker at *07:30 set Licht on-for-timer [$SELF:dauer]<br>
attr wecker setList dauer:60,120,180
</code></ul>
</li>
</ul> </ul>
<br> <br>

View File

@@ -599,9 +599,9 @@ END
command.<br> command.<br>
Can be used in scenarios like: Can be used in scenarios like:
<ul><code> <ul><code>
define Leuchtdauer notify schalter:on define lightOn notify switch:on
set Licht on-for-timer [$SELF:dauer]<br> set Light on-for-timer [$SELF:duration]<br>
attr Leuchtdauer setList dauer:60,120,180 attr lightOn setList duration:60,120,180
</code></ul> </code></ul>
</li> </li>