mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
fhem.pl: Replace-Magic replaces now attributes and internals too, just like
devspec (Forum #38276) git-svn-id: https://svn.fhem.de/fhem/trunk@13893 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
730a668eb1
commit
abb6b90e62
@ -1083,10 +1083,11 @@ The following local attributes are used by a wider range of devices:
|
||||
<br><br>
|
||||
From featurelevel 5.7 on the set and setreading command replaces:
|
||||
<ul>
|
||||
<li>[device:reading] with the corresponding reading of device, if both device
|
||||
and reading exists.</li>
|
||||
<li>[device:reading:d] same as above, but only the number is retrieved, see
|
||||
ReadingsNum </li>
|
||||
<li>[device:name] with the reading, internal or attribute of the device, if
|
||||
both device and the reading, internal or attribute exists. You can use the
|
||||
r:, i: or a: prefix to restrict the search to one type, analogue to the
|
||||
devspec filtering.</li>
|
||||
<li>[device:name:d] same as above, but only the number is retrieved</li>
|
||||
<li>{(perlExpression)} with the result of perlExpression.
|
||||
The $DEV variable is additionally available, designating the set device
|
||||
name.
|
||||
@ -1650,6 +1651,14 @@ The following local attributes are used by a wider range of devices:
|
||||
ReadingsNum(<devicename>,<reading>,<defaultvalue>)<br>
|
||||
Return the reading as a number, i.e. delete non-numerical values.
|
||||
</li><br>
|
||||
<li>ReadingsTimestamp(<devicename>,<reading>,<
|
||||
defaultvalue>)<br>
|
||||
returns the timestamp of the reading.
|
||||
</li><br>
|
||||
<li>ReadingsAge(<devicename>,<reading>,<defaultvalue>)
|
||||
<br>
|
||||
returns the age of the reading in seconds.
|
||||
</li><br>
|
||||
<li>
|
||||
AttrVal(<devicename>,<attribute>,<defaultvalue>)<br>
|
||||
Return the attribute of the device
|
||||
|
@ -1151,10 +1151,12 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
<br><br>
|
||||
Ab featurelevel 5.7 ersetzt das set und setreading Befehl
|
||||
<ul>
|
||||
<li>[device:reading] mit dem Wert des Readings für device, falls sowohl
|
||||
device, als auch Reading existiert, und nicht leer ist.</li>
|
||||
<li>[device:reading:d] wie ohne :d, aber alles nicht-numerische wird
|
||||
entfernt, siehe ReadingsNum</li>
|
||||
<li>[device:name] mit dem Wert des Readings, Internals oder Attributes
|
||||
für device, falls sowohl device, als auch Reading, Internal oder
|
||||
Attribut existiert, und nicht leer ist. Man kann einen der Prefixe r:, i:
|
||||
oder a: verwenden, um die Suche einzuschraenken, genau wie im devspec.</li>
|
||||
<li>[device:name:d] wie ohne :d, aber alles nicht-numerische wird
|
||||
entfernt.</li>
|
||||
<li>{(perlExpression)} mit dem Ergebnis der perlExpression.
|
||||
$DEV wird dabei mit dem Namen des vom set betroffenen Gerätes ersetzt.
|
||||
</li>
|
||||
@ -1786,6 +1788,13 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
Wie ReadingsVal, löscht aber alles, was kein Zahl ist, um den Wert
|
||||
bei Berechnungen verwenden zu können.
|
||||
</li><br>
|
||||
<li>ReadingsTimestamp(<devicename>)<br>
|
||||
gibt den Zeitstempel des Readings zurück.
|
||||
</li><br>
|
||||
<li>ReadingsAge(<devicename>,<reading>,<defaultvalue>)
|
||||
<br>
|
||||
gibt das Alter des Readings in Sekunden zurück.
|
||||
</li><br>
|
||||
<li>
|
||||
AttrVal(<devicename>,<attribute>,<defaultvalue>)<br>
|
||||
Gibt die gesetzteb Attribute des Gerätes zurück
|
||||
|
22
fhem/fhem.pl
22
fhem/fhem.pl
@ -1620,10 +1620,24 @@ ReplaceSetMagic($$@) # Forum #38276
|
||||
my $a = join(" ", @_);
|
||||
my $oa = $a;
|
||||
|
||||
$a =~ s/\[([a-z0-9._]+):([a-z0-9._-]+)(:d)?\]/{
|
||||
my $x = $3 ? ReadingsNum($1,$2,"") : ReadingsVal($1,$2,"");
|
||||
$x eq "" ? "[$1:$2".($3?$3:"")."]" : $x
|
||||
}/egi;
|
||||
sub
|
||||
rsmVal($$$$$)
|
||||
{
|
||||
my ($all, $t, $d, $n, $s, $val) = @_;
|
||||
my $hash = $defs{$d};
|
||||
return $all if(!$hash);
|
||||
if(!$t || $t eq "r:") {
|
||||
my $r = $hash->{READINGS};
|
||||
$val = $r->{$n}{VAL} if($r && $r->{$n});
|
||||
}
|
||||
$val = $hash->{$n} if(!defined($val) && (!$t || $t eq "i:"));
|
||||
$val = $attr{$d}{$n} if(!defined($val) && (!$t || $t eq "a:") && $attr{$d});
|
||||
return $all if(!defined($val));
|
||||
$val =~ s/[^-\.\d]//g if($s);
|
||||
return $val;
|
||||
}
|
||||
|
||||
$a=~s/(\[(.:)?([a-z0-9._]+):([a-z0-9._-]+)(:d)?\])/rsmVal($1,$2,$3,$4,$5)/egi;
|
||||
|
||||
$evalSpecials->{'%DEV'} = $hash->{NAME};
|
||||
$a =~ s/{\((.*?)\)}/AnalyzePerlCommand($hash->{CL},$1,1)/egs;
|
||||
|
Loading…
Reference in New Issue
Block a user