From 3b2788ed41bb85e3cda6da1e0ac9285c6f575d5c Mon Sep 17 00:00:00 2001 From: martinp876 Date: Tue, 14 Jan 2014 11:59:46 +0000 Subject: [PATCH] add tempList handling git-svn-id: https://svn.fhem.de/fhem/trunk@4642 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_HMinfo.pm | 172 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 3 deletions(-) diff --git a/fhem/FHEM/98_HMinfo.pm b/fhem/FHEM/98_HMinfo.pm index 1de273b21..969f94d4b 100644 --- a/fhem/FHEM/98_HMinfo.pm +++ b/fhem/FHEM/98_HMinfo.pm @@ -262,6 +262,128 @@ sub HMinfo_paramCheck(@) { #################################################### $ret .="\n\n PairedTo missmatch to IODev"."\n ".(join "\n ",sort @idMismatch) if (@idMismatch); return $ret; } +sub HMinfo_tempList(@) { ###################################################### + my ($action,$fName)=@_; + $fName = "tempList.cfg" if (!$fName); + $action = "save" if (!$action); + my $ret; + if ($action eq "save"){ + open(aSave, ">$fName") || return("Can't open $fName: $!"); + my @incmpl; + foreach my $eN(HMinfo_getEntities("d")){#search for devices and select correct channel + my $md = AttrVal($eN,"model",""); + my $chN; #tempList channel name + if ($md =~ m/(HM-CC-RT-DN-BoM|HM-CC-RT-DN)/){ + $chN = $defs{$eN}{channel_04}; + } + elsif ($md =~ m/(ROTO_ZEL-STG-RM-FWT|HM-CC-TC)/){ + $chN = $defs{$eN}{channel_02}; + } + next if (!$chN || !$defs{$chN} ); + print aSave "\nentities:$chN"; + my @tl = sort grep /tempList[SMFWT]/,keys %{$defs{$chN}{READINGS}}; + if (scalar@tl != 7){ + print aSave "\nincomplete:$chN only data for ".join(",",@tl); + push @incmpl,$chN; + next; + } + foreach my $rd (@tl){ + print aSave "\n$rd>$defs{$chN}{READINGS}{$rd}{VAL}"; + } + } + print aSave "\n======= finished ===\n"; + close(aSave); + $ret = "incomplete data for ".join("\n ",@incmpl) if (scalar@incmpl); + } + elsif ($action eq "verify"){ + open(aSave, "$fName") || return("Can't open $fName: $!"); + my @el = (); + my @elAll = (); + my @entryFail = (); + my @entryNF = (); + while(){ + chomp; + if($_ =~ m/^entities:/){ + my $line = $_; + $line =~s/.*://; + @el = (); + foreach (split(",",$line)){ + if ($defs{$_}){ + push @el,$_ if ($defs{$_}); + } + else{ + push @entryNF,$_; + } + } + push @elAll,@el; + } + elsif(@el && $_ =~ m/tempList[SMFWT].*\>/){ + my ($tln,$val) = ($1,$2)if($_ =~ m/(.*)>(.*)/); + $tln =~ s/ //g; + $val =~ s/ //g; + foreach my $eN(@el){ + my $valR = ReadingsVal($eN,$tln,""); + $valR =~ s/ //g; + push @entryFail,$eN." :".$tln if ($valR ne $val); + } + } + } + $ret .= "\nentries tested:\n " .join("\n ",@elAll) if (scalar@elAll); + $ret .= "\nfailed verify:\n " .join("\n ",@entryFail) if (scalar@entryFail); + $ret .= "\nentries not found:\n ".join("\n ",@entryNF) if (scalar@entryNF); + } + elsif ($action eq "restore"){ + open(aSave, "$fName") || return("Can't open $fName: $!"); + my @el = (); + my @elAll = (); + my @entryFail = (); + my @entryNF = (); + my @exec = (); + while(){ + chomp; + if($_ =~ m/^entities:/){ + my $line = $_; + $line =~s/.*://; + @el = (); + foreach (split(",",$line)){ + if ($defs{$_}){ + push @el,$_ if ($defs{$_}); + } + else{ + push @entryNF,$_; + } + } + foreach (@exec){ + my @param = split(" ",$_); + CUL_HM_Set($defs{$param[0]},@param); + } + push @elAll,@el; + } + elsif(@el && $_ =~ m/tempList[SMFWT].*\>/){ + my ($tln,$val) = ($1,$2)if($_ =~ m/(.*)>(.*)/); + $tln =~ s/ //g; + $val =~ tr/ +/ /; + $val =~ s/^ //; + $val =~ s/ $//; + @exec = (); + foreach my $eN(@el){ + my $x = CUL_HM_Set($defs{$eN},$eN,$tln,"prep",split(" ",$val)); + push @entryFail,$eN." :".$tln." respose:$x" if ($x != 1); + push @exec,$eN." ".$tln." exec ".$val; + } + } + } + foreach (@exec){ + my @param = split(" ",$_); + CUL_HM_Set($defs{$param[0]},@param); + } + + $ret = "failed Entries:\n " .join("\n ",@entryFail) if (scalar@entryFail); + $ret = "Entries not found:\n ".join("\n ",@entryNF) if (scalar@entryNF); + } + + return $ret; +} sub HMinfo_getEntities(@) { ################################################### my ($filter,$re) = @_; @@ -273,9 +395,9 @@ sub HMinfo_getEntities(@) { ################################################### $re = '.' if (!$re); if ($filter){# options provided $doDev=$doChn=$doEmp= 0;#change default -no warnings; - my @pl = split undef,$filter; -use warnings; + no warnings; + my @pl = split undef,$filter; + use warnings; foreach (@pl){ $doDev = 1 if($_ eq 'd'); $doChn = 1 if($_ eq 'c'); @@ -663,6 +785,9 @@ sub HMinfo_SetFn($@) {######################################################### elsif($cmd eq "update") {##update hm counts ----------------------------- $ret = HMinfo_status($hash); } + elsif($cmd eq "tempList") {##update hm counts ----------------------------- + $ret = HMinfo_tempList(@a); + } elsif($cmd eq "help") { $ret = " Unknown argument $cmd, choose one of " ."\n ---checks---" @@ -672,6 +797,7 @@ sub HMinfo_SetFn($@) {######################################################### ."\n ---actions---" ."\n saveConfig [] # stores peers and register with saveConfig" ."\n autoReadReg [] # trigger update readings if attr autoReadReg is set" + ."\n tempList [save|restore|verify][filename] # handle tempList of thermostat devices" ."\n ---infos---" ."\n update # update HMindfo counts" ."\n register [] # devicefilter parse devicename. Partial strings supported" @@ -1393,6 +1519,46 @@ sub HMinfo_noDup(@) {#return list with no duplicates performs a save for all HM register setting and peers. See CUL_HM saveConfig.
+
  • tempList [save|restore|verify] [filename]
    + this function supports handling of tempList for thermstates. + It allows templists to be saved in a separate file, verify settings against the file + and write the templist of the file to the devices.
    +
  • save saves tempList readings of the system to the file.
    + Note that templist as available in FHEM is put to the file. It is up to the user to make + sure the data is actual
    + Storage is not cumulative - former content of the file will be removed
  • +
  • restore available templist as defined in the file is written directly + to the device
  • +
  • verify file data is compared to readings as present in FHEM. It does not + verify data in the device - user needs to ensure actuallity on the readings
  • +
    +
  • filename is the name of the file to be used. Default ist tempList.cfg
  • + File example
    +
      + entities:HK1_Climate,HK2_Clima
      + tempListFri>07:00 14.0 13:00 16.0 16:00 18.0 21:00 19.0 24:00 14.0
      + tempListMon>07:00 14.0 16:00 18.0 21:00 19.0 24:00 14.0
      + tempListSat>08:00 14.0 15:00 18.0 21:30 19.0 24:00 14.0
      + tempListSun>08:00 14.0 15:00 18.0 21:30 19.0 24:00 14.0
      + tempListThu>07:00 14.0 16:00 18.0 21:00 19.0 24:00 14.0
      + tempListTue>07:00 14.0 13:00 16.0 16:00 18.0 21:00 19.0 24:00 15.0
      + tempListWed>07:00 14.0 16:00 18.0 21:00 19.0 24:00 14.0
      + entities:hk3_Climate
      + tempListFri>06:00 17.0 12:00 21.0 23:00 20.0 24:00 19.5
      + tempListMon>06:00 17.0 12:00 21.0 23:00 20.0 24:00 17.0
      + tempListSat>06:00 17.0 12:00 21.0 23:00 20.0 24:00 17.0
      + tempListSun>06:00 17.0 12:00 21.0 23:00 20.0 24:00 17.0
      + tempListThu>06:00 17.0 12:00 21.0 23:00 20.0 24:00 17.0
      + tempListTue>06:00 17.0 12:00 21.0 23:00 20.0 24:00 17.0
      + tempListWed>06:00 17.0 12:00 21.0 23:00 20.0 24:00 17.0
      +
    + File keywords
    +
  • entities comma separated list of entities which refers to the teml lists following
  • +
  • tempList... time and temp couples as used in the set tempList commands
  • +
    + + +
  • cpRegs <src:peer> <dst:peer>
    allows to copy register, setting and behavior of a channel to another or for peers from the same or different channels. Copy therefore is allowed