From 37b4c925b8debffdffbf31ba94ca89b60d1d92e4 Mon Sep 17 00:00:00 2001 From: justme-1968 Date: Thu, 22 Dec 2016 20:57:17 +0000 Subject: [PATCH] 30_HUEBridge.pm: added pollDevices 2 31_HUEDevice.pm: allow optional polling intervall for groups git-svn-id: https://svn.fhem.de/fhem/trunk@12864 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/30_HUEBridge.pm | 11 +++++++---- fhem/FHEM/31_HUEDevice.pm | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/fhem/FHEM/30_HUEBridge.pm b/fhem/FHEM/30_HUEBridge.pm index 5b55f7e57..c5d0a81a9 100644 --- a/fhem/FHEM/30_HUEBridge.pm +++ b/fhem/FHEM/30_HUEBridge.pm @@ -40,7 +40,7 @@ sub HUEBridge_Initialize($) $hash->{GetFn} = "HUEBridge_Get"; $hash->{AttrFn} = "HUEBridge_Attr"; $hash->{UndefFn} = "HUEBridge_Undefine"; - $hash->{AttrList} = "key disable:1 disabledForIntervals httpUtils:1,0 noshutdown:1,0 pollDevices:1,0 queryAfterSet:1,0 $readingFnAttributes"; + $hash->{AttrList} = "key disable:1 disabledForIntervals httpUtils:1,0 noshutdown:1,0 pollDevices:1,2,0 queryAfterSet:1,0 $readingFnAttributes"; } sub @@ -775,9 +775,10 @@ HUEBridge_GetUpdate($) my $type; my $result; - if( AttrVal($name,"pollDevices",1) ) { + my $poll_devices = AttrVal($name, "pollDevices", 1); + if( $poll_devices ) { my ($now) = gettimeofday(); - if( $hash->{LOCAL} || $now - $hash->{helper}{last_config_timestamp} > 300 ) { + if( $poll_devices > 1 || $hash->{LOCAL} || $now - $hash->{helper}{last_config_timestamp} > 300 ) { $result = HUEBridge_Call($hash, $hash, undef, undef); $hash->{helper}{last_config_timestamp} = $now; } else { @@ -1614,7 +1615,9 @@ HUEBridge_Attr($$$)
  • disable
  • disabledForIntervals
  • pollDevices
    - the bridge will poll all devices instead of each device itself. default is 1.
  • + 1 -> the bridge will poll all lights in one go instead of each device polling itself independently
    + 2 -> the bridge will poll all devices in one go instead of each device polling itself independently
    + default is 1.
  • queryAfterSet
    the bridge will request the real device state after a set command. default is 1.
  • noshutdown
    diff --git a/fhem/FHEM/31_HUEDevice.pm b/fhem/FHEM/31_HUEDevice.pm index 8d9f5c401..78290d260 100644 --- a/fhem/FHEM/31_HUEDevice.pm +++ b/fhem/FHEM/31_HUEDevice.pm @@ -273,17 +273,19 @@ sub HUEDevice_Define($$) $modules{HUEDevice}{defptr}{$code} = $hash; - if( AttrVal($iodev, "pollDevices", undef) ) { - $interval = 0 unless defined($interval); - } else { + if( AttrVal($iodev, "pollDevices", 1) ) { + $interval = undef unless defined($interval); + + } elsif( !$hash->{helper}->{devtype} || $hash->{helper}->{devtype} ne 'G' ) { $interval = 60 unless defined($interval); + } $args[3] = "" if( !defined( $args[3] ) ); if( !$hash->{helper}->{devtype} ) { $hash->{DEF} = "$id $args[3] IODev=$iodev" if( $iodev ); - $interval = 60 if( $interval && $interval < 10 ); + $interval = 60 if( defined($interval) && $interval < 10 ); $hash->{INTERVAL} = $interval; $hash->{helper}{on} = -1; @@ -308,6 +310,9 @@ sub HUEDevice_Define($$) } elsif( $hash->{helper}->{devtype} eq 'G' ) { $hash->{DEF} = "group $id $args[3] IODev=$iodev" if( $iodev ); + $interval = 60 if( defined($interval) && $interval < 10 ); + $hash->{INTERVAL} = $interval; + $hash->{helper}{all_on} = -1; $hash->{helper}{any_on} = -1; @@ -321,7 +326,7 @@ sub HUEDevice_Define($$) } elsif( $hash->{helper}->{devtype} eq 'S' ) { $hash->{DEF} = "sensor $id $args[3] IODev=$iodev" if( $iodev ); - $interval = 60 if( $interval && $interval < 1 ); + $interval = 60 if( defined($interval) && $interval < 1 ); $hash->{INTERVAL} = $interval; } @@ -754,7 +759,7 @@ HUEDevice_Set($@) return undef; } - $hash->{".triggerUsed"} = 1 if( $hash->{helper}->{devtype} ne 'G' ); + $hash->{".triggerUsed"} = 1; return undef if( !defined($result) ); if( $hash->{helper}->{update_timeout} == -1 ) { @@ -997,7 +1002,6 @@ HUEDevice_GetUpdate($) HUEDevice_Parse($hash,$result); - return undef; } elsif( $hash->{helper}->{devtype} eq 'S' ) { } @@ -1006,6 +1010,8 @@ HUEDevice_GetUpdate($) InternalTimer(gettimeofday()+$hash->{INTERVAL}, "HUEDevice_GetUpdate", $hash, 0) if( $hash->{INTERVAL} ); } + return undef if( $hash->{helper}->{devtype} eq 'G' ); + my $result = HUEDevice_ReadFromServer($hash,$hash->{ID}); if( !defined($result) ) { $hash->{helper}{reachable} = 0; @@ -1066,7 +1072,6 @@ HUEDevice_Parse($$) $hash->{uniqueid} = $result->{uniqueid} if( defined($result->{uniqueid}) ); if( $hash->{helper}->{devtype} eq 'G' ) { - $hash->{STATE} = 'Initialized'; if( $result->{lights} ) { $hash->{lights} = join( ",", @{$result->{lights}} ); } else {