2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-16 10:46:03 +00:00

24_TPLinkHS110: Added some extra checks for data integrity

git-svn-id: https://svn.fhem.de/fhem/trunk@13019 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
vk 2017-01-09 09:34:43 +00:00
parent efbe061815
commit bd17100435

View File

@ -134,7 +134,17 @@ sub TPLinkHS110_Get($$)
$socket->close(); $socket->close();
unless( defined $retval) { return undef; } unless( defined $retval) { return undef; }
$rdata = decrypt(substr($rdata,4)); $rdata = decrypt(substr($rdata,4));
my $realtimejson = decode_json($rdata); my $realtimejson;
if (length($rdata)==0) {
Log3 $hash, 1, "TPLinkHS110: $name: Received zero bytes of realtime data. Cannot process realtime data";
return;
}
eval {
$realtimejson = decode_json($rdata);
} or do {
Log3 $hash, 2, "TPLinkHS110: $name json-decoding failed. Problem decoding getting statistical data";
return;
};
foreach my $key2 (sort keys %{$realtimejson->{'emeter'}->{'get_realtime'}}) { foreach my $key2 (sort keys %{$realtimejson->{'emeter'}->{'get_realtime'}}) {
readingsBulkUpdate($hash, $key2, $realtimejson->{'emeter'}->{'get_realtime'}->{$key2}); readingsBulkUpdate($hash, $key2, $realtimejson->{'emeter'}->{'get_realtime'}->{$key2});
} }
@ -168,7 +178,7 @@ sub TPLinkHS110_Get($$)
if ($count) { readingsBulkUpdate($hash, "daily_average", $total/$count)}; if ($count) { readingsBulkUpdate($hash, "daily_average", $total/$count)};
1; 1;
} or do { } or do {
Log3 $hash, 3, "TPLinkHS110: $name json-decoding failed. Problem decoding getting statistical data"; Log3 $hash, 2, "TPLinkHS110: $name json-decoding failed. Problem decoding getting statistical data";
}; };
} }
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);