2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

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://svn.fhem.de/fhem/trunk@823 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2011-02-04 21:19:35 +00:00
parent 89fadfaa37
commit accb230ae1
2 changed files with 67 additions and 17 deletions

View File

@ -44,7 +44,8 @@ ECMD_Initialize($)
$hash->{UndefFn} = "ECMD_Undef"; $hash->{UndefFn} = "ECMD_Undef";
$hash->{GetFn} = "ECMD_Get"; $hash->{GetFn} = "ECMD_Get";
$hash->{SetFn} = "ECMD_Set"; $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 sub
ECMD_Set($@) ECMD_EvalClassDef($$$)
{ {
my ($hash, @a) = @_; my ($hash, $classname, $filename)=@_;
my $name = $a[0]; my $name= $hash->{NAME};
# usage check
my $usage= "Usage: set $name classdef <classname> <filename> ";
return $usage if(@a != 4);
return $usage if($a[1] ne "classdef");
# from the definition
my $classname= $a[2];
my $filename= $a[3];
# refuse overwriting existing definitions # refuse overwriting existing definitions
if(defined($hash->{fhem}{classDefs}{$classname})) { if(defined($hash->{fhem}{classDefs}{$classname})) {
@ -526,11 +518,58 @@ ECMD_Set($@)
} }
} }
$hash->{READINGS}{$a[1]}{VAL} = "$classname $filename"; # store class definitions in attribute
$hash->{READINGS}{$a[1]}{TIME} = TimeNow(); $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; 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 <classname> <filename> ";
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 sub
ECMD_Write($$) ECMD_Write($$)

View File

@ -3725,6 +3725,17 @@ Attributes:<br>
</ul> </ul>
<br><br> <br><br>
<a name="M232attr"></a>
<b>Attributes</b>
<br><br>
<ul>
<li>classdefs<br>A colon-separated list of &lt;classname&gt;=&lt;filename&gt;.
The list is automatically updated if a class definition is added. You can
directly set the attribute.</li>
</ul>
<br><br>
<a name="ECMDClassdef"></a> <a name="ECMDClassdef"></a>
<b>Class definition</b> <b>Class definition</b>
<br><br> <br><br>