2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2024-11-22 09:49:50 +00:00

fhem.pl: add older-than-seconds parameter to deletereading (Foruim #116520)

git-svn-id: https://svn.fhem.de/fhem/trunk@23306 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2020-12-07 09:02:12 +00:00
parent 3fe0a1b1ce
commit 48c6a0bef6
3 changed files with 17 additions and 8 deletions

View File

@ -839,11 +839,13 @@ The following local attributes are used by a wider range of devices:
<a name="deletereading"></a>
<h3>deletereading</h3>
<ul>
<code>deletereading &lt;devspec&gt; &lt;readingname&gt;</code> <br>
<code>deletereading &lt;devspec&gt; &lt;readingname&gt;
[&lt;older-than-seconds&gt;]</code> <br>
<br>
Delete the reading &lt;readingname&gt;
for a device. &lt;readingname&gt; 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.
for a device. &lt;readingname&gt; 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
&lt;devspec&gt;.<br>
<br>

View File

@ -867,11 +867,14 @@ Die folgenden lokalen Attribute werden von mehreren Ger&auml;ten verwendet:
<a name="deletereading"></a>
<h3>deletereading</h3>
<ul>
<code>deletereading &lt;devspec&gt; &lt;readingname&gt;</code> <br>
<code>deletereading &lt;devspec&gt; &lt;readingname&gt;
[&lt;older-than-seconds&gt;]</code> <br>
<br>
Entfernt das Reading &lt;readingname&gt; f&uuml;r das spezifizierte
Ger&auml;t. &lt;readingname&gt; ist ein perl Regular-Expression, was den
vollst&auml;ndigen Namen des Readings erfassen muss.
Falls &lt;older-than-seconds&gt; spezifiziert ist, werden nur readings
entfernt, die aelter als dieser Zahl (in Sekunden) sind.<br>
Mit gr&ouml;&szlig;ter Sorgfalt verwenden! FHEM kann abst&uuml;rzen, falls
man lebenswichtige Readings entfernt.<br>

View File

@ -414,8 +414,8 @@ my %ra = (
"deleteattr" => { Fn=>"CommandDeleteAttr",
Hlp=>"<devspec> [<attrname>],delete attribute for <devspec>" },
"deletereading" => { Fn=>"CommandDeleteReading",
Hlp=>"<devspec> [<readingname>],delete user defined reading for ".
"<devspec>" },
Hlp=>"<devspec> <readingname> [older-than-seconds],".
"delete user defined readings" },
"delete" => { Fn=>"CommandDelete",
Hlp=>"<devspec>,delete the corresponding definition(s)"},
"displayattr"=> { Fn=>"CommandDisplayAttr",
@ -2378,11 +2378,14 @@ CommandDeleteReading($$)
$def = $1;
}
my @a = split(" ", $def, 2);
return "Usage: deletereading [-q] <name> <reading>\n$namedef" if(@a != 2);
my @a = split(" ", $def, 3);
return "Usage: deletereading [-q] <name> <reading> [older-than-seconds]\n".
$namedef if(@a < 2);
eval { "" =~ m/$a[1]/ };
return "Bad regexp $a[1]: $@" if($@);
return "Bad older-than-seconds format $a[2]"
if(defined($a[2]) && $a[2] !~ m/^\d+$/);
my @rets;
foreach my $sdev (devspec2array($a[0],$cl)) {
@ -2397,6 +2400,7 @@ CommandDeleteReading($$)
foreach my $reading (grep { /$readingspec/ }
keys %{$defs{$sdev}{READINGS}} ) {
next if(defined($a[2]) && ReadingsAge($sdev, $reading, 0) <= $a[2]);
readingsDelete($defs{$sdev}, $reading);
push @rets, "Deleted reading $reading for device $sdev";
}