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:
parent
3fe0a1b1ce
commit
48c6a0bef6
@ -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 <devspec> <readingname></code> <br>
|
||||
<code>deletereading <devspec> <readingname>
|
||||
[<older-than-seconds>]</code> <br>
|
||||
<br>
|
||||
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.
|
||||
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>
|
||||
|
@ -867,11 +867,14 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
<a name="deletereading"></a>
|
||||
<h3>deletereading</h3>
|
||||
<ul>
|
||||
<code>deletereading <devspec> <readingname></code> <br>
|
||||
<code>deletereading <devspec> <readingname>
|
||||
[<older-than-seconds>]</code> <br>
|
||||
<br>
|
||||
Entfernt das Reading <readingname> für das spezifizierte
|
||||
Gerät. <readingname> ist ein perl Regular-Expression, was den
|
||||
vollständigen Namen des Readings erfassen muss.
|
||||
Falls <older-than-seconds> spezifiziert ist, werden nur readings
|
||||
entfernt, die aelter als dieser Zahl (in Sekunden) sind.<br>
|
||||
|
||||
Mit größter Sorgfalt verwenden! FHEM kann abstürzen, falls
|
||||
man lebenswichtige Readings entfernt.<br>
|
||||
|
12
fhem/fhem.pl
12
fhem/fhem.pl
@ -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";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user