mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-12 02:39:57 +00:00
new attribute userReadings
git-svn-id: https://svn.fhem.de/fhem/trunk@2505 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
25da3ea364
commit
9704c53279
@ -370,13 +370,27 @@ A line ending with \ will be concatenated with the next one, so long lines
|
|||||||
<li>If a reading is listed in event-on-update-reading, an update of the
|
<li>If a reading is listed in event-on-update-reading, an update of the
|
||||||
reading creates an event no matter whether the reading is also listed
|
reading creates an event no matter whether the reading is also listed
|
||||||
in event-on-change-reading.</li>
|
in event-on-change-reading.</li>
|
||||||
</ol>
|
</ol><br>
|
||||||
|
|
||||||
</ul>
|
<a name="userReadings"></a>
|
||||||
|
<li>userReadings<br>
|
||||||
|
A comma-separated list of user-defined readings. Each definition has the form
|
||||||
|
<code><reading> { <perl code> }</code>. After a single or bulk
|
||||||
|
readings update, the user-defined readings are set by evaluating the <a href="#perl">
|
||||||
|
perl code</a>
|
||||||
|
<code>{ <perl code> }</code> for all definitions and setting the value of
|
||||||
|
the respective user-defined reading <code><reading></code> to the result.<br><br>
|
||||||
|
Examples:<br>
|
||||||
|
<code>attr myPowerMeter userReadings power { ReadingsVal("myPowerMeter","count.A",0)/1250.0;; }</code><br>
|
||||||
|
<code>attr myMultiMeter userReadings power1 { ReadingsVal("myMultiMeter","count.A",0)/1250.0;; },
|
||||||
|
power2 { ReadingsVal("myMultiMeter","count.B",0)/1250.0;; }</code>
|
||||||
|
</li><br>
|
||||||
|
|
||||||
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
Device specific attributes are documented in the corresponding device section.
|
Device specific attributes are documented in the corresponding device section.
|
||||||
<br>
|
<br><br>
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -380,7 +380,21 @@ Zeilen erstreckende Befehle, indem man keine \ am Zeilenende eingeben muss.</p>
|
|||||||
<li>Wenn ein "reading" in event-on-update-reading aufgeführt ist,
|
<li>Wenn ein "reading" in event-on-update-reading aufgeführt ist,
|
||||||
erzeugt eine Aktualisierung ein Ereignis unabhängig ob das
|
erzeugt eine Aktualisierung ein Ereignis unabhängig ob das
|
||||||
"reading" auch in event-on-change-reading aufgelistet ist.</li>
|
"reading" auch in event-on-change-reading aufgelistet ist.</li>
|
||||||
</ul>
|
</ul><br>
|
||||||
|
|
||||||
|
<a name="userReadings"></a>
|
||||||
|
<li>userReadings<br>
|
||||||
|
A comma-separated list of user-defined readings. Each definition has the form
|
||||||
|
<code><reading> { <perl code> }</code>. After a single or bulk
|
||||||
|
readings update, the user-defined readings are set by evaluating the <a href="#perl">
|
||||||
|
perl code</a>
|
||||||
|
<code>{ <perl code> }</code> for all definitions and setting the value of
|
||||||
|
the respective user-defined reading <code><reading></code> to the result.<br><br>
|
||||||
|
Examples:<br>
|
||||||
|
<code>attr myPowerMeter userReadings power { ReadingsVal("myPowerMeter","count.A",0)/1250.0;; }</code><br>
|
||||||
|
<code>attr myMultiMeter userReadings power1 { ReadingsVal("myMultiMeter","count.A",0)/1250.0;; },
|
||||||
|
power2 { ReadingsVal("myMultiMeter","count.B",0)/1250.0;; }</code>
|
||||||
|
</li><br>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
62
fhem/fhem.pl
62
fhem/fhem.pl
@ -166,7 +166,7 @@ use vars qw(%addNotifyCB); # Used by event enhancers (e.g. avarage)
|
|||||||
|
|
||||||
use vars qw($reread_active);
|
use vars qw($reread_active);
|
||||||
|
|
||||||
my $AttrList = "room group comment alias eventMap";
|
my $AttrList = "room group comment alias eventMap userReadings";
|
||||||
|
|
||||||
my %comments; # Comments from the include files
|
my %comments; # Comments from the include files
|
||||||
my $ipv6; # Using IPV6
|
my $ipv6; # Using IPV6
|
||||||
@ -318,6 +318,17 @@ if(int(@ARGV) == 2) {
|
|||||||
# End of client code
|
# End of client code
|
||||||
###################################################
|
###################################################
|
||||||
|
|
||||||
|
|
||||||
|
###################################################
|
||||||
|
# for debugging
|
||||||
|
sub
|
||||||
|
Debug($) {
|
||||||
|
my $msg= shift;
|
||||||
|
Log 1, "DEBUG>" . $msg;
|
||||||
|
}
|
||||||
|
###################################################
|
||||||
|
|
||||||
|
|
||||||
###################################################
|
###################################################
|
||||||
# Server initialization
|
# Server initialization
|
||||||
doGlobalDef($ARGV[0]);
|
doGlobalDef($ARGV[0]);
|
||||||
@ -1385,6 +1396,12 @@ CommandDeleteAttr($$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$a[0] = $sdev;
|
$a[0] = $sdev;
|
||||||
|
|
||||||
|
if($a[1] eq "userReadings") {
|
||||||
|
Debug "Deleting userReadings for $sdev";
|
||||||
|
delete($defs{$sdev}{fhem}{userReadings});
|
||||||
|
}
|
||||||
|
|
||||||
$ret = CallFn($sdev, "AttrFn", "del", @a);
|
$ret = CallFn($sdev, "AttrFn", "del", @a);
|
||||||
if($ret) {
|
if($ret) {
|
||||||
push @rets, $ret;
|
push @rets, $ret;
|
||||||
@ -1747,6 +1764,27 @@ CommandAttr($$)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($a[1] eq "userReadings") {
|
||||||
|
|
||||||
|
my %userReadings;
|
||||||
|
|
||||||
|
my $arg= $a[2]; # myReading1 { codecodecode1 }, myReading2 { codecodecode2 }, myReading3 { codecodecode3 }
|
||||||
|
|
||||||
|
my $regexi= '\s*(\w+)\s+({.*?})\s*'; # matches myReading1 { codecodecode1 }
|
||||||
|
my $regexo= '^(' . $regexi . ')(,\s*(.*))*$';
|
||||||
|
|
||||||
|
Debug "arg is $arg";
|
||||||
|
|
||||||
|
while($arg =~ /$regexo/) {
|
||||||
|
my $userReading= $2;
|
||||||
|
my $perlCode= $3;
|
||||||
|
#Debug sprintf("userReading %s has perlCode %s", $userReading, $perlCode);
|
||||||
|
$userReadings{$userReading}= $perlCode;
|
||||||
|
$arg= defined($5) ? $5 : "";
|
||||||
|
}
|
||||||
|
$defs{$sdev}{fhem}{userReadings}= \%userReadings;
|
||||||
|
}
|
||||||
|
|
||||||
if($a[1] eq "IODev" && (!$a[2] || !defined($defs{$a[2]}))) {
|
if($a[1] eq "IODev" && (!$a[2] || !defined($defs{$a[2]}))) {
|
||||||
push @rets,"$sdev: unknown IODev specified";
|
push @rets,"$sdev: unknown IODev specified";
|
||||||
next;
|
next;
|
||||||
@ -1770,6 +1808,7 @@ CommandAttr($$)
|
|||||||
$defs{$sdev}{NR} = $devcount++
|
$defs{$sdev}{NR} = $devcount++
|
||||||
if($defs{$ioname}{NR} > $defs{$sdev}{NR});
|
if($defs{$ioname}{NR} > $defs{$sdev}{NR});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Log 3, join(" ", @rets) if(!$cl && @rets);
|
Log 3, join(" ", @rets) if(!$cl && @rets);
|
||||||
return join("\n", @rets);
|
return join("\n", @rets);
|
||||||
@ -2750,11 +2789,6 @@ addEvent($$)
|
|||||||
#
|
#
|
||||||
################################################################
|
################################################################
|
||||||
|
|
||||||
sub
|
|
||||||
Debug($) {
|
|
||||||
my $msg= shift;
|
|
||||||
Log 1, "DEBUG>" . $msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
# get the names of interfaces for the device represented by the $hash
|
# get the names of interfaces for the device represented by the $hash
|
||||||
# empty list is returned if interfaces are not defined
|
# empty list is returned if interfaces are not defined
|
||||||
@ -2927,6 +2961,7 @@ readingsBeginUpdate($)
|
|||||||
return $now;
|
return $now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Call readingsEndUpdate when you are done updating readings.
|
# Call readingsEndUpdate when you are done updating readings.
|
||||||
# This optionally calls DoTrigger to propagate the changes.
|
# This optionally calls DoTrigger to propagate the changes.
|
||||||
@ -2937,6 +2972,20 @@ readingsEndUpdate($$)
|
|||||||
my ($hash,$dotrigger)= @_;
|
my ($hash,$dotrigger)= @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
# process user readings
|
||||||
|
if(defined($hash->{fhem}{userReadings})) {
|
||||||
|
my %userReadings= %{$hash->{fhem}{userReadings}};
|
||||||
|
foreach my $userReading (keys %userReadings) {
|
||||||
|
Debug "Evaluating " . $userReadings{$userReading};
|
||||||
|
my $value= eval $userReadings{$userReading};
|
||||||
|
if($@) {
|
||||||
|
$value = "Error evaluating $name userReading $userReading: $@";
|
||||||
|
Log 1, $value;
|
||||||
|
}
|
||||||
|
readingsBulkUpdate($hash,$userReading,$value,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# turn off updating mode
|
# turn off updating mode
|
||||||
delete $hash->{".updateTimestamp"};
|
delete $hash->{".updateTimestamp"};
|
||||||
delete $hash->{".attreour"};
|
delete $hash->{".attreour"};
|
||||||
@ -2966,7 +3015,6 @@ readingsEndUpdate($$)
|
|||||||
}
|
}
|
||||||
$hash->{STATE} = ReplaceEventMap($name, $st, 1) if(defined($st));
|
$hash->{STATE} = ReplaceEventMap($name, $st, 1) if(defined($st));
|
||||||
|
|
||||||
|
|
||||||
# propagate changes
|
# propagate changes
|
||||||
if($dotrigger && $init_done) {
|
if($dotrigger && $init_done) {
|
||||||
DoTrigger($name, undef, 1) if(!$readingsUpdateDelayTrigger);
|
DoTrigger($name, undef, 1) if(!$readingsUpdateDelayTrigger);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user