mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
fhem.pl: attr: add -a and -r Options (Forum #83414)
git-svn-id: https://svn.fhem.de/fhem/trunk@16017 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
b2043fa3fc
commit
0bf933410d
@ -675,7 +675,7 @@ The following local attributes are used by a wider range of devices:
|
|||||||
<a name="attr"></a>
|
<a name="attr"></a>
|
||||||
<h3>attr</h3>
|
<h3>attr</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<code>attr <devspec> <attrname> [<value>] </code><br>
|
<code>attr [-a|-r] <devspec> <attrname> [<value>]</code><br>
|
||||||
|
|
||||||
<br>Set an attribute for a device defined by <a href="#define">define</a>.
|
<br>Set an attribute for a device defined by <a href="#define">define</a>.
|
||||||
You can define your own <a href="#attributes">attributes</a> too to use them
|
You can define your own <a href="#attributes">attributes</a> too to use them
|
||||||
@ -685,19 +685,27 @@ The following local attributes are used by a wider range of devices:
|
|||||||
See the <a href="#devspec">Device specification</a> section for details on
|
See the <a href="#devspec">Device specification</a> section for details on
|
||||||
<devspec>.
|
<devspec>.
|
||||||
After setting the attribute, the global event "ATTR" will be generated.
|
After setting the attribute, the global event "ATTR" will be generated.
|
||||||
<br><br>
|
<br>
|
||||||
|
If the option -a is specified, append the given value to the currently
|
||||||
|
existing value. Note: if the value does not start with a comma (,), then a
|
||||||
|
space will be added automatically to the old value before appending the
|
||||||
|
new.<br>
|
||||||
|
With the -r option one can remove a part of an attribute value.<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
<ul>
|
<ul><code>
|
||||||
<code>attr global verbose 3</code><br>
|
attr global verbose 3<br>
|
||||||
<code>attr lamp room kitchen</code><br>
|
attr lamp room kitchen<br>
|
||||||
<code>attr lamp group lights</code><br>
|
attr lamp group lights<br>
|
||||||
<code>attr lamp loglevel 6</code><br>
|
attr lamp loglevel 6<br>
|
||||||
<code>attr weatherstation event-on-update-reading wind,temperature,humidity</code><br>
|
attr weatherstation event-on-update-reading wind,temperature,humidity<br>
|
||||||
<code>attr weatherstation event-on-change-reading israining</code><br>
|
attr weatherstation event-on-change-reading israining<br>
|
||||||
<code>attr weatherstation event-on-change-reading israining,state</code><br>
|
attr weatherstation event-on-change-reading israining,state<br>
|
||||||
<code>attr heating stateFormat Temp:measured-temp, Valve:actuator</code><br>
|
attr heating stateFormat Temp:measured-temp, Valve:actuator<br>
|
||||||
</ul>
|
attr -a TYPE=SVG room ,SvgRoom</br>
|
||||||
|
attr -r TYPE=SVG room ,SvgRoom</br>
|
||||||
|
</code></ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
Notes:<br>
|
Notes:<br>
|
||||||
|
@ -685,7 +685,7 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
|||||||
<a name="attr"></a>
|
<a name="attr"></a>
|
||||||
<h3>attr</h3>
|
<h3>attr</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<code>attr <devspec> <attrname> [<value>] </code><br>
|
<code>attr [-a|-r] <devspec> <attrname> [<value>]</code><br>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
Dieser Befehl setzt ein Attribut für ein Gerät welches mit <a
|
Dieser Befehl setzt ein Attribut für ein Gerät welches mit <a
|
||||||
@ -702,17 +702,26 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
|||||||
Nach der Durchführung das globale Ereignis "ATTR" wird generiert.
|
Nach der Durchführung das globale Ereignis "ATTR" wird generiert.
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
Falls die Option -a spezifiziert ist, dann wird value zum aktuellen Wert
|
||||||
|
hinzugefügt. Achtung: falls value nicht mit einem Komma (,)
|
||||||
|
anfängt, dann wird es mit einem Leerzeichen angehängt.
|
||||||
|
<br>
|
||||||
|
Mit der -r Option kann man Teile eines Attributes wieder entfernen.<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
Beispiele:
|
Beispiele:
|
||||||
<ul>
|
<ul><code>
|
||||||
<code>attr global verbose 3</code><br>
|
attr global verbose 3<br>
|
||||||
<code>attr lamp room kitchen</code><br>
|
attr lamp room kitchen<br>
|
||||||
<code>attr lamp group lights</code><br>
|
attr lamp group lights<br>
|
||||||
<code>attr lamp loglevel 6</code><br>
|
attr lamp loglevel 6<br>
|
||||||
<code>attr weatherstation event-on-update-reading wind,temperature,humidity</code><br>
|
attr weatherstation event-on-update-reading wind,temperature,humidity<br>
|
||||||
<code>attr weatherstation event-on-change-reading israining</code><br>
|
attr weatherstation event-on-change-reading israining<br>
|
||||||
<code>attr weatherstation event-on-change-reading israining,state</code><br>
|
attr weatherstation event-on-change-reading israining,state<br>
|
||||||
<code>attr heating stateFormat Temp:measured-temp, Valve:actuator</code><br>
|
attr heating stateFormat Temp:measured-temp, Valve:actuator<br>
|
||||||
</ul>
|
attr -a TYPE=SVG room ,SvgRoom</br>
|
||||||
|
attr -r TYPE=SVG room ,SvgRoom</br>
|
||||||
|
</code></ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
Bemerkungen:<br>
|
Bemerkungen:<br>
|
||||||
|
47
fhem/fhem.pl
47
fhem/fhem.pl
@ -2668,11 +2668,13 @@ sub
|
|||||||
CommandAttr($$)
|
CommandAttr($$)
|
||||||
{
|
{
|
||||||
my ($cl, $param) = @_;
|
my ($cl, $param) = @_;
|
||||||
my ($ret, @a);
|
my ($ret, $append, $remove, @a);
|
||||||
|
|
||||||
|
$append = ($param =~ s/^-a //);
|
||||||
|
$remove = ($param =~ s/^-r //);
|
||||||
@a = split(" ", $param, 3) if($param);
|
@a = split(" ", $param, 3) if($param);
|
||||||
|
|
||||||
return "Usage: attr <name> <attrname> [<attrvalue>]\n$namedef"
|
return "Usage: attr [-a|-r] <name> <attrname> [<attrvalue>]\n$namedef"
|
||||||
if(@a && @a < 2);
|
if(@a && @a < 2);
|
||||||
|
|
||||||
my @rets;
|
my @rets;
|
||||||
@ -2680,6 +2682,7 @@ CommandAttr($$)
|
|||||||
|
|
||||||
my $hash = $defs{$sdev};
|
my $hash = $defs{$sdev};
|
||||||
my $attrName = $a[1];
|
my $attrName = $a[1];
|
||||||
|
my $attrVal = $a[2];
|
||||||
if(!defined($hash)) {
|
if(!defined($hash)) {
|
||||||
push @rets, "Please define $sdev first" if($init_done);#define -ignoreErr
|
push @rets, "Please define $sdev first" if($init_done);#define -ignoreErr
|
||||||
next;
|
next;
|
||||||
@ -2710,15 +2713,25 @@ CommandAttr($$)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($attrName eq 'disable' and $a[2] && $a[2] eq 'toggle') {
|
if($append && $attrVal && $attr{$sdev} && $attr{$sdev}{$attrName}) {
|
||||||
$a[2] = IsDisabled($sdev) ? 0 : 1;
|
$attrVal = $attr{$sdev}{$attrName} .
|
||||||
|
($attrVal =~ m/^,/ ? $attrVal : " $attrVal");
|
||||||
|
}
|
||||||
|
if($remove && $attrVal && $attr{$sdev} && $attr{$sdev}{$attrName}) {
|
||||||
|
my $v = $attr{$sdev}{$attrName};
|
||||||
|
$v =~ s/\s*$attrVal\s*//;
|
||||||
|
$attrVal = $v;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($attrName eq 'disable' and $attrVal && $attrVal eq 'toggle') {
|
||||||
|
$attrVal = IsDisabled($sdev) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($attrName eq "userReadings") {
|
if($attrName eq "userReadings") {
|
||||||
|
|
||||||
my @userReadings;
|
my @userReadings;
|
||||||
# myReading1[:trigger1] [modifier1] { codecodecode1 }, ...
|
# myReading1[:trigger1] [modifier1] { codecodecode1 }, ...
|
||||||
my $arg= $a[2];
|
my $arg= $attrVal;
|
||||||
|
|
||||||
# matches myReading1[:trigger2] { codecode1 }
|
# matches myReading1[:trigger2] { codecode1 }
|
||||||
my $regexi= '\s*([\w.-]+)(:\S*)?\s+((\w+)\s+)?({.*?})\s*';
|
my $regexi= '\s*([\w.-]+)(:\S*)?\s+((\w+)\s+)?({.*?})\s*';
|
||||||
@ -2755,7 +2768,7 @@ CommandAttr($$)
|
|||||||
if($attrName eq "eventMap") {
|
if($attrName eq "eventMap") {
|
||||||
delete $hash->{".eventMapHash"};
|
delete $hash->{".eventMapHash"};
|
||||||
delete $hash->{".eventMapCmd"};
|
delete $hash->{".eventMapCmd"};
|
||||||
$attr{$sdev}{eventMap} = (defined $a[2] ? $a[2] : 1);
|
$attr{$sdev}{eventMap} = (defined $attrVal ? $attrVal : 1);
|
||||||
my $r = ReplaceEventMap($sdev, "test", 1); # refresh eventMapCmd
|
my $r = ReplaceEventMap($sdev, "test", 1); # refresh eventMapCmd
|
||||||
if($r =~ m/^ERROR in eventMap for /) {
|
if($r =~ m/^ERROR in eventMap for /) {
|
||||||
delete($attr{$sdev}{eventMap});
|
delete($attr{$sdev}{eventMap});
|
||||||
@ -2773,11 +2786,11 @@ CommandAttr($$)
|
|||||||
pv=>{"%name"=>1, "%state"=>1, "%type"=>1} },
|
pv=>{"%name"=>1, "%state"=>1, "%type"=>1} },
|
||||||
);
|
);
|
||||||
|
|
||||||
if(defined($a[2]) && $ra{$attrName} && $init_done) {
|
if(defined($attrVal) && $ra{$attrName} && $init_done) {
|
||||||
my ($lval,$rp) = ($a[2], $ra{$attrName}{p});
|
my ($lval,$rp) = ($attrVal, $ra{$attrName}{p});
|
||||||
|
|
||||||
if($rp && $lval =~ m/$rp/) {
|
if($rp && $lval =~ m/$rp/) {
|
||||||
my $err = perlSyntaxCheck($a[2], %{$ra{$attrName}{pv}});
|
my $err = perlSyntaxCheck($attrVal, %{$ra{$attrName}{pv}});
|
||||||
return "attr $sdev $a[1]: $err" if($err);
|
return "attr $sdev $a[1]: $err" if($err);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -2792,8 +2805,8 @@ CommandAttr($$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($fhemdebug && $sdev eq "global") {
|
if($fhemdebug && $sdev eq "global") {
|
||||||
$a[2] = "-" if($attrName eq "logfile");
|
$attrVal = "-" if($attrName eq "logfile");
|
||||||
$a[2] = 5 if($attrName eq "verbose");
|
$attrVal = 5 if($attrName eq "verbose");
|
||||||
}
|
}
|
||||||
$ret = CallFn($sdev, "AttrFn", "set", @a);
|
$ret = CallFn($sdev, "AttrFn", "set", @a);
|
||||||
if($ret) {
|
if($ret) {
|
||||||
@ -2801,27 +2814,27 @@ CommandAttr($$)
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $val = $a[2];
|
my $val = $attrVal;
|
||||||
$val = 1 if(!defined($val));
|
$val = 1 if(!defined($val));
|
||||||
$attr{$sdev}{$attrName} = $val;
|
$attr{$sdev}{$attrName} = $val;
|
||||||
|
|
||||||
if($attrName eq "IODev") {
|
if($attrName eq "IODev") {
|
||||||
if(!$a[2] || !defined($defs{$a[2]})) {
|
if(!$attrVal || !defined($defs{$attrVal})) {
|
||||||
if($init_done) {
|
if($init_done) {
|
||||||
push @rets,"$sdev: unknown IODev $a[2] specified";
|
push @rets,"$sdev: unknown IODev $attrVal specified";
|
||||||
} else {
|
} else {
|
||||||
$hash->{IODevMissing} = 1;
|
$hash->{IODevMissing} = 1;
|
||||||
$hash->{IODevName} = $a[2];
|
$hash->{IODevName} = $attrVal;
|
||||||
}
|
}
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $ioname = $a[2];
|
my $ioname = $attrVal;
|
||||||
$hash->{IODev} = $defs{$ioname};
|
$hash->{IODev} = $defs{$ioname};
|
||||||
delete($defs{$ioname}{".clientArray"}); # Force a recompute
|
delete($defs{$ioname}{".clientArray"}); # Force a recompute
|
||||||
}
|
}
|
||||||
if($attrName eq "stateFormat" && $init_done) {
|
if($attrName eq "stateFormat" && $init_done) {
|
||||||
my $err = perlSyntaxCheck($a[2], ("%name"=>""));
|
my $err = perlSyntaxCheck($attrVal, ("%name"=>""));
|
||||||
return $err if($err);
|
return $err if($err);
|
||||||
evalStateFormat($hash);
|
evalStateFormat($hash);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user