From aab6cbf7fc46a7f01153a5e568c882f99e448798 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sun, 29 Jan 2023 11:48:19 +0000 Subject: [PATCH] AttrTemplate.pm: add the pardefault: template command (Forum #131914) git-svn-id: https://svn.fhem.de/fhem/trunk@27145 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/AttrTemplate.pm | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/fhem/FHEM/AttrTemplate.pm b/fhem/FHEM/AttrTemplate.pm index 8355b6d23..a38a40e93 100644 --- a/fhem/FHEM/AttrTemplate.pm +++ b/fhem/FHEM/AttrTemplate.pm @@ -14,12 +14,13 @@ package main; # - 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 +# name in all 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. +# else a 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. +# - pardefault:::. +# Same as par, but the dialog is always shown, with the input is prefilled. # - 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. @@ -68,7 +69,8 @@ AttrTemplate_Initialize() } elsif($line =~ m/^name:(.*)/) { $name = $1; - my (@p,@c); + my (@p,@c,%t); + $templates{$name}{ptype} = \%t; $templates{$name}{pars} = \@p; $templates{$name}{cmds} = \@c; $templates{$name}{desc} = $lastComment if($lastComment); @@ -89,8 +91,10 @@ AttrTemplate_Initialize() } - } elsif($line =~ m/^par:(.*)/) { - push(@{$templates{$name}{pars}}, $1); + } elsif($line =~ m/^(par|pardefault):(.*)/) { + push(@{$templates{$name}{pars}}, $2); + my @v = split(";",$2,2); + $templates{$name}{ptype}{$v[0]} = $1; } elsif($line =~ m/^desc:(.*)/) { $templates{$name}{desc} = $1; @@ -278,7 +282,7 @@ AttrTemplate_Set($$@) if($@); if(defined($ret)) { $repl{$parname} = $ret; - next; + next if($h->{ptype}{$parname} ne "pardefault"); } } @@ -292,13 +296,14 @@ AttrTemplate_Set($$@) return "". "". - "

Specify the unknown parameters for $name/$entry:

". + "

Need the following parameters for the attrTemplate $entry


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