mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 04:36:36 +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->{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 <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];
|
||||
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 <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
|
||||
ECMD_Write($$)
|
||||
|
@ -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):<pre>
|
||||
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</pre>
|
||||
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.
|
||||
<pre>
|
||||
define IrPower01 notify IrPower set lamp toggle</pre>
|
||||
turns the lamp on and off.
|
||||
@ -3725,6 +3725,17 @@ Attributes:<br>
|
||||
</ul>
|
||||
<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>
|
||||
<b>Class definition</b>
|
||||
<br><br>
|
||||
|
Loading…
x
Reference in New Issue
Block a user