diff --git a/FHEM/AttrTemplate.pm b/FHEM/AttrTemplate.pm index 1c0d5464f..1533f011c 100644 --- a/FHEM/AttrTemplate.pm +++ b/FHEM/AttrTemplate.pm @@ -2,6 +2,32 @@ # $Id$ package main; +# Syntax of the AttrTemplate file: +# - empty lines are ignored +# - lines starting with # are comments (see also desc:) +# - lines starting with the following keywords are special, all others are +# regular FHEM commands +# - name: name of the template, marks the end of the previous template. +# - filter:, describing the list of devices this +# template is applicable for. Well be executed when the set function is +# executed. +# - prereq:, where cond is a perl expression, or devspec2array returning +# exactly one device. Evaluated at initialization(!). +# - par:::. if there is an additional argument in the set, +# name in alle commands will be replaced with it. Else will be +# excuted: if returns a value, name in the commands will be replaced with it, +# else an error message/dialog will request the user to enter a value for +# name. +# For each name starting with RADIO_, a radio select button is offered. Such +# parameters must defined last. +# - desc: additional text for the "set attrTemplate help ?". If missing, the +# last comment before name: will be used for this purpose. +# - farewell: to be shown after the commands are executed. +# - order: sort the templates for help purposes. +# - option: if perl code return false, skip all commands until next +# option (or name:) + + my %templates; my $initialized; my %cachedUsage; @@ -187,14 +213,29 @@ AttrTemplate_Set($$@) my $h = $templates{$entry}; return "Unknown template_entry_name $entry" if(!$h); - my (%repl, @mComm, @mList, $missing); + my (@na, %repl, @mComm, @mList, $missing); + for(my $i1=0; $i1<@a; $i1++) { # parse parname=value form the command line + my $fnd; + for my $k (@{$h->{pars}}) { + my ($parname, $comment, $perl_code) = split(";",$k,3); + if($a[$i1] =~ m/$parname=(.*)/) { + $repl{$parname} = $1; + return "Empty parameters are not allowed" if($1 eq ""); + $fnd=1; + last; + } + } + push(@na,$a[$i1]) if(!$fnd); + } + @a = @na; + for my $k (@{$h->{pars}}) { my ($parname, $comment, $perl_code) = split(";",$k,3); - if(@a) { + next if(defined($repl{$parname})); + + if(@a) { # old-style, without prefix $repl{$parname} = $a[0]; - push(@mList, $parname); - push(@mComm, "$parname: with the $comment"); shift(@a); next; } @@ -210,8 +251,8 @@ AttrTemplate_Set($$@) } } - push(@mList, $parname); - push(@mComm, "$parname: with the $comment"); + push(@mList, "$parname=..."); + push(@mComm, "$parname= with $comment"); $missing = 1; } @@ -219,19 +260,36 @@ AttrTemplate_Set($$@) if($hash->{CL} && $hash->{CL}{TYPE} eq "FHEMWEB") { return "". - "". - "

Replace
".join("
",@mComm). + "". + "

Specify the unknown parameters for $entry:

". + "". + join("", map { + my @t=split("= with ",$_,2); + "") + } @mComm)."
$t[1]" .($t[0] =~ m/^RADIO_/ ? + "": + "
". '