From 2bd3562cff403296000146b024fa35faa3f14fb7 Mon Sep 17 00:00:00 2001 From: borisneubert Date: Sat, 24 Nov 2012 13:48:12 +0000 Subject: [PATCH] avoid unitialized value warnings for undefined readings in ReadingsBulkUpdate git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@2182 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/fhem.pl | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 97eceade8..d01f49f7b 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -2928,21 +2928,25 @@ readingsBulkUpdate($$$) { # shorthand my $readings= $hash->{READINGS}; + + my $changed= 1; + # check for changes only if reading already exists + if(defined($readings->{$reading})) { - # these flags determine if any of the "event-on" attributes are set; - my $attreocr= AttrVal($name, "event-on-change-reading", ""); - my $attreour= AttrVal($name, "event-on-update-reading", ""); + # these flags determine if any of the "event-on" attributes are set; + my $attreocr= AttrVal($name, "event-on-change-reading", ""); + my $attreour= AttrVal($name, "event-on-update-reading", ""); - # these flags determine whether the reading is listed in any of the attributes - my $eocr= $attreocr && grep($_ eq $reading, split /,/,$attreocr); - my $eour= $attreour && grep($_ eq $reading, split /,/,$attreour); + # these flags determine whether the reading is listed in any of the attributes + my $eocr= $attreocr && grep($_ eq $reading, split /,/,$attreocr); + my $eour= $attreour && grep($_ eq $reading, split /,/,$attreour); - # determine if an event should be created - my $changed= !($attreocr || $attreour) # always create event if no attribute is set - || $eour # or if the reading is listed in event-on-update-reading - || ($eocr && # or if the reading is listed in event-on-change-reading... - ($value ne $readings->{$reading}{VAL})); # ...and its value has changed. - + # determine if an event should be created + my $changed= !($attreocr || $attreour) # always create event if no attribute is set + || $eour # or if the reading is listed in event-on-update-reading + || ($eocr && # or if the reading is listed in event-on-change-reading... + ($value ne $readings->{$reading}{VAL})); # ...and its value has changed. + } setReadingsVal($hash, $reading, $value, $hash->{helper}{updating}{latestUpdate});