2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

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 868010d8e4
commit f48be9b537
2 changed files with 68 additions and 22 deletions

View File

@ -17,8 +17,17 @@ at_Initialize($)
$hash->{SetFn} = "at_Set";
$hash->{AttrFn} = "at_Attr";
$hash->{StateFn} = "at_State";
$hash->{AttrList} = "disable:0,1 disabledForIntervals $readingFnAttributes ".
"skip_next:0,1 alignTime computeAfterInit";
no warnings 'qw';
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";
}
@ -255,16 +264,33 @@ sub
at_Set($@)
{
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 "Unknown argument $a[1], choose one of $cmd"
if(!defined($sets{$a[1]}));
my $cmd = $a[1];
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($a[1] eq "modifyTimeSpec") {
if($cmd eq "modifyTimeSpec") {
my ($err, undef) = GetTimeSpec($a[2]);
return $err if($err);
@ -272,26 +298,25 @@ at_Set($@)
($hash->{PERIODIC} eq "yes" ? "*":"").
$a[2];
$hash->{OLDDEF} = $hash->{DEF};
my $ret = at_Define($hash, "$hash->{NAME} at $def");
my $ret = at_Define($hash, "$me at $def");
delete $hash->{OLDDEF};
return $ret;
} elsif($a[1] eq "inactive") {
} elsif($cmd eq "inactive") {
readingsSingleUpdate($hash, "state", "inactive", 1);
return undef;
} elsif($a[1] eq "active") {
} elsif($cmd eq "active") {
readingsSingleUpdate($hash,"state","Next: ".FmtTime($hash->{TRIGGERTIME}),1)
if(!AttrVal($hash->{NAME}, "disable", undef));
if(!AttrVal($me, "disable", undef));
return undef;
} elsif($a[1] eq "execNow") {
my $name = $hash->{NAME};
my %sp = ( "%SELF" => $name );
} elsif($cmd eq "execNow") {
my %sp = ( "%SELF" => $me );
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());
return undef;
@ -577,6 +602,18 @@ at_ultimo(;$$$)
skip the next execution. Just like the attribute with the same name,
but better suited for webCmd.
</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>
@ -616,7 +653,16 @@ at_ultimo(;$$$)
Used for at commands: skip the execution of the command the next
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>
<br>

View File

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