mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
new command deletereading
git-svn-id: https://svn.fhem.de/fhem/trunk@2533 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
075b1ba04b
commit
5867c7f8ed
@ -37,6 +37,7 @@
|
||||
<a href="#define">define</a>
|
||||
<a href="#delete">delete</a>
|
||||
<a href="#deleteattr">deleteattr</a>
|
||||
<a href="#deletereading">deletereading</a>
|
||||
<a href="#fheminfo">fheminfo</a>
|
||||
<a href="#get">get</a>
|
||||
<a href="#getstate">getstate</a>
|
||||
@ -466,6 +467,23 @@ A line ending with \ will be concatenated with the next one, so long lines
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="delete"></a>
|
||||
<h3>delete</h3>
|
||||
<ul>
|
||||
<code>delete <devspec></code> <br>
|
||||
<br>
|
||||
Delete something created with the <a href="#define">define</a> command.
|
||||
See the <a href="#devspec">Device specification</a> section for details on
|
||||
<devspec>.<br>
|
||||
After deletion, the global event "DELETED" will be generated, see the notify
|
||||
section for details.<br>
|
||||
Examples:
|
||||
<ul>
|
||||
<code>delete lamp</code><br>
|
||||
</ul>
|
||||
<br>
|
||||
</ul>
|
||||
|
||||
<a name="deleteattr"></a>
|
||||
<h3>deleteattr</h3>
|
||||
<ul>
|
||||
@ -485,19 +503,22 @@ A line ending with \ will be concatenated with the next one, so long lines
|
||||
<br>
|
||||
</ul>
|
||||
|
||||
<a name="delete"></a>
|
||||
<h3>delete</h3>
|
||||
<a name="deletereading"></a>
|
||||
<h3>deletereading</h3>
|
||||
<ul>
|
||||
<code>delete <devspec></code> <br>
|
||||
<code>deletereading <devspec> <readingname></code> <br>
|
||||
<br>
|
||||
Delete something created with the <a href="#define">define</a> command.
|
||||
Delete the reading <readingname>
|
||||
for a device. <readingname> is a perl regular expression that must match the whole name of the reading.
|
||||
Use with greatest care! FHEM might crash if you delete vital readings of a device.
|
||||
See the <a href="#devspec">Device specification</a> section for details on
|
||||
<devspec>.<br>
|
||||
After deletion, the global event "DELETED" will be generated, see the notify
|
||||
section for details.<br>
|
||||
<br>
|
||||
|
||||
Examples:
|
||||
<ul>
|
||||
<code>delete lamp</code><br>
|
||||
<code>deletereading mySensor temp1</code><br>
|
||||
<code>deletereading mySensor temp\d+</code><br>
|
||||
</ul>
|
||||
<br>
|
||||
</ul>
|
||||
|
@ -34,6 +34,7 @@
|
||||
<a href="#define">define</a>
|
||||
<a href="#delete">delete</a>
|
||||
<a href="#deleteattr">deleteattr</a>
|
||||
<a href="#deletereading">deletereading</a>
|
||||
<a href="#fheminfo">fheminfo</a>
|
||||
<a href="#get">get</a>
|
||||
<a href="#getstate">getstate</a>
|
||||
@ -482,6 +483,25 @@ Zeilen erstreckende Befehle, indem man keine \ am Zeilenende eingeben muss.</p>
|
||||
</ul>
|
||||
|
||||
|
||||
<a name="delete"></a>
|
||||
<h3>delete</h3>
|
||||
<ul>
|
||||
<code>delete <devspec></code> <br>
|
||||
<br>
|
||||
Löscht etwas was mit dem <a href="#define">define</a> Befehl erstellt worden
|
||||
ist.
|
||||
Lesen Sie sich bitte den Abschnitt <a href="#devspec">Device specification</a> für
|
||||
Details von
|
||||
<devspec> durch.<br>
|
||||
Nach dem löschen, wird das globale Ereignis "DELETED" erzeugt. Lesen Sie bitte
|
||||
den Abschnitt zu "notify" für genauere Informationen durch.<br>
|
||||
Beispiel:
|
||||
<ul>
|
||||
<code>delete lamp</code><br>
|
||||
</ul>
|
||||
<br>
|
||||
</ul>
|
||||
|
||||
<a name="deleteattr"></a>
|
||||
<h3>deleteattr</h3>
|
||||
<ul>
|
||||
@ -503,21 +523,22 @@ Zeilen erstreckende Befehle, indem man keine \ am Zeilenende eingeben muss.</p>
|
||||
<br>
|
||||
</ul>
|
||||
|
||||
<a name="delete"></a>
|
||||
<h3>delete</h3>
|
||||
<a name="deletereading"></a>
|
||||
<h3>deletereading</h3>
|
||||
<ul>
|
||||
<code>delete <devspec></code> <br>
|
||||
<code>deletereading <devspec> <readingname></code> <br>
|
||||
<br>
|
||||
Löscht etwas was mit dem <a href="#define">define</a> Befehl erstellt worden
|
||||
ist.
|
||||
Lesen Sie sich bitte den Abschnitt <a href="#devspec">Device specification</a> für
|
||||
Details von
|
||||
<devspec> durch.<br>
|
||||
Nach dem löschen, wird das globale Ereignis "DELETED" erzeugt. Lesen Sie bitte
|
||||
den Abschnitt zu "notify" für genauere Informationen durch.<br>
|
||||
Beispiel:
|
||||
Delete the reading <readingname>
|
||||
for a device. <readingname> is a perl regular expression that must match the whole name of the reading.
|
||||
Use with greatest care! FHEM might crash if you delete vital readings of a device.
|
||||
See the <a href="#devspec">Device specification</a> section for details on
|
||||
<devspec>.<br>
|
||||
<br>
|
||||
|
||||
Examples:
|
||||
<ul>
|
||||
<code>delete lamp</code><br>
|
||||
<code>deletereading mySensor temp1</code><br>
|
||||
<code>deletereading mySensor temp\d+</code><br>
|
||||
</ul>
|
||||
<br>
|
||||
</ul>
|
||||
|
54
fhem/fhem.pl
54
fhem/fhem.pl
@ -186,9 +186,9 @@ my $cvsid = '$Id$';
|
||||
my $namedef =
|
||||
"where <name> is either:\n" .
|
||||
"- a single device name\n" .
|
||||
"- a list seperated by komma (,)\n" .
|
||||
"- a regexp, if contains one of the following characters: *[]^\$\n" .
|
||||
"- a range seperated by dash (-)\n";
|
||||
"- a list separated by komma (,)\n" .
|
||||
"- a regexp, if it contains one of the following characters: *[]^\$\n" .
|
||||
"- a range separated by dash (-)\n";
|
||||
my $stt_sec; # Used by SecondsTillTomorrow()
|
||||
my $stt_day; # Used by SecondsTillTomorrow()
|
||||
my @cmdList; # Remaining commands in a chain. Used by sleep
|
||||
@ -220,6 +220,8 @@ $readingFnAttributes = "event-on-change-reading:0,1 event-on-update-reading:0,1
|
||||
Hlp=>"<name> <type> <options>,define a device/at/notify entity" },
|
||||
"deleteattr" => { Fn=>"CommandDeleteAttr",
|
||||
Hlp=>"<devspec> [<attrname>],delete attribute for <devspec>" },
|
||||
"deletereading" => { Fn=>"CommandDeleteReading",
|
||||
Hlp=>"<devspec> [<attrname>],delete user defined reading for <devspec>" },
|
||||
"delete" => { Fn=>"CommandDelete",
|
||||
Hlp=>"<devspec>,delete the corresponding definition(s)"},
|
||||
"get" => { Fn=>"CommandGet",
|
||||
@ -1398,8 +1400,8 @@ CommandDeleteAttr($$)
|
||||
$a[0] = $sdev;
|
||||
|
||||
if($a[1] eq "userReadings") {
|
||||
Debug "Deleting userReadings for $sdev";
|
||||
delete($defs{$sdev}{fhem}{userReadings});
|
||||
#Debug "Deleting userReadings for $sdev";
|
||||
delete($defs{$sdev}{fhem}{'.userReadings'});
|
||||
}
|
||||
|
||||
$ret = CallFn($sdev, "AttrFn", "del", @a);
|
||||
@ -1419,6 +1421,37 @@ CommandDeleteAttr($$)
|
||||
return join("\n", @rets);
|
||||
}
|
||||
|
||||
#############
|
||||
sub
|
||||
CommandDeleteReading($$)
|
||||
{
|
||||
my ($cl, $def) = @_;
|
||||
|
||||
my @a = split(" ", $def, 2);
|
||||
return "Usage: deletereading <name> <reading>\n$namedef" if(@a != 2);
|
||||
|
||||
my @rets;
|
||||
foreach my $sdev (devspec2array($a[0])) {
|
||||
|
||||
if(!defined($defs{$sdev})) {
|
||||
push @rets, "Please define $sdev first";
|
||||
next;
|
||||
}
|
||||
|
||||
$a[0] = $sdev;
|
||||
my $readingspec= '^' . $a[1] . '$';
|
||||
|
||||
foreach my $reading (grep { /$readingspec/ } keys ($defs{$sdev}{READINGS})) {
|
||||
delete($defs{$sdev}{READINGS}{$reading});
|
||||
push @rets, "Deleted reading $reading for device $sdev";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return join("\n", @rets);
|
||||
}
|
||||
|
||||
#############
|
||||
sub
|
||||
PrintHash($$)
|
||||
{
|
||||
@ -1773,7 +1806,7 @@ CommandAttr($$)
|
||||
my $regexi= '\s*(\w+)\s+({.*?})\s*'; # matches myReading1 { codecodecode1 }
|
||||
my $regexo= '^(' . $regexi . ')(,\s*(.*))*$';
|
||||
|
||||
Debug "arg is $arg";
|
||||
#Debug "arg is $arg";
|
||||
|
||||
while($arg =~ /$regexo/) {
|
||||
my $userReading= $2;
|
||||
@ -1782,7 +1815,7 @@ CommandAttr($$)
|
||||
$userReadings{$userReading}= $perlCode;
|
||||
$arg= defined($5) ? $5 : "";
|
||||
}
|
||||
$defs{$sdev}{fhem}{userReadings}= \%userReadings;
|
||||
$defs{$sdev}{fhem}{'.userReadings'}= \%userReadings;
|
||||
}
|
||||
|
||||
if($a[1] eq "IODev" && (!$a[2] || !defined($defs{$a[2]}))) {
|
||||
@ -2926,7 +2959,6 @@ EOD
|
||||
################################################################
|
||||
#
|
||||
# Wrappers for commonly used core functions in device-specific modules.
|
||||
# This part maintained by Boris Neubert omega at online dot de
|
||||
#
|
||||
################################################################
|
||||
|
||||
@ -2973,10 +3005,10 @@ readingsEndUpdate($$)
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
# process user readings
|
||||
if(defined($hash->{fhem}{userReadings})) {
|
||||
my %userReadings= %{$hash->{fhem}{userReadings}};
|
||||
if(defined($hash->{fhem}{'.userReadings'})) {
|
||||
my %userReadings= %{$hash->{fhem}{'.userReadings'}};
|
||||
foreach my $userReading (keys %userReadings) {
|
||||
Debug "Evaluating " . $userReadings{$userReading};
|
||||
#Debug "Evaluating " . $userReadings{$userReading};
|
||||
my $value= eval $userReadings{$userReading};
|
||||
if($@) {
|
||||
$value = "Error evaluating $name userReading $userReading: $@";
|
||||
|
Loading…
Reference in New Issue
Block a user