From 6b15f9f7e49e98b817599a47656f6277caab0604 Mon Sep 17 00:00:00 2001 From: neubert Date: Fri, 4 Feb 2011 21:19:35 +0000 Subject: [PATCH] Attribute classdefs added to ECMDDevice to allow for persistence of class definition in the config file by means of the save command. git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@823 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/66_ECMD.pm | 69 ++++++++++++++++++++++++++++++++++---------- docs/commandref.html | 15 ++++++++-- 2 files changed, 67 insertions(+), 17 deletions(-) diff --git a/FHEM/66_ECMD.pm b/FHEM/66_ECMD.pm index 8ca7099c0..250160987 100644 --- a/FHEM/66_ECMD.pm +++ b/FHEM/66_ECMD.pm @@ -44,7 +44,8 @@ ECMD_Initialize($) $hash->{UndefFn} = "ECMD_Undef"; $hash->{GetFn} = "ECMD_Get"; $hash->{SetFn} = "ECMD_Set"; - $hash->{AttrList}= "loglevel:0,1,2,3,4,5"; + $hash->{AttrFn} = "ECMD_Attr"; + $hash->{AttrList}= "classdefs loglevel:0,1,2,3,4,5"; } ##################################### @@ -431,19 +432,10 @@ ECMD_Get($@) ##################################### sub -ECMD_Set($@) +ECMD_EvalClassDef($$$) { - my ($hash, @a) = @_; - my $name = $a[0]; - - # usage check - my $usage= "Usage: set $name classdef "; - return $usage if(@a != 4); - return $usage if($a[1] ne "classdef"); - - # from the definition - my $classname= $a[2]; - my $filename= $a[3]; + my ($hash, $classname, $filename)=@_; + my $name= $hash->{NAME}; # refuse overwriting existing definitions if(defined($hash->{fhem}{classDefs}{$classname})) { @@ -526,11 +518,58 @@ ECMD_Set($@) } } - $hash->{READINGS}{$a[1]}{VAL} = "$classname $filename"; - $hash->{READINGS}{$a[1]}{TIME} = TimeNow(); + # store class definitions in attribute + $attr{$name}{classdefs}= ""; + my @a; + foreach my $c (keys %{$hash->{fhem}{classDefs}}) { + push @a, "$c=$hash->{fhem}{classDefs}{$c}{filename}"; + } + $attr{$name}{"classdefs"}= join(":", @a); + return undef; } +##################################### +sub +ECMD_Attr($@) +{ + + my @a = @_; + my $hash= $defs{$a[1]}; + + if($a[0] eq "set" && $a[2] eq "classdefs") { + my @classdefs= split(/:/,$a[3]); + delete $hash->{fhem}{classDefs}; + + foreach my $classdef (@classdefs) { + my ($classname,$filename)= split(/=/,$classdef,2); + ECMD_EvalClassDef($hash, $classname, $filename); + } + } + + return undef; +} + + +##################################### +sub +ECMD_Set($@) +{ + my ($hash, @a) = @_; + my $name = $a[0]; + + # usage check + my $usage= "Usage: set $name classdef "; + return $usage if(@a != 4); + return $usage if($a[1] ne "classdef"); + + # from the definition + my $classname= $a[2]; + my $filename= $a[3]; + + return ECMD_EvalClassDef($hash, $classname, $filename); +} + ##################################### sub ECMD_Write($$) diff --git a/docs/commandref.html b/docs/commandref.html index 4529a8741..b63421202 100644 --- a/docs/commandref.html +++ b/docs/commandref.html @@ -2331,7 +2331,7 @@ A line ending with \ will be concatenated with the next one, so long lines send a list of "raw" commands. The first command will be immediately sent, the next one after the previous one is acked by the target. The length will be computed automatically, and the message counter will be - incremented if the first tw charcters are ++. + incremented if the first tw charcters are ++. Example (enable AES):
    set hm1 raw ++A001F100001234560105000000001\
                ++A001F10000123456010802010AF10B000C00\
@@ -3115,7 +3115,7 @@ A line ending with \ will be concatenated with the next one, so long lines
       button = pwr
       config = IrPower
     end
- and you press the pwr button the IrPower toggle event occures at fhem. + and you press the pwr button the IrPower toggle event occures at fhem.
     define IrPower01 notify IrPower set lamp toggle
turns the lamp on and off. @@ -3725,6 +3725,17 @@ Attributes:


+ + Attributes +

+
    +
  • classdefs
    A colon-separated list of <classname>=<filename>. + The list is automatically updated if a class definition is added. You can + directly set the attribute.
  • +
+

+ + Class definition