From da6ccee1a9dc800a33f808f190ed8c98e447886f Mon Sep 17 00:00:00 2001 From: justme-1968 Date: Sun, 4 Oct 2015 20:23:21 +0000 Subject: [PATCH] 30_HUEBridge.pm,31_HUEDevice.pm: preparation to parse bridge answert to PUT instead of polling git-svn-id: https://svn.fhem.de/fhem/trunk@9378 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/30_HUEBridge.pm | 31 ++++++++++++++++++++++++++++--- fhem/FHEM/31_HUEDevice.pm | 20 ++++++++++---------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/fhem/FHEM/30_HUEBridge.pm b/fhem/FHEM/30_HUEBridge.pm index 6128a3300..f4920a8bc 100644 --- a/fhem/FHEM/30_HUEBridge.pm +++ b/fhem/FHEM/30_HUEBridge.pm @@ -217,7 +217,7 @@ sub HUEBridge_Pair($) return undef; } - $attr{$name}{key} = $result->{success}{username} if( $result->{success}{username} ); + $attr{$name}{key} = $result->{success}{username} if( $result->{success}{username} ); $hash->{STATE} = 'Paired'; @@ -578,10 +578,35 @@ sub HUEBridge_ProcessResponse($$) my $error = $obj->[0]->{error}->{'description'}; $hash->{STATE} = $error; - - Log3 $name, 3, $error; } +if( 0 ) { + my %json = (); + foreach my $item (@{$obj}) { + if( my $success = $item->{success} ) { + foreach my $key ( keys %{$success} ) { + my @l = split( '/', $key ); + if( $l[1] eq 'lights' && $l[3] eq 'state' ) { + $json{$l[2]}->{state}->{$l[4]} = $success->{$key}; + } + } + + } elsif( my $error = $item->{error} ) { + my $msg = $error->{'description'}; + Log3 $name, 3, $msg; + } + } +#Log 3, Dumper \%json; + + foreach my $id ( keys %json ) { + my $code = $name ."-". $id; + if( my $chash = $modules{HUEDevice}{defptr}{$code} ) { + $json{$id}->{state}->{reachable} = 1; + HUEDevice_Parse( $chash, $json{$id} ); + } + } +} + return ($obj->[0]); } elsif( ref($obj) eq 'HASH' ) diff --git a/fhem/FHEM/31_HUEDevice.pm b/fhem/FHEM/31_HUEDevice.pm index 3e37a60c3..65dc1c432 100644 --- a/fhem/FHEM/31_HUEDevice.pm +++ b/fhem/FHEM/31_HUEDevice.pm @@ -984,16 +984,16 @@ HUEDevice_Parse($$) $s = 'unreachable' if( !$reachable ); - $hash->{helper}{on} = $on; - $hash->{helper}{reachable} = $reachable; - $hash->{helper}{colormode} = $colormode; - $hash->{helper}{bri} = $bri; - $hash->{helper}{ct} = $ct; - $hash->{helper}{hue} = $hue; - $hash->{helper}{sat} = $sat; - $hash->{helper}{xy} = $xy; - $hash->{helper}{alert} = $alert; - $hash->{helper}{effect} = $effect; + $hash->{helper}{on} = $on if( defined($on) ); + $hash->{helper}{reachable} = $reachable if( defined($reachable) ); + $hash->{helper}{colormode} = $colormode if( defined($colormode) ); + $hash->{helper}{bri} = $bri if( defined($bri) ); + $hash->{helper}{ct} = $ct if( defined($ct) ); + $hash->{helper}{hue} = $hue if( defined($hue) ); + $hash->{helper}{sat} = $sat if( defined($sat) ); + $hash->{helper}{xy} = $xy if( defined($xy) ); + $hash->{helper}{alert} = $alert if( defined($alert) ); + $hash->{helper}{effect} = $effect if( defined($effect) ); $hash->{helper}{percent} = $percent;