mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-21 01:46:08 +00:00
98_JsonMod.pm: #109413: list shrink reduced to computed readings
git-svn-id: https://svn.fhem.de/fhem/trunk@21517 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a9969502e0
commit
c95a9fd870
@ -30,6 +30,7 @@ use utf8;
|
|||||||
use Time::Local qw( timelocal timegm );
|
use Time::Local qw( timelocal timegm );
|
||||||
use Text::Balanced qw ( extract_codeblock extract_delimited );
|
use Text::Balanced qw ( extract_codeblock extract_delimited );
|
||||||
use Unicode::Normalize qw( NFD );
|
use Unicode::Normalize qw( NFD );
|
||||||
|
use List::Util qw( any );
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
|
|
||||||
#use Memory::Usage;
|
#use Memory::Usage;
|
||||||
@ -474,20 +475,25 @@ sub JsonMod_DoReadings {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (my $readingList = AttrVal($name, 'readingList', '')) {
|
if (my $readingList = AttrVal($name, 'readingList', '')) {
|
||||||
|
# support for perl expressions within
|
||||||
my $NAME = $name;
|
my $NAME = $name;
|
||||||
if (not eval $readingList and $@) {
|
if (not eval $readingList and $@) {
|
||||||
JsonMod_Logger($hash, 2, 'error while evaluating readingList: %s', $@);
|
JsonMod_Logger($hash, 2, 'error while evaluating readingList: %s', $@);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if (keys %{$newReadings}) {
|
if (keys %{$newReadings}) {
|
||||||
|
my @newReadings;
|
||||||
|
my @oldReadings = split ',', ReadingsVal($name, '.computedReadings', '');
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
foreach my $k (keys %{$newReadings}) {
|
foreach my $k (keys %{$newReadings}) {
|
||||||
readingsBulkUpdate($hash, $k, $newReadings->{$k});
|
readingsBulkUpdate($hash, $k, $newReadings->{$k});
|
||||||
|
push @newReadings, $k;
|
||||||
};
|
};
|
||||||
# not used anymore
|
# not used anymore
|
||||||
foreach my $k (keys %{$oldReadings}) {
|
foreach my $k (keys %{$oldReadings}) {
|
||||||
readingsDelete($hash, $k) if ($oldReadings->{$k} == 0);
|
readingsDelete($hash, $k) if ($oldReadings->{$k} == 0 and any { $_ eq $k} @oldReadings);
|
||||||
};
|
};
|
||||||
|
readingsBulkUpdate($hash, '.computedReadings', join ',', @newReadings);
|
||||||
readingsEndUpdate($hash, 1);
|
readingsEndUpdate($hash, 1);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user