From 332b6a0d1713d41a73285dfc204579a81970cc9e Mon Sep 17 00:00:00 2001 From: markus-m <> Date: Wed, 9 Sep 2015 06:55:19 +0000 Subject: [PATCH] 31_MilightDevice: fixed crash on lost connection, 38_CO20: removed errors on timeout git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@9213 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- CHANGED | 2 ++ FHEM/31_MilightDevice.pm | 55 ++++++++++++++++++++-------------------- FHEM/38_CO20.pm | 4 +-- MAINTAINER.txt | 8 +++--- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/CHANGED b/CHANGED index 4363b8543..8d77c494c 100644 --- a/CHANGED +++ b/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - bugfix: 31_MilightDevice.pm: fixed bug that lead to crash on lost bridge connection, added module name prefix to round function + - bugfix: 38_CO20.pm: removed unneccesary error messages due to USB timeout - feature: 70_PushNotifier: use regexe for deviceID - bugfix: 30_pilight_temp: pressure, windavg, winddir, windgust from weather stations without temperature - feature: 74_Unifi: - new readings for controller, accesspoints and clients diff --git a/FHEM/31_MilightDevice.pm b/FHEM/31_MilightDevice.pm index 2b51d16f8..0bf60cace 100644 --- a/FHEM/31_MilightDevice.pm +++ b/FHEM/31_MilightDevice.pm @@ -103,7 +103,7 @@ sub MilightDevice_devStateIcon($) my $name = $hash->{NAME}; my $percent = ReadingsVal($name,"brightness","100"); - my $s = $dim_values{roundfunc($percent/10)}; + my $s = $dim_values{MilightDevice_roundfunc($percent/10)}; # Return SVG coloured icon with toggle as default action return ".*:light_light_$s@#".ReadingsVal($name, "rgb", "FFFFFF").":toggle" @@ -175,7 +175,7 @@ sub MilightDevice_Define($$) if ($hash->{LEDTYPE} eq 'White'); my $defaultcommandset = $hash->{helper}->{COMMANDSET}; - $hash->{helper}->{COMMANDSET} .= " dim:slider,0,".roundfunc(100/MilightDevice_DimSteps($hash)).",100 brightness:slider,0,".roundfunc(100/MilightDevice_DimSteps($hash)).",100"; + $hash->{helper}->{COMMANDSET} .= " dim:slider,0,".MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)).",100 brightness:slider,0,".MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)).",100"; # webCmds if (!defined($attr{$name}{webCmd})) @@ -216,7 +216,7 @@ sub MilightDevice_Init($) if( AttrVal($hash->{NAME}, "gamma", "1.0") eq "1.0") { - Log3 $name, 5, $name." dimstep ".roundfunc(100/MilightDevice_DimSteps($hash))." / gamma 1.0"; + Log3 $name, 5, $name." dimstep ".MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash))." / gamma 1.0"; } else { $hash->{helper}->{COMMANDSET} =~ s/dim:slider,0,.*,100/dim:slider,0,1,100/g; $hash->{helper}->{COMMANDSET} =~ s/brightness:slider,0,.*,100/brightness:slider,0,1,100/g; @@ -430,9 +430,9 @@ sub MilightDevice_Set(@) return $usage if ($args[0] !~ /^([0-9A-Fa-f]{1,2})([0-9A-Fa-f]{1,2})([0-9A-Fa-f]{1,2})$/); my( $r, $g, $b ) = (hex($1)/255.0, hex($2)/255.0, hex($3)/255.0); my( $h, $s, $v ) = Color::rgb2hsv($r,$g,$b); - $h = roundfunc($h * 360); - $s = roundfunc($s * 100); - $v = roundfunc($v * 100); + $h = MilightDevice_roundfunc($h * 360); + $s = MilightDevice_roundfunc($s * 100); + $v = MilightDevice_roundfunc($v * 100); if (defined($args[1])) { return $usage if (($args[1] !~ /^\d+$/) && ($args[1] > 0)); # Decimal value for ramp > 0 @@ -450,7 +450,7 @@ sub MilightDevice_Set(@) elsif ($cmd eq 'dimup') { $usage = "Usage: set $name dimup [percent change(0..100)] [seconds(0..x)]"; - my $percentChange = roundfunc(100 / MilightDevice_DimSteps($hash)); # Default one dimStep + my $percentChange = MilightDevice_roundfunc(100 / MilightDevice_DimSteps($hash)); # Default one dimStep if (defined($args[0])) { # Percent change (0..100%) return $usage if (($args[0] !~ /^\d+$/) || (!($args[0] ~~ [0..100]))); # Decimal value for percent between 0..100 @@ -481,7 +481,7 @@ sub MilightDevice_Set(@) elsif ($cmd eq 'dimdown') { $usage = "Usage: set $name dimdown [percent change(0..100)] [seconds(0..x)]"; - my $percentChange = roundfunc(100 / MilightDevice_DimSteps($hash)); # Default one dimStep + my $percentChange = MilightDevice_roundfunc(100 / MilightDevice_DimSteps($hash)); # Default one dimStep if (defined($args[0])) { # Percent change (0..100%) return $usage if (($args[0] !~ /^\d+$/) || (!($args[0] ~~ [0..100]))); # Decimal value for percent between 0..100 @@ -707,7 +707,7 @@ sub MilightDevice_Attr(@) } elsif ($cmd eq 'set' && $attribName eq 'defaultBrightness') { - return "defaultBrighness: has to be between ".roundfunc(100/MilightDevice_DimSteps($hash))." and 100" unless ($attribVal ~~ [roundfunc(100/MilightDevice_DimSteps($hash))..100]); + return "defaultBrighness: has to be between ".MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash))." and 100" unless ($attribVal ~~ [MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash))..100]); } return undef; @@ -803,9 +803,9 @@ sub MilightDevice_RGB_On(@) } # When turning on, make sure we request at least minimum dim step. - if ($v < roundfunc(100/MilightDevice_DimSteps($hash))) + if ($v < MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash))) { - $v = roundfunc(100/MilightDevice_DimSteps($hash)); + $v = MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)); } return MilightDevice_RGB_Dim($hash, $v, $ramp, $flags); @@ -825,7 +825,7 @@ sub MilightDevice_RGB_Off(@) MilightDevice_BridgeDevices_Update($hash, "brightness_on") if ($hash->{SLOT} eq 'A' && AttrVal($hash->{NAME}, "updateGroupDevices", 0) == 1); # Dim down to min brightness then send off command (avoid flicker on turn on) - MilightDevice_RGB_Dim($hash, roundfunc(100/MilightDevice_DimSteps($hash)), $ramp, $flags); + MilightDevice_RGB_Dim($hash, MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)), $ramp, $flags); return MilightDevice_RGB_Dim($hash, 0, 0, 'q'); } else @@ -916,8 +916,8 @@ sub MilightDevice_RGB_ColorConverter(@) my $color = $hash->{helper}->{COLORMAP}[$h % 360]; # there are 0..9 dim level, setup correction - my $valueSpread = roundfunc(100/MilightDevice_DimSteps($hash)); - my $totalVal = roundfunc($v / $valueSpread); + my $valueSpread = MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)); + my $totalVal = MilightDevice_roundfunc($v / $valueSpread); # saturation 100..50: color full, white increase. 50..0 white full, color decrease my $colorVal = ($s >= 50) ? $totalVal : int(($s / 50 * $totalVal) +0.5); my $whiteVal = ($s >= 50) ? int(((100-$s) / 50 * $totalVal) +0.5) : $totalVal; @@ -981,9 +981,9 @@ sub MilightDevice_RGBW_On(@) $v = ReadingsVal($hash->{NAME}, "brightness", AttrVal($hash->{NAME}, "defaultBrightness", 36)); } # When turning on, make sure we request at least minimum dim step. - if ($v < roundfunc(100/MilightDevice_DimSteps($hash))) + if ($v < MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash))) { - $v = roundfunc(100/MilightDevice_DimSteps($hash)); + $v = MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)); } return MilightDevice_RGBW_Dim($hash, $v, $ramp, $flags); @@ -1003,7 +1003,7 @@ sub MilightDevice_RGBW_Off(@) MilightDevice_BridgeDevices_Update($hash, "brightness_on") if ($hash->{SLOT} eq 'A' && AttrVal($hash->{NAME}, "updateGroupDevices", 0) == 1); # Dim down to min brightness then send off command (avoid flicker on turn on) - MilightDevice_RGBW_Dim($hash, roundfunc(100/MilightDevice_DimSteps($hash)), $ramp, $flags); + MilightDevice_RGBW_Dim($hash, MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)), $ramp, $flags); return MilightDevice_RGBW_Dim($hash, 0, 0, 'q'); } else @@ -1059,7 +1059,7 @@ sub MilightDevice_RGBW_SetHSV(@) # brightness 2..27 (x02..x1b) | 25 dim levels - my $cf = roundfunc((($gammaVal / 100) * MilightDevice_DimSteps($hash)) + 1); + my $cf = MilightDevice_roundfunc((($gammaVal / 100) * MilightDevice_DimSteps($hash)) + 1); if ($sat < 20) { $wl = $cf; @@ -1242,9 +1242,9 @@ sub MilightDevice_White_On(@) $v = ReadingsVal($hash->{NAME}, "brightness", AttrVal($hash->{NAME}, "defaultBrightness", 36)); } # When turning on, make sure we request at least minimum dim step. - if ($v < roundfunc(100/MilightDevice_DimSteps($hash))) + if ($v < MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash))) { - $v = roundfunc(100/MilightDevice_DimSteps($hash)); + $v = MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)); } return MilightDevice_White_Dim($hash, $v, $ramp, $flags); } @@ -1265,7 +1265,7 @@ sub MilightDevice_White_Off(@) MilightDevice_BridgeDevices_Update($hash, "brightness_on") if ($hash->{SLOT} eq 'A' && AttrVal($hash->{NAME}, "updateGroupDevices", 0) == 1); } # Dim down to min brightness then send off command (avoid flicker on turn on) - MilightDevice_White_Dim($hash, roundfunc(100/MilightDevice_DimSteps($hash)), $ramp, $flags); + MilightDevice_White_Dim($hash, MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)), $ramp, $flags); return MilightDevice_White_Dim($hash, 0, 0, 'q'); } else @@ -1314,9 +1314,9 @@ sub MilightDevice_White_DimOn(@) $v = ReadingsVal($hash->{NAME}, "brightness", AttrVal($hash->{NAME}, "defaultBrightness", 36)); } # When turning on, make sure we request at least minimum dim step. - if ($v < roundfunc(100/MilightDevice_DimSteps($hash))) + if ($v < MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash))) { - $v = roundfunc(100/MilightDevice_DimSteps($hash)); + $v = MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)); } MilightDevice_White_Dim($hash, $v, $ramp, $flags); @@ -1377,7 +1377,7 @@ sub MilightDevice_White_SetHSV(@) # Calculate brightness hardware value (11 steps for white) my $maxWl = (100 / MilightDevice_DimSteps($hash)); - my $wl = roundfunc($gammaVal / $maxWl); + my $wl = MilightDevice_roundfunc($gammaVal / $maxWl); # On first load, whiteLevel won't be defined, define it. $hash->{helper}->{whiteLevel} = $wl if (!defined($hash->{helper}->{whiteLevel})); @@ -1738,7 +1738,7 @@ sub MilightDevice_HSV_Transition(@) $satToSet += $satStep; # Increment new saturation by step (negative step decrements) $valToSet += $valStep; # Increment new brightness by step (negative step decrements) Log3 ($hash, 4, "$hash->{NAME}_HSV_Transition: Add to Queue: h:".($hueToSet).", s:".($satToSet).", v:".($valToSet)." ($i/$steps)"); - MilightDevice_CmdQueue_Add($hash, roundfunc($hueToSet), roundfunc($satToSet), roundfunc($valToSet), undef, $stepWidth, $timeFrom + (($i-1) * $stepWidth / 1000) ); + MilightDevice_CmdQueue_Add($hash, MilightDevice_roundfunc($hueToSet), MilightDevice_roundfunc($satToSet), MilightDevice_roundfunc($valToSet), undef, $stepWidth, $timeFrom + (($i-1) * $stepWidth / 1000) ); } # Set target time for completion of sequence. # This may be slightly higher than what was requested since $stepWidth > minDelay (($steps * $stepWidth) > $ramp) @@ -1915,7 +1915,7 @@ sub MilightDevice_CreateGammaMapping(@) { my $correction = ($i / 100) ** (1 / $gamma); $gammaMap[$i] = $correction * 100; - $gammaMap[$i] = roundfunc(100/MilightDevice_DimSteps($hash)) if($gammaMap[$i] < roundfunc(100/MilightDevice_DimSteps($hash))); + $gammaMap[$i] = MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash)) if($gammaMap[$i] < MilightDevice_roundfunc(100/MilightDevice_DimSteps($hash))); Log3 ($hash, 5, "$hash->{NAME} create gammamap v-in: ".$i.", v-out: $gammaMap[$i]"); } @@ -1953,6 +1953,7 @@ sub MilightDevice_CmdQueue_Add(@) # sender busy ? if(defined($actualCmd)) { + return undef if (ref($actualCmd) ne 'HASH'); return undef if (!defined($actualCmd->{inProgess})); return undef if (($actualCmd->{inProgess} || 0) == 1); } @@ -2090,7 +2091,7 @@ sub MilightDevice_BridgeDevices_Update(@) return undef; } -sub roundfunc($) { +sub MilightDevice_roundfunc($) { my ($number) = @_; return sprintf("%.0f", $number); #return Math::Round::round($number); diff --git a/FHEM/38_CO20.pm b/FHEM/38_CO20.pm index cf30929a4..7dbb4b95e 100755 --- a/FHEM/38_CO20.pm +++ b/FHEM/38_CO20.pm @@ -405,7 +405,7 @@ CO20_dataread($$) $hash->{DEV}->interrupt_read(0x00000081, $buf, 0x0000010, $hash->{timeout}); $data.=$buf; Log3 $name, 4, "getdata read $ret" if($ret != 16); - $intdata = ord(substr($buf,0,1))." ".ord(substr($buf,1,1))." ".ord(substr($buf,2,1))." ".ord(substr($buf,3,1))." ".ord(substr($buf,4,1))." ".ord(substr($buf,5,1))." ".ord(substr($buf,6,1))." ".ord(substr($buf,7,1))." ".ord(substr($buf,8,1))." ".ord(substr($buf,9,1))." ".ord(substr($buf,10,1))." ".ord(substr($buf,11,1))." ".ord(substr($buf,12,1))." ".ord(substr($buf,13,1))." ".ord(substr($buf,14,1))." ".ord(substr($buf,15,1)); + $intdata = ord(substr($buf,0,1))." ".ord(substr($buf,1,1))." ".ord(substr($buf,2,1))." ".ord(substr($buf,3,1))." ".ord(substr($buf,4,1))." ".ord(substr($buf,5,1))." ".ord(substr($buf,6,1))." ".ord(substr($buf,7,1))." ".ord(substr($buf,8,1))." ".ord(substr($buf,9,1))." ".ord(substr($buf,10,1))." ".ord(substr($buf,11,1))." ".ord(substr($buf,12,1))." ".ord(substr($buf,13,1))." ".ord(substr($buf,14,1))." ".ord(substr($buf,15,1)) if(length($buf) > 15); Log3 $name, 5, "$intdata\n$buf"; } Log3 $name, 5, length($data); @@ -537,7 +537,7 @@ CO20_dataset($$$) } - if($ret == 16) { + if($ret == 16 and $buflen > 15) { $hash->{DEV}->interrupt_read(0x00000081, $buf, 0x0000010, $hash->{timeout}); Log3 $name, 5, "getdata read $ret"; my $intdata .= ord(substr($buf,0,1))." ".ord(substr($buf,1,1))." ".ord(substr($buf,2,1))." ".ord(substr($buf,3,1))." ".ord(substr($buf,4,1))." ".ord(substr($buf,5,1))." ".ord(substr($buf,6,1))." ".ord(substr($buf,7,1))." ".ord(substr($buf,8,1))." ".ord(substr($buf,9,1))." ".ord(substr($buf,10,1))." ".ord(substr($buf,11,1))." ".ord(substr($buf,12,1))." ".ord(substr($buf,13,1))." ".ord(substr($buf,14,1))." ".ord(substr($buf,15,1)); diff --git a/MAINTAINER.txt b/MAINTAINER.txt index fceb1fff6..5548e5102 100644 --- a/MAINTAINER.txt +++ b/MAINTAINER.txt @@ -110,20 +110,20 @@ FHEM/23_WEBIO_12DIGITAL.pm sachag http://forum.fhem.de Sonstiges FHEM/24_NetIO230B.pm rudolfkoenig/orphan http://forum.fhem.de Sonstiges FHEM/30_HUEBridge.pm justme1968 http://forum.fhem.de Beleuchtung FHEM/30_LIGHTIFY.pm justme1968 http://forum.fhem.de Beleuchtung -FHEM/30_MilightBridge.pm mattwire http://forum.fhem.de Beleuchtung +FHEM/30_MilightBridge.pm mattwire/markus-m http://forum.fhem.de Beleuchtung FHEM/30_ENECSYSGW.pm akw http://forum.fhem.de Sonstige Systeme FHEM/30_pilight_dimmer.pm risiko http://forum.fhem.de Sonstige Systeme FHEM/30_pilight_switch.pm risiko http://forum.fhem.de Sonstige Systeme FHEM/30_pilight_temp.pm risiko http://forum.fhem.de Sonstige Systeme FHEM/30_pilight_raw.pm risiko http://forum.fhem.de Sonstige Systeme FHEM/31_HUEDevice.pm justme1968 http://forum.fhem.de Beleuchtung -FHEM/31_MilightDevice.pm mattwire http://forum.fhem.de Beleuchtung +FHEM/31_MilightDevice.pm mattwire/markus-m http://forum.fhem.de Beleuchtung FHEM/31_ENECSYSINV.pm akw http://forum.fhem.de Sonstige Systeme FHEM/31_LightScene.pm justme1968 http://forum.fhem.de Automatisierung FHEM/32_SYSSTAT.pm justme1968 http://forum.fhem.de Unterstuetzende Dienste FHEM/32_mailcheck.pm justme1968 http://forum.fhem.de Automatisierung FHEM/32_yowsup.pm justme1968 http://forum.fhem.de Unterstuetzende Dienste -FHEM/32_withings.pm justme1968 http://forum.fhem.de Sonstiges +FHEM/32_withings.pm markus-m http://forum.fhem.de Sonstiges FHEM/33_readingsGroup.pm justme1968 http://forum.fhem.de Frontends FHEM/33_readingsHistory.pm justme1968 http://forum.fhem.de Frontends FHEM/33_readingsProxy.pm justme1968 http://forum.fhem.de Automatisierung @@ -143,7 +143,7 @@ FHEM/36_WMBUS.pm kaihs http://forum.fhem.de Sonstige FHEM/37_SHC.pm rr2000 http://forum.fhem.de Sonstige Systeme FHEM/37_SHCdev.pm rr2000 http://forum.fhem.de Sonstige Systeme FHEM/38_harmony.pm justme1968 http://forum.fhem.de Multimedia -FHEM/38_CO20.pm justme1968 http://forum.fhem.de Sonstiges +FHEM/38_CO20.pm markus-m http://forum.fhem.de Sonstiges FHEM/38_JawboneUp.pm domschl http://forum.fhem.de Sonstiges FHEM/40_RFXCOM.pm wherzig http://forum.fhem.de RFXTRX FHEM/41_OREGON.pm wherzig http://forum.fhem.de Sonstiges