98_HMtemplate:improve non-peer templates

git-svn-id: https://svn.fhem.de/fhem/trunk@15459 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
martinp876 2017-11-19 18:21:41 +00:00
parent cfa66a138d
commit 22321540da

View File

@ -191,6 +191,7 @@ sub HMtemplate_Attr(@) {#######################################################
} }
elsif($attrName eq "tpl_entity"){# used with select option elsif($attrName eq "tpl_entity"){# used with select option
if ($cmd eq "set"){ if ($cmd eq "set"){
return "entity:$attrVal not defined" if(!defined $defs{$attrVal});
$attr{$name}{tpl_ePeer} = ""; $attr{$name}{tpl_ePeer} = "";
if($hash->{tpl_type} eq "basic"){# we dont need peer - import now if($hash->{tpl_type} eq "basic"){# we dont need peer - import now
} }
@ -200,9 +201,25 @@ sub HMtemplate_Attr(@) {#######################################################
$modules{HMtemplate}{AttrList} =~ s/tpl_ePeer.*?( |$)//; $modules{HMtemplate}{AttrList} =~ s/tpl_ePeer.*?( |$)//;
$modules{HMtemplate}{AttrList} .=" tpl_ePeer:$peerList"; $modules{HMtemplate}{AttrList} .=" tpl_ePeer:$peerList";
} }
############ set attr param from device if selected
if(ReadingsVal($hash->{NAME},"state","") eq "select"){# do we have to set params?
my $dh = $defs{$attrVal};
my ($tName,$tType) = (InternalVal($name,"tpl_Name",""),InternalVal($name,"tpl_type",""));
if ( $tType eq "basic"){ #we have enough to prefill parameter
my @pN = split(" ",$culHmTpl->{$tName}{p});## get param Names template
my @pD ;
@pD = split(" ",$dh->{helper}{tmpl}{"0>$tName"})
if( defined $dh->{helper}{tmpl}
&& defined $dh->{helper}{tmpl}{"0>$tName"});
for (my $cnt = 0;$cnt < scalar(@pN); $cnt++){
$attr{$name}{"tpl_param_$pN[$cnt]"} = defined $pD[$cnt] ? $pD[$cnt] : "";
}
}
}
} }
else{ else{
$attr{$name}{"tpl_ePeer"} = ""; $attr{$name}{tpl_ePeer} = "";
$modules{HMtemplate}{AttrList} =~ s/ tpl_ePeer.*?\ / tpl_ePeer/; $modules{HMtemplate}{AttrList} =~ s/ tpl_ePeer.*?\ / tpl_ePeer/;
} }
} }
@ -385,8 +402,8 @@ sub HMtemplate_SetFn($@) {#####################################################
$_ = $attr{$name}{"tpl_param_$_"} foreach (@p); $_ = $attr{$name}{"tpl_param_$_"} foreach (@p);
return HMinfo_templateSet( $attr{$name}{tpl_entity} return HMinfo_templateSet( $attr{$name}{tpl_entity}
,$hash->{tpl_Name} ,$hash->{tpl_Name}
,($hash->{tpl_type} eq "basic"?"none" ,($hash->{tpl_type} eq "basic" ? "0"
:$attr{$name}{tpl_ePeer}.":".AttrVal($name,"tpl_eType","both"))# type either long/short/both : $attr{$name}{tpl_ePeer}.":".AttrVal($name,"tpl_eType","both"))# type either long/short/both
,@p ,@p
); );
} }