98_readingsWatcher: remove List::Utils
git-svn-id: https://svn.fhem.de/fhem/trunk@21681 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
# 2.1.1 => 14.04.20 remove List::Utils
|
||||||
# 2.1.0 => 06.04.20
|
# 2.1.0 => 06.04.20
|
||||||
# 2.0.0 => 05.04.20 perlcritic -4 / PBP
|
# 2.0.0 => 05.04.20 perlcritic -4 / PBP
|
||||||
# 1.7.1 => 25.01.20 fix ErrorValue 0
|
# 1.7.1 => 25.01.20 fix ErrorValue 0
|
||||||
@@ -42,7 +43,6 @@ use warnings;
|
|||||||
use utf8;
|
use utf8;
|
||||||
use GPUtils qw(GP_Import GP_Export); # wird für den Import der FHEM Funktionen aus der fhem.pl benötigt
|
use GPUtils qw(GP_Import GP_Export); # wird für den Import der FHEM Funktionen aus der fhem.pl benötigt
|
||||||
use Time::HiRes qw(gettimeofday);
|
use Time::HiRes qw(gettimeofday);
|
||||||
use List::Util qw(uniq);
|
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
{
|
{
|
||||||
@@ -158,7 +158,7 @@ sub Undefine {
|
|||||||
|
|
||||||
delFromAttrList('readingsWatcher'); # global -> userattr
|
delFromAttrList('readingsWatcher'); # global -> userattr
|
||||||
# wer hat alles ein Attribut readingsWatcher gesetzt ?
|
# wer hat alles ein Attribut readingsWatcher gesetzt ?
|
||||||
foreach (devspec2array("readingsWatcher!=")) {
|
foreach (devspec2array('readingsWatcher!=')) {
|
||||||
delFromDevAttrList($_, 'readingsWatcher'); # aufräumen
|
delFromDevAttrList($_, 'readingsWatcher'); # aufräumen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,11 +315,11 @@ sub formatStateList {
|
|||||||
foreach (@devs) {
|
foreach (@devs) {
|
||||||
my ($d,$r,$t,$s,$g) = split(',', $_);
|
my ($d,$r,$t,$s,$g) = split(',', $_);
|
||||||
# die tatsächlichen Breiten aus den vorhandenen Werten ermitteln
|
# die tatsächlichen Breiten aus den vorhandenen Werten ermitteln
|
||||||
$dw = length($d) if (length($d) > $dw);
|
$dw = (length($d) > $dw) ? length($d) : $dw;
|
||||||
$rw = length($r) if (length($r) > $rw);
|
$rw = (length($r) > $rw) ? length($r) : $rw;
|
||||||
$tw = length($t) if (length($t) > $tw);
|
$tw = (length($t) > $tw) ? length($t) : $tw;
|
||||||
$sw = length($s) if (length($s) > $sw);
|
$sw = (length($s) > $sw) ? length($s) : $sw;
|
||||||
$aw = length($g) if (length($g) > $aw);
|
$aw = (length($g) > $aw) ? length($g) : $aw;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $head = 'Device ' .(' ' x ($dw-6))
|
my $head = 'Device ' .(' ' x ($dw-6))
|
||||||
@@ -428,7 +428,7 @@ sub OnTimer {
|
|||||||
|
|
||||||
next if (!$rSA || IsDisabled($device) || IsIgnored($device));
|
next if (!$rSA || IsDisabled($device) || IsIgnored($device));
|
||||||
|
|
||||||
push @devices, $device; # if !grep {/$device/} @devices; keine doppelten Namen
|
push @devices, $device;
|
||||||
|
|
||||||
$or_and = 1 if (index($rSA,'+') != -1); # Readings als AND auswerten
|
$or_and = 1 if (index($rSA,'+') != -1); # Readings als AND auswerten
|
||||||
$rSA =~ s/\+/,/g ; # eventuell vorhandene + auch in Komma wandeln
|
$rSA =~ s/\+/,/g ; # eventuell vorhandene + auch in Komma wandeln
|
||||||
@@ -439,16 +439,29 @@ sub OnTimer {
|
|||||||
|
|
||||||
my $ok_device = 0;
|
my $ok_device = 0;
|
||||||
|
|
||||||
foreach (split(';', $rSA)) {
|
foreach (split(';', $rSA)) { #Anzahl Regelsätze im Device
|
||||||
|
|
||||||
my ($timeout, $errorValue, @readings_ar) = split(',', $_);
|
my ($timeout, $errorValue, @readings_ar) = split(',', $_);
|
||||||
|
|
||||||
if (@readings_ar) {
|
if (@readings_ar) {
|
||||||
$ok_device = 1;
|
|
||||||
$timeout = int($timeout);
|
$timeout = int($timeout);
|
||||||
|
|
||||||
|
if ($timeout > 1) {
|
||||||
|
$ok_device = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (@readings_ar == 1) {
|
||||||
|
Log3 $hash,2,"$name, invalid timeout value $timeout for reading $device $readings_ar[0]";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log3 $hash,2,"$name, invalid timeout value $timeout for readings $device ".join(',',@readings_ar);
|
||||||
|
}
|
||||||
|
@readings_ar = (); # das werten wir danach im foreach erst gar nicht mehr aus
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $reading (@readings_ar) { # alle zu überwachenden Readings
|
foreach my $reading (@readings_ar) { # alle zu überwachenden Readings in einem Regelsatz
|
||||||
|
|
||||||
$reading =~ s/ //g;
|
$reading =~ s/ //g;
|
||||||
my $state = 0;
|
my $state = 0;
|
||||||
@@ -465,9 +478,8 @@ sub OnTimer {
|
|||||||
|
|
||||||
$readings_count++;
|
$readings_count++;
|
||||||
|
|
||||||
if (($age > $timeout) && ($timeout > 0)) {
|
if ($age > $timeout) {
|
||||||
|
push @toDevs, $device if !grep {/$device/} @toDevs; # keine doppelten Namen
|
||||||
push @toDevs, $device; # if (!grep {/$device/} @toDevs);
|
|
||||||
$timeOutState = 'timeout';
|
$timeOutState = 'timeout';
|
||||||
$d_d ++; # Device Tote
|
$d_d ++; # Device Tote
|
||||||
my $rts = ReadingsTimestamp($device, $reading, 0);
|
my $rts = ReadingsTimestamp($device, $reading, 0);
|
||||||
@@ -481,10 +493,9 @@ sub OnTimer {
|
|||||||
|
|
||||||
my $d_r = $device.'_'.$reading;
|
my $d_r = $device.'_'.$reading;
|
||||||
|
|
||||||
readingsBulkUpdate($hash, $d_r, $timeOutState) if ($timeout > 0);
|
readingsBulkUpdate($hash, $d_r, $timeOutState) if ($timeOutState);
|
||||||
$readingsList =~ s/$d_r,// if ($readingsList); # das Reading aus der Liste streichen, leer solange noch kein Device das Attr hat !
|
|
||||||
|
|
||||||
Log3 $hash,2,"name, invalid timeout value $timeout for reading $device $reading" if ($timeout < 1);
|
$readingsList =~ s/$d_r,// if ($readingsList); # das Reading aus der Liste streichen, leer solange noch kein Device das Attr hat !
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setReadingsVal($defs{$device},$reading,'unknown',TimeNow()) if ($errorValue); # leise setzen ohne Event
|
setReadingsVal($defs{$device},$reading,'unknown',TimeNow()) if ($errorValue); # leise setzen ohne Event
|
||||||
@@ -492,8 +503,10 @@ sub OnTimer {
|
|||||||
Log3 $hash,3,"$name, reading Timestamp for $reading not found on device $device";
|
Log3 $hash,3,"$name, reading Timestamp for $reading not found on device $device";
|
||||||
readingsBulkUpdate($hash, $device.'_'.$reading, 'no Timestamp');
|
readingsBulkUpdate($hash, $device.'_'.$reading, 'no Timestamp');
|
||||||
}
|
}
|
||||||
}
|
} # Readings in einem Regelsatz
|
||||||
} # Anzahl Readings Sätze im Device
|
} # Anzahl Regelsätze im Device
|
||||||
|
|
||||||
|
push @toDevs , $device if ($d_d);
|
||||||
|
|
||||||
if ($ok_device && $timeOutState) {
|
if ($ok_device && $timeOutState) {
|
||||||
my $error;
|
my $error;
|
||||||
@@ -515,11 +528,8 @@ sub OnTimer {
|
|||||||
}
|
}
|
||||||
} # foreach device
|
} # foreach device
|
||||||
|
|
||||||
# eventuell doppelte Einträge aus allen vier Listen entfernen
|
# eventuell doppelte Einträge aus der Timeout Liste entfernen
|
||||||
@devices = List::Util::uniq @devices if (@devices);
|
# @toDevs = uniq @toDevs if (@toDevs > 1);
|
||||||
@toDevs = List::Util::uniq @toDevs if (@toDevs);
|
|
||||||
@skipDevs = List::Util::uniq @skipDevs if (@skipDevs);
|
|
||||||
@deadDevs = List::Util::uniq @deadDevs if (@deadDevs);
|
|
||||||
|
|
||||||
readingsBulkUpdate($hash, 'readings' , $readings_count);
|
readingsBulkUpdate($hash, 'readings' , $readings_count);
|
||||||
readingsBulkUpdate($hash, 'devices' , int(@devices));
|
readingsBulkUpdate($hash, 'devices' , int(@devices));
|
||||||
@@ -534,7 +544,7 @@ sub OnTimer {
|
|||||||
clearReadings($name,$readingsList) if ($readingsList);
|
clearReadings($name,$readingsList) if ($readingsList);
|
||||||
|
|
||||||
(@devices) ? readingsBulkUpdate($hash, '.associatedWith', join(',', @devices)) : readingsDelete($hash, '.associatedWith');
|
(@devices) ? readingsBulkUpdate($hash, '.associatedWith', join(',', @devices)) : readingsDelete($hash, '.associatedWith');
|
||||||
(@toDevs) ? readingsBulkUpdate($hash, 'timeoutDevs', join(',', @toDevs)) : readingsBulkUpdate($hash, 'toDevs', 'none');
|
(@toDevs) ? readingsBulkUpdate($hash, 'timeoutDevs', join(',', @toDevs)) : readingsBulkUpdate($hash, 'timeoutDevs', 'none');
|
||||||
(@deadDevs) ? readingsBulkUpdate($hash, 'deadDevs', join(',', @deadDevs)) : readingsBulkUpdate($hash, 'deadDevs', 'none');
|
(@deadDevs) ? readingsBulkUpdate($hash, 'deadDevs', join(',', @deadDevs)) : readingsBulkUpdate($hash, 'deadDevs', 'none');
|
||||||
(@skipDevs) ? readingsBulkUpdate($hash, 'skippedDevs', join(',', @skipDevs)) : readingsBulkUpdate($hash, 'skippedDevs', 'none');
|
(@skipDevs) ? readingsBulkUpdate($hash, 'skippedDevs', join(',', @skipDevs)) : readingsBulkUpdate($hash, 'skippedDevs', 'none');
|
||||||
|
|
||||||
@@ -738,7 +748,7 @@ sub clearReadings {
|
|||||||
"supervision",
|
"supervision",
|
||||||
"überwachung"
|
"überwachung"
|
||||||
],
|
],
|
||||||
"version": "2.1.0",
|
"version": "2.1.1",
|
||||||
"release_status": "stable",
|
"release_status": "stable",
|
||||||
"author": [
|
"author": [
|
||||||
"Wzut"
|
"Wzut"
|
||||||
|
|||||||
Reference in New Issue
Block a user