From e1d3aea5412181ac36659a84de04048007ee98b6 Mon Sep 17 00:00:00 2001 From: justme1968 Date: Mon, 2 Sep 2013 19:31:38 +0000 Subject: [PATCH] switched to log3 added alert command git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@3842 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/30_HUEBridge.pm | 41 +++++++++++++++++++++------------------ fhem/FHEM/31_HUEDevice.pm | 35 +++++++++++++++++++++------------ 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index cf964ec6b..95e5c16f9 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. - SVN + - feature: HUEDevice: added alert command - change: The DBLOG propagated Attribute DbLogExclude will work as regexp to exclude defined readings to log. If a MinInterval is set, the logentry is dropped if the diff --git a/fhem/FHEM/30_HUEBridge.pm b/fhem/FHEM/30_HUEBridge.pm index b64ac1892..7c78591cc 100644 --- a/fhem/FHEM/30_HUEBridge.pm +++ b/fhem/FHEM/30_HUEBridge.pm @@ -29,7 +29,7 @@ sub HUEBridge_Initialize($) $hash->{SetFn} = "HUEBridge_Set"; $hash->{GetFn} = "HUEBridge_Get"; $hash->{UndefFn} = "HUEBridge_Undefine"; - $hash->{AttrList}= "key loglevel:0,1,2,3,4,5"; + $hash->{AttrList}= "key"; } sub @@ -250,7 +250,7 @@ HUEBridge_Autocreate($) next if($defs{$d}{TYPE} ne "HUEDevice"); if(defined($defs{$d}{fhem}) && defined($defs{$d}{fhem}{id}) && $defs{$d}{fhem}{id} eq $id) { - Log 5, "$name id '$id' already defined as '$defs{$d}{NAME}'"; + Log3 $name, 5, "$name id '$id' already defined as '$defs{$d}{NAME}'"; $found = 1; last; } @@ -260,11 +260,11 @@ HUEBridge_Autocreate($) my $devname= "HUEDevice" . $id; my $define= "$devname HUEDevice $id"; - Log 5, "$name create new device '$devname' for address '$id'"; + Log3 $name, 5, "$name create new device '$devname' for address '$id'"; my $cmdret= CommandDefine(undef,$define); if($cmdret) { - Log 1, "$name: Autocreate: An error occurred while creating device for id '$id': $cmdret"; + Log3 $name, 1, "$name: Autocreate: An error occurred while creating device for id '$id': $cmdret"; } else { $cmdret= CommandAttr(undef,"$devname alias ".$result->{$id}{name}); $cmdret= CommandAttr(undef,"$devname room HUEDevice"); @@ -278,9 +278,10 @@ HUEBridge_Autocreate($) sub HUEBridge_ProcessResponse($$) { my ($hash,$obj) = @_; + my $name = $hash->{NAME}; - #Log 3, ref($obj); - #Log 3, "Receiving: " . Dumper $obj; + #Log3 $name, 3, ref($obj); + #Log3 $name, 3, "Receiving: " . Dumper $obj; if( ref($obj) eq 'ARRAY' ) { @@ -290,7 +291,7 @@ sub HUEBridge_ProcessResponse($$) $hash->{STATE} = $error; - Log 3, $error; + Log3 $name, 3, $error; } return ($obj->[0]); @@ -321,7 +322,7 @@ HUEBridge_Call($$$) { my ($hash,$path,$obj) = @_; - #Log 3, "Sending: " . Dumper $obj; + #Log3 $name, 3, "Sending: " . Dumper $obj; my $json = undef; $json = encode_json($obj) if $obj; @@ -333,6 +334,8 @@ HUEBridge_Call($$$) sub HUEBridge_HTTP_Call($$$) { my ($hash,$path,$obj) = @_; + my $name = $hash->{NAME}; + my $uri = "http://" . $hash->{Host} . "/api"; my $method = 'GET'; if( defined($obj) ) { @@ -341,17 +344,17 @@ sub HUEBridge_HTTP_Call($$$) if( $hash->{STATE} eq 'Pairing' ) { $method = 'POST'; } else { - $uri .= "/" . AttrVal($hash->{NAME}, "key", ""); + $uri .= "/" . AttrVal($name, "key", ""); } } else { - $uri .= "/" . AttrVal($hash->{NAME}, "key", ""); + $uri .= "/" . AttrVal($name, "key", ""); } if( defined $path) { $uri .= "/" . $path; } - #Log 3, "Url: " . $uri; + #Log3 $name, 3, "Url: " . $uri; my $ret = HUEBridge_HTTP_Request(0,$uri,$method,undef,$obj,undef); - #Log 3, Dumper $ret; + #Log3 $name, 3, Dumper $ret; if( !defined($ret) ) { return undef; } elsif($ret eq '') { @@ -378,7 +381,7 @@ HUEBridge_HTTP_Request($$$@) my $displayurl= $quiet ? "" : $url; if($url !~ /^(http|https):\/\/([^:\/]+)(:\d+)?(\/.*)$/) { - Log 1, "HUEBridge_HTTP_Request $displayurl: malformed or unsupported URL"; + Log3 undef, 1, "HUEBridge_HTTP_Request $displayurl: malformed or unsupported URL"; return undef; } @@ -396,7 +399,7 @@ HUEBridge_HTTP_Request($$$@) if($protocol eq "https") { eval "use IO::Socket::SSL"; if($@) { - Log 1, $@; + Log3 undef, 1, $@; } else { $conn = IO::Socket::SSL->new(PeerAddr=>"$host:$port", Timeout=>$timeout); } @@ -404,7 +407,7 @@ HUEBridge_HTTP_Request($$$@) $conn = IO::Socket::INET->new(PeerAddr=>"$host:$port", Timeout=>$timeout); } if(!$conn) { - Log 1, "HUEBridge_HTTP_Request $displayurl: Can't connect to $protocol://$host:$port\n"; + Log3 undef, 1, "HUEBridge_HTTP_Request $displayurl: Can't connect to $protocol://$host:$port\n"; undef $conn; return undef; } @@ -428,7 +431,7 @@ HUEBridge_HTTP_Request($$$@) vec($rin, $conn->fileno(), 1) = 1; my $nfound = select($rout=$rin, undef, undef, $timeout); if($nfound <= 0) { - Log 1, "HUEBridge_HTTP_Request $displayurl: Select timeout/error: $!"; + Log3 undef, 1, "HUEBridge_HTTP_Request $displayurl: Select timeout/error: $!"; undef $conn; return undef; } @@ -441,11 +444,11 @@ HUEBridge_HTTP_Request($$$@) $ret=~ s/(.*?)\r\n\r\n//s; # Not greedy: switch off the header. my @header= split("\r\n", $1); my $hostpath= $quiet ? "" : $host . $path; - Log 5, "HUEBridge_HTTP_Request $displayurl: Got data, length: ".length($ret); + Log3 undef, 5, "HUEBridge_HTTP_Request $displayurl: Got data, length: ".length($ret); if(!length($ret)) { - Log 4, "HUEBridge_HTTP_Request $displayurl: Zero length data, header follows..."; + Log3 undef, 4, "HUEBridge_HTTP_Request $displayurl: Zero length data, header follows..."; for (@header) { - Log 4, "HUEBridge_HTTP_Request $displayurl: $_"; + Log3 undef, 4, "HUEBridge_HTTP_Request $displayurl: $_"; } } undef $conn; diff --git a/fhem/FHEM/31_HUEDevice.pm b/fhem/FHEM/31_HUEDevice.pm index dfe48b5d8..89a65021c 100644 --- a/fhem/FHEM/31_HUEDevice.pm +++ b/fhem/FHEM/31_HUEDevice.pm @@ -22,6 +22,7 @@ my %hueModels = ( LLC005 => {name => 'LivingColors Bloom' ,type => 'Color Light' ,subType => 'colordimmer',}, LLC006 => {name => 'LivingColors Iris' ,type => 'Color Light' ,subType => 'colordimmer',}, LLC007 => {name => 'LivingColors Bloom' ,type => 'Color Light' ,subType => 'colordimmer',}, + LST001 => {name => 'LightStrips' ,type => 'Color Light' ,subType => 'colordimmer',}, LWB001 => {name => 'LivingWhites Bulb' ,type => 'Dimmable light' ,subType => 'dimmer',}, LWL001 => {name => 'LivingWhites Outlet' ,type => 'Dimmable plug-in unit' ,subType => 'dimmer',}, ); @@ -107,7 +108,6 @@ HUEDevice_devStateIcon($) sub HUEDevice_summaryFn($$$$) { -Log 3, "HUEDevice_summaryFn"; my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn. my $hash = $defs{$d}; my $name = $hash->{NAME}; @@ -145,6 +145,8 @@ sub HUEDevice_Define($$) $hash->{fhem}{hue} = -1; $hash->{fhem}{sat} = -1; $hash->{fhem}{xy} = ''; + $hash->{fhem}{alert} = ''; + $hash->{fhem}{effect} = ''; $hash->{fhem}{percent} = -1; @@ -153,9 +155,9 @@ sub HUEDevice_Define($$) AssignIoPort($hash); if(defined($hash->{IODev}->{NAME})) { - Log 3, "$name: I/O device is " . $hash->{IODev}->{NAME}; + Log3 $name, 3, "$name: I/O device is " . $hash->{IODev}->{NAME}; } else { - Log 1, "$name: no I/O device"; + Log3 $name, 1, "$name: no I/O device"; } #HUEDevice_GetUpdate($hash); @@ -231,19 +233,19 @@ HUEDevice_SetParam($$@) } elsif( $cmd eq "rgb" && $value =~ m/^(..)(..)(..)/) { # calculation from http://www.everyhue.com/vanilla/discussion/94/rgb-to-xy-or-hue-sat-values/p1 my( $r, $g, $b ) = (hex($1)/255.0, hex($2)/255.0, hex($3)/255.0); -#Log 3, "rgb: ". $r . " " . $g ." ". $b; +#Log3 $name, 3, "rgb: ". $r . " " . $g ." ". $b; my $X = 1.076450 * $r - 0.237662 * $g + 0.161212 * $b; my $Y = 0.410964 * $r + 0.554342 * $g + 0.034694 * $b; my $Z = -0.010954 * $r - 0.013389 * $g + 1.024343 * $b; -#Log 3, "XYZ: ". $X . " " . $Y ." ". $Y; +#Log3 $name, 3, "XYZ: ". $X . " " . $Y ." ". $Y; if( $X != 0 || $Y != 0 || $Z != 0 ) { my $x = $X / ($X + $Y + $Z); my $y = $Y / ($X + $Y + $Z); -#Log 3, "xyY:". $x . " " . $y ." ". $Y; +#Log3 $name, 3, "xyY:". $x . " " . $y ." ". $Y; #$x = 0 if( $x < 0 ); #$x = 1 if( $x > 1 ); @@ -268,6 +270,8 @@ HUEDevice_SetParam($$@) $obj->{'hue'} = int($h*256); $obj->{'sat'} = 0+$s; $obj->{'bri'} = 0+$v; + } elsif( $cmd eq "alert" ) { + $obj->{'alert'} = $value; } elsif( $cmd eq "effect" ) { $obj->{'effect'} = $value; } elsif( $cmd eq "transitiontime" ) { @@ -319,7 +323,7 @@ HUEDevice_Set($@) } my $list = "off:noArg on:noArg toggle:noArg statusRequest:noArg"; - $list .= " pct:slider,0,1,100 bri:slider,0,1,254" if( AttrVal($name, "subType", "colordimmer") =~ m/dimmer/ ); + $list .= " pct:slider,0,1,100 bri:slider,0,1,254 alert:none,select,lselect" if( AttrVal($name, "subType", "colordimmer") =~ m/dimmer/ ); #$list .= " dim06% dim12% dim18% dim25% dim31% dim37% dim43% dim50% dim56% dim62% dim68% dim75% dim81% dim87% dim93% dim100%" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/dimmer/ ); $list .= " rgb:colorpicker,RGB color:slider,2000,1,6500 ct:slider,154,1,500 hue:slider,0,1,65535 sat:slider,0,1,254 xy effect:none,colorloop" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/color/ ); return SetExtensions($hash, $list, $name, @aa); @@ -468,26 +472,26 @@ HUEDevice_ReadFromServer($@) { my ($hash,@a) = @_; - my $dev = $hash->{NAME}; + my $name = $hash->{NAME}; no strict "refs"; my $ret; - unshift(@a,$dev); + unshift(@a,$name); $ret = IOWrite($hash, @a); use strict "refs"; return $ret; - return if(IsDummy($dev) || IsIgnored($dev)); + return if(IsDummy($name) || IsIgnored($name)); my $iohash = $hash->{IODev}; if(!$iohash || !$iohash->{TYPE} || !$modules{$iohash->{TYPE}} || !$modules{$iohash->{TYPE}}{ReadFn}) { - Log 5, "No I/O device or ReadFn found for $dev"; + Log3 $name, 5, "No I/O device or ReadFn found for $name"; return; } no strict "refs"; #my $ret; - unshift(@a,$dev); + unshift(@a,$name); $ret = &{$modules{$iohash->{TYPE}}{ReadFn}}($iohash, @a); use strict "refs"; return $ret; @@ -545,6 +549,8 @@ HUEDevice_GetUpdate($) my $sat = $state->{'sat'}; my $xy = undef; $xy = $state->{'xy'}->[0] .",". $state->{'xy'}->[1] if( defined($state->{'xy'}) ); + my $alert = $state->{alert}; + my $effect = $state->{effect}; if( defined($colormode) && $colormode ne $hash->{fhem}{colormode} ) {readingsBulkUpdate($hash,"colormode",$colormode);} if( defined($bri) && $bri != $hash->{fhem}{bri} ) {readingsBulkUpdate($hash,"bri",$bri);} @@ -560,6 +566,8 @@ HUEDevice_GetUpdate($) if( defined($sat) && $sat != $hash->{fhem}{sat} ) {readingsBulkUpdate($hash,"sat",$sat);} if( defined($xy) && $xy ne $hash->{fhem}{xy} ) {readingsBulkUpdate($hash,"xy",$xy);} if( defined($reachable) && $reachable ne $hash->{fhem}{reachable} ) {readingsBulkUpdate($hash,"reachable",$reachable);} + if( defined($alert) && $alert ne $hash->{fhem}{alert} ) {readingsBulkUpdate($hash,"alert",$alert);} + if( defined($effect) && $effect ne $hash->{fhem}{effect} ) {readingsBulkUpdate($hash,"effect",$effect);} my $s = ''; my $percent; @@ -600,6 +608,8 @@ HUEDevice_GetUpdate($) $hash->{fhem}{hue} = $hue; $hash->{fhem}{sat} = $sat; $hash->{fhem}{xy} = $xy; + $hash->{fhem}{alert} = $alert; + $hash->{fhem}{effect} = $effect; $hash->{fhem}{percent} = $percent; } @@ -685,6 +695,7 @@ HUEDevice_GetUpdate($) set saturation to <value>; range is 0-254.
  • xy <x>,<y>
    set the xy color coordinates to <x>,<y>
  • +
  • alert [none|select|lselect]
  • effect [none|colorloop]
  • transitiontime <time>
    set the transitiontime to <time> 1/10s