From 12e1837d74e921ad59e5e479ed8e72b84d99138b Mon Sep 17 00:00:00 2001 From: justme-1968 Date: Sun, 16 Oct 2016 10:39:01 +0000 Subject: [PATCH] 31_HUEDevice.pm: better lastupdated handling git-svn-id: https://svn.fhem.de/fhem/trunk@12349 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/31_HUEDevice.pm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/fhem/FHEM/31_HUEDevice.pm b/fhem/FHEM/31_HUEDevice.pm index 40f7cd152..9e2a1206b 100644 --- a/fhem/FHEM/31_HUEDevice.pm +++ b/fhem/FHEM/31_HUEDevice.pm @@ -1194,11 +1194,12 @@ HUEDevice_Parse($$) substr( $lastupdated, 10, 1, '_' ); my $sec = SVG_time_to_sec($lastupdated); $sec += $iohash->{helper}{offsetUTC}; - + $lastupdated = FmtDateTime($sec); } - return undef if( ReadingsTimestamp($name,'state','') eq $lastupdated ); + return undef if( $hash->{lastupdated} && $hash->{lastupdated} eq $lastupdated ); + $hash->{lastupdated} = $lastupdated; $readings{state} = $state->{status} if( defined($state->{status}) ); $readings{state} = $state->{flag}?'1':'0' if( defined($state->{flag}) ); @@ -1215,14 +1216,21 @@ HUEDevice_Parse($$) if( scalar keys %readings ) { readingsBeginUpdate($hash); - if( $lastupdated ) { - $hash->{'.updateTimestamp'} = $lastupdated; - $hash->{CHANGETIME}[0] = $lastupdated; + + my $i = 0; + foreach my $key ( keys %readings ) { + if( defined($readings{$key}) ) { + if( $lastupdated ) { + $hash->{'.updateTimestamp'} = $lastupdated; + $hash->{CHANGETIME}[$i] = $lastupdated; + } + + readingsBulkUpdate($hash, $key, $readings{$key}, 1); + + ++$i; + } } - foreach my $key ( keys %readings ) { - readingsBulkUpdate($hash, $key, $readings{$key}, 1) if( defined($readings{$key}) ); - } readingsEndUpdate($hash,1); delete $hash->{CHANGETIME}; }