2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-06 06:36:36 +00:00

31_HUEDevice.pm: better lastupdated handling

git-svn-id: https://svn.fhem.de/fhem/trunk@12349 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2016-10-16 10:39:01 +00:00
parent f3da9a1a79
commit 12e1837d74

View File

@ -1198,7 +1198,8 @@ HUEDevice_Parse($$)
$lastupdated = FmtDateTime($sec); $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->{status} if( defined($state->{status}) );
$readings{state} = $state->{flag}?'1':'0' if( defined($state->{flag}) ); $readings{state} = $state->{flag}?'1':'0' if( defined($state->{flag}) );
@ -1215,14 +1216,21 @@ HUEDevice_Parse($$)
if( scalar keys %readings ) { if( scalar keys %readings ) {
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
my $i = 0;
foreach my $key ( keys %readings ) {
if( defined($readings{$key}) ) {
if( $lastupdated ) { if( $lastupdated ) {
$hash->{'.updateTimestamp'} = $lastupdated; $hash->{'.updateTimestamp'} = $lastupdated;
$hash->{CHANGETIME}[0] = $lastupdated; $hash->{CHANGETIME}[$i] = $lastupdated;
} }
foreach my $key ( keys %readings ) { readingsBulkUpdate($hash, $key, $readings{$key}, 1);
readingsBulkUpdate($hash, $key, $readings{$key}, 1) if( defined($readings{$key}) );
++$i;
} }
}
readingsEndUpdate($hash,1); readingsEndUpdate($hash,1);
delete $hash->{CHANGETIME}; delete $hash->{CHANGETIME};
} }