From 340a989b450a2a6b60a9d6932795fb0b6d8f1cd2 Mon Sep 17 00:00:00 2001 From: choenig <> Date: Sun, 11 Jul 2021 12:06:25 +0000 Subject: [PATCH] 10_WS980: v1.4.0 - allow to skip invalid values git-svn-id: https://svn.fhem.de/fhem/trunk@24726 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/10_WS980.pm | 67 ++++++++++++++++++++++++++++++------------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 38a7ff281..5a03f1f46 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - change: 10_WS980: allow to ignore invalid values - feature: 49_SSCam: new value 8.2.8-xxxx for attr simu_SVSversion - bugfix: 76_SMAInverter:fix ETOTAL/LOADTOTAL bug - feature: 76_SMAInverter: hide unavailable data diff --git a/fhem/FHEM/10_WS980.pm b/fhem/FHEM/10_WS980.pm index a2c67984c..07a6b5749 100644 --- a/fhem/FHEM/10_WS980.pm +++ b/fhem/FHEM/10_WS980.pm @@ -33,7 +33,7 @@ use warnings; use IO::Socket::INET; use POSIX qw(strftime); -my $version = "1.3.0"; +my $version = "1.4.0"; #------------------------------------------------------------------------------------------------------ # global constants @@ -165,6 +165,7 @@ sub WS980_Initialize($) $hash->{AttrList} = "altitude ". "events:textField-long ". "connection:Keep-Alive,Close ". + "invalidValues:updateReading,skip,skipAndLog ". "requests:multiple-strict,".join(",", sort keys %{REQUESTS()})." ". "showRawBuffer:1 ". "silentReconnect:1 ". @@ -293,6 +294,20 @@ sub WS980_AttrFn(@) } } + ####################### + #### invalidValues #### + + if ($attrName eq "invalidValues") { + if ($cmd eq "set") { + if ($attrVal eq "updateReading" || $attrVal eq "skip" || $attrVal eq "skipAndLog") { + return undef; + } + else { + return "'invalidValues' must be either updateReading, skip or skipAndLog"; + } + } + } + ################ #### events #### @@ -522,6 +537,7 @@ sub WS980_handleMultiValuesUpdate($$$) WS980_Log($hash, 5, "decoding block: " . WS980_hexDump($buf)); my $showRawBuffer = AttrVal($name, "showRawBuffer", "0") eq "1" ? 1 : 0; + my $invalidValues = AttrVal($name, "invalidValues", "updateReading"); for (my $i = 0; $i < length($buf); ) { @@ -564,7 +580,12 @@ sub WS980_handleMultiValuesUpdate($$$) my $value = hex(WS980_binToHex($rawValue)); if ($value eq $errVal) { - $value = "n/a"; + if ($invalidValues eq "updateReading") { + $value = 'n/a'; + } else { + WS980_Log($hash, 4, "skipping invalid value of \"$reading\"") if ($invalidValues eq "skipAndLog"); + next; + } } else { # convert negative values my $lbit = 1 << ($bytes * 2 * 4) - 1; @@ -1365,14 +1386,14 @@ sub WS980_Log($$$) =begin html - +
define <name> WS980 [IP] [INTERVAL]
attr <name> altitude <height>
pressureRel_calculated
-reading. If unset, the altitude from global is used.
attr <name> connection <Keep-Alive|Close>
Keep-Alive
: The connection to the WS980 is kept open as long as possible. Reconnect is only done if necessary. Keep-Alive
is default and a good setting in most cases.Close
: The connection is opened on-the-fly and closed directly after doing requests. Close
should only be used if you have multiple clients connection to your WS980 which might cause frequent read-timeouts. ConnectionState
will display disconnected
most of the time, this is OK!
attr <name> invalidValues <updateReading|skip|skipAndLog>
updateReading
: The reading will be set to n/a when an invalid value is received. updateReading
is default.skip
: Invalid values will silently be skipped, the corresponding reading will not be updated.skipAndLog
: Invalid values will be logged, and the corresponding reading will not be updated.attr <name> events <Configuration>|<Configuration>|...
attr <name> dusk:brightness<30,20|brightSunlight:brightness>80000,5000
attr <name> requests current todayMax ...
attr <name> showRawBuffer 1
attr <name> silentReconnect 1
attr <name> unit_temperature <unit>
attr <name> unit_pressure <unit>
attr <name> unit_wind <unit>
attr <name> unit_rain <unit>
attr <name> unit_light <unit>
attr <name> disable 1