From b6bdbb2934bdd25c5cfd589117defe6b459f81fb Mon Sep 17 00:00:00 2001 From: justme-1968 Date: Sun, 9 Oct 2016 20:25:32 +0000 Subject: [PATCH] HUE: correct sensor timestamps by utc offset git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@12307 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/30_HUEBridge.pm | 52 +++++++++++++++++++++++++------------------- FHEM/31_HUEDevice.pm | 10 +++++++++ 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/FHEM/30_HUEBridge.pm b/FHEM/30_HUEBridge.pm index 2979bb373..98464ec00 100644 --- a/FHEM/30_HUEBridge.pm +++ b/FHEM/30_HUEBridge.pm @@ -167,18 +167,18 @@ sub HUEBridge_Undefine($$) sub HUEBridge_fillBridgeInfo($$) { - my ($hash,$result) = @_; + my ($hash,$config) = @_; my $name = $hash->{NAME}; - $hash->{name} = $result->{name}; - $hash->{modelid} = $result->{modelid}; - $hash->{swversion} = $result->{swversion}; - $hash->{apiversion} = $result->{apiversion}; + $hash->{name} = $config->{name}; + $hash->{modelid} = $config->{modelid}; + $hash->{swversion} = $config->{swversion}; + $hash->{apiversion} = $config->{apiversion}; - my @l = split( '\.', $result->{apiversion} ); + my @l = split( '\.', $config->{apiversion} ); $hash->{helper}{apiversion} = ($l[0] << 16) + ($l[1] << 8) + $l[2]; - if( !defined($result->{'linkbutton'}) + if( !defined($config->{'linkbutton'}) && !defined($attr{$name}{icon}) ) { $attr{$name}{icon} = 'hue_filled_bridge_v1' if( $hash->{modelid} && $hash->{modelid} eq 'BSB001' ); $attr{$name}{icon} = 'hue_filled_bridge_v2' if( $hash->{modelid} && $hash->{modelid} eq 'BSB002' ); @@ -793,34 +793,42 @@ HUEBridge_GetUpdate($) sub HUEBridge_Parse($$) { - my($hash,$result) = @_; + my($hash,$config) = @_; my $name = $hash->{NAME}; Log3 $name, 4, "parse status message for $name"; - #Log3 $name, 5, Dumper $result; + #Log3 $name, 5, Dumper $config; - #Log 3, Dumper $result; - $result = $result->{config} if( defined($result->{config}) ); + #Log 3, Dumper $config; + $config = $config->{config} if( defined($config->{config}) ); - HUEBridge_fillBridgeInfo($hash, $result); + HUEBridge_fillBridgeInfo($hash, $config); - $hash->{zigbeechannel} = $result->{zigbeechannel}; + $hash->{zigbeechannel} = $config->{zigbeechannel}; - if( defined( $result->{swupdate} ) ) { - my $txt = $result->{swupdate}->{text}; + if( my $utc = $config->{UTC} ) { + substr( $utc, 10, 1, '_' ); + my $sec = SVG_time_to_sec($utc); + my $offset = time()-$sec; + + $hash->{helper}{offsetUTC} = $offset; + } + + if( defined( $config->{swupdate} ) ) { + my $txt = $config->{swupdate}->{text}; readingsSingleUpdate($hash, "swupdate", $txt, 1) if( $txt && $txt ne ReadingsVal($name,"swupdate","") ); if( defined($hash->{updatestate}) ){ - readingsSingleUpdate($hash, 'state', 'update done', 1 ) if( $result->{swupdate}->{updatestate} == 0 && $hash->{helper}{updatestate} >= 2 ); - readingsSingleUpdate($hash, 'state', 'update failed', 1 ) if( $result->{swupdate}->{updatestate} == 2 && $hash->{helper}{updatestate} == 3 ); + readingsSingleUpdate($hash, 'state', 'update done', 1 ) if( $config->{swupdate}->{updatestate} == 0 && $hash->{helper}{updatestate} >= 2 ); + readingsSingleUpdate($hash, 'state', 'update failed', 1 ) if( $config->{swupdate}->{updatestate} == 2 && $hash->{helper}{updatestate} == 3 ); } - $hash->{updatestate} = $result->{swupdate}->{updatestate}; + $hash->{updatestate} = $config->{swupdate}->{updatestate}; $hash->{helper}{updatestate} = $hash->{updatestate}; - if( $result->{swupdate}->{devicetypes} ) { + if( $config->{swupdate}->{devicetypes} ) { my $devicetypes; - $devicetypes .= 'bridge' if( $result->{swupdate}->{devicetypes}->{bridge} ); - $devicetypes .= ',' if( $devicetypes && scalar(@{$result->{swupdate}->{devicetypes}->{lights}}) ); - $devicetypes .= join( ",", @{$result->{swupdate}->{devicetypes}->{lights}} ) if( $result->{swupdate}->{devicetypes}->{lights} ); + $devicetypes .= 'bridge' if( $config->{swupdate}->{devicetypes}->{bridge} ); + $devicetypes .= ',' if( $devicetypes && scalar(@{$config->{swupdate}->{devicetypes}->{lights}}) ); + $devicetypes .= join( ",", @{$config->{swupdate}->{devicetypes}->{lights}} ) if( $config->{swupdate}->{devicetypes}->{lights} ); $hash->{updatestate} .= " [$devicetypes]" if( $devicetypes ); } diff --git a/FHEM/31_HUEDevice.pm b/FHEM/31_HUEDevice.pm index d2d0f0f8c..40f7cd152 100644 --- a/FHEM/31_HUEDevice.pm +++ b/FHEM/31_HUEDevice.pm @@ -1188,6 +1188,16 @@ HUEDevice_Parse($$) $lastupdated = $state->{lastupdated}; substr( $lastupdated, 10, 1, ' ' ); + + my $offset = 0; + if( my $iohash = $hash->{IODev} ) { + 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 ); $readings{state} = $state->{status} if( defined($state->{status}) );