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:
parent
89fadfaa37
commit
accb230ae1
@ -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($$)
|
||||||
|
@ -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 <classname>=<filename>.
|
||||||
|
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>
|
||||||
|
Loading…
Reference in New Issue
Block a user