From 0696f44fea6b1d34bc5eb33e6a1cc3c03fe7f929 Mon Sep 17 00:00:00 2001
From: martinp876 <>
Date: Fri, 13 Apr 2018 18:00:46 +0000
Subject: [PATCH] HMtemplate:introduce unassign - rename apply to assign
git-svn-id: https://svn.fhem.de/fhem/trunk@16604 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/98_HMtemplate.pm | 64 ++++++++++++++++++--------------------
1 file changed, 31 insertions(+), 33 deletions(-)
diff --git a/fhem/FHEM/98_HMtemplate.pm b/fhem/FHEM/98_HMtemplate.pm
index 853a50505..cc277ca7c 100644
--- a/fhem/FHEM/98_HMtemplate.pm
+++ b/fhem/FHEM/98_HMtemplate.pm
@@ -17,11 +17,11 @@ sub HMtemplate_noDup(@);
use Blocking;
use HMConfig;
my %HtState =(
- s0=>{name=>"init" ,cmd=>["select" ,"defTmpl","delete","edit"] ,info=>[ "delete to remove a template definition"
+ s0=>{name=>"init" ,cmd=>["select" ,"defTmpl","delete","edit"] ,info=>[ "delete to unassign a template definition"
,"defTmpl to greate a template"
,"- use an entity as default"
,"edit to modify a template definition"
- ,"select to apply a template to a entity"
+ ,"select to assign a template to a entity"
]}
,s1=>{name=>"edit" ,cmd=>["dismiss","save" ,"saveAs","importReg"] ,info=>[ "change attr Reg_ as desired"
,"change attr tpl_params ':' separated"
@@ -29,7 +29,7 @@ my %HtState =(
,"saveAs to create a copy"
,"dismiss will reset HMtemplate"
]}
- ,s2=>{name=>"defTmpl",cmd=>["dismiss","save","saveAs"] ,info=>[ "1)set attr tpl_type"
+ ,s2=>{name=>"defTmpl",cmd=>["dismiss","save" ,"saveAs"] ,info=>[ "1)set attr tpl_type"
,"2)set attr tpl_source"
,"3)set attr tpl_peer if peer required"
,"4)set attr tpl_params ':' separated"
@@ -37,12 +37,12 @@ my %HtState =(
]}
,s3=>{name=>"defTmpl",cmd=>["defTmpl","edit" ,"delete"] ,info=>[ "delete"
]}
- ,s4=>{name=>"select" ,cmd=>["dismiss","apply" ,"select"] ,info=>[ "apply the selected template to an entity"
+ ,s4=>{name=>"select" ,cmd=>["dismiss","assign" ,"select","unassign"] ,info=>[ "assign/unassign the selected template to an entity"
,"1) choose target entity"
,"2) select a peer if required"
,"3) select type if required"
,"4) fill all attr tpl_param_"
- ,"5) set apply to execute and write the register"
+ ,"5) set assign to execute and write the register"
]}
,s5=>{name=>"defTmpl",cmd=>["defTmpl","edit" ,"delete"] ,info=>[ "s5 info1"
,"s5 info2"
@@ -269,7 +269,7 @@ sub HMtemplate_GetFn($@) {#####################################################
return "template unknown $tN" if(!defined $culHmTpl->{$tN});
return "set hm templateDef $tN "
- .join(":",split(" ",$culHmTpl->{$tN}{p}))
+ .join(":",split(" ",($culHmTpl->{$tN}{p} ? $culHmTpl->{$tN}{p} : "0")))
." \"$culHmTpl->{$tN}{t}\""
." ".join(" ",map{$_.=":".$culHmTpl->{$tN}{reg}{$_}} keys %{$culHmTpl->{$tN}{reg}})
;
@@ -399,7 +399,7 @@ sub HMtemplate_SetFn($@) {#####################################################
}
}
}
- elsif ($cmd eq "apply" ) {#
+ elsif ($cmd eq "assign" ) {#
my @p = split(" ",$culHmTpl->{$hash->{tpl_Name}}{p});## get params in correct order
$_ = $attr{$name}{"tpl_param_$_"} foreach (@p);
return HMinfo_templateSet( $attr{$name}{tpl_entity}
@@ -409,6 +409,13 @@ sub HMtemplate_SetFn($@) {#####################################################
,@p
);
}
+ elsif ($cmd eq "unassign" ) {# General - still open
+ my ($entityName,$entityPeer) = split(";",$a[0]);
+
+ return HMinfo_templateDel( $entityName
+ ,$hash->{tpl_Name}
+ ,$entityPeer);
+ }
elsif ($cmd eq "importReg" ){#
my ($eName) = @a;
@@ -419,27 +426,6 @@ sub HMtemplate_SetFn($@) {#####################################################
return "template not assigned to $eName" if (scalar(@fnd) != 1);
HMtemplate_import($name,$eName,InternalVal($name,"tpl_type",""),InternalVal($name,"tpl_peer",""));
-
- # my @fnd = map { $_ =~ s/ .*//g; $_ }
- # map {$hash->{READINGS}{$_}{VAL}}
- # grep /^usage_/,keys %{$hash->{READINGS}};
- # my @reg;
- # my $first = 1;
- # foreach my $d(@fnd){
- # my $dHash = CUL_HM_getDeviceHash($defs{$d});
- # my $st = AttrVal($dHash->{NAME},"subType","");
- # my $md = AttrVal($dHash->{NAME},"model","");
- # my @dr = (CUL_HM_getRegN($st,$md,"01"));
- #
- # if ($first){
- # @reg = @dr;
- # $first = 0;
- # }
- # else{
- # @reg = HMtemplate_intersection(\@reg,\@dr);
- # }
- # }
- # return join("\n",sort @reg);
}
elsif ($cmd eq "edit" ) {#
my ($templ) = @a;
@@ -502,18 +488,25 @@ sub HMtemplate_SetFn($@) {#####################################################
return HMtemplate_save($name,$tName);
}
else{
- #"select","edit","delete", "defTmpl","dismiss","save","saveAs","importReg","apply"]
+ #"select","edit","delete", "defTmpl","dismiss","save","saveAs","importReg","assign"]
my @cmdLst = @{$HtState{${$eSt}}{cmd}};
my $tList = ":".join(",",sort keys%{$culHmTpl});
$_ .=$tList foreach(grep/^(edit|delete|select)$/,@cmdLst);
+
+ $tList = ":". join(",",map{(my $foo = $_) =~ s/^(.*?)\s*\|(.*?)\s*\|.*/$1;$2/;$foo}
+ map{$defs{ht}{READINGS}{$_}{VAL}}
+ grep /^usage/,keys %{$defs{$name}{READINGS}});
+ $tList =~ s/ //g;
+ $_ .= $tList foreach(grep/^(unassign)$/,@cmdLst);
+
if (grep/^importReg$/,@cmdLst){
my @fnd = map { $_ =~ s/ .*//g; $_ }
map {$hash->{READINGS}{$_}{VAL}}
grep /^usage_/,keys %{$hash->{READINGS}};
my $eList = ":".join(",",sort @fnd);
- $_ .=$eList foreach(grep/^(importReg)$/,@cmdLst);
+ $_ .= $eList foreach(grep/^(importReg)$/,@cmdLst);
}
- $_ .=":noArg" foreach(grep/^(save|dismiss|apply)$/,@cmdLst);# no arguments
+ $_ .= ":noArg" foreach(grep/^(save|dismiss|assign)$/,@cmdLst);# no arguments
$ret = "Unknown argument $cmd, choose one of ".join (" ",sort @cmdLst);
}
@@ -621,7 +614,6 @@ sub HMtemplate_setUsageReading($){
if (eval "defined(&HMinfo_templateUsg)" && $hash->{tpl_Name}){
my $tu = HMinfo_templateUsg("","",$hash->{tpl_Name});
$tu =~ s/\|$hash->{tpl_Name}//g;
- $tu =~ s/.\|/|/g;
my $usgCnt = 1;
readingsBeginUpdate($hash);
readingsBulkUpdate($hash,"usage_".$usgCnt++,$_) foreach(split("\n",$tu));
@@ -684,11 +676,17 @@ sub HMtemplate_setUsageReading($){
Apply an existing template to a entity
Once the command is issued it is necessary to select the entity, peer and short/long which the entity shall be applied to.
If the template has parameter the value needs to be set.
- Finally apply the template to teh entity.
+ Finally assign the template to teh entity.