From a7179c57ce6d06d77a61d2f6eb68546872887e12 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 8 Jan 2020 04:21:09 +0100 Subject: [PATCH] code style Log3 Fn --- 74_XiaomiBTLESens.pm | 162 +++++++++++++++++++++---------------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/74_XiaomiBTLESens.pm b/74_XiaomiBTLESens.pm index f432049..e95c9e7 100644 --- a/74_XiaomiBTLESens.pm +++ b/74_XiaomiBTLESens.pm @@ -2,7 +2,7 @@ # # Developed with Kate # -# (c) 2017-2018 Copyright: Marko Oldenburg (leongaultier at gmail dot com) +# (c) 2017-2020 Copyright: Marko Oldenburg (leongaultier at gmail dot com) # All rights reserved # # Special thanks goes to: @@ -262,7 +262,7 @@ sub Define($$) { CommandAttr( undef, $name . ' room XiaomiBTLESens' ) if ( AttrVal( $name, 'room', 'none' ) eq 'none' ); - Log3 $name, 3, "XiaomiBTLESens ($name) - defined with BTMAC $hash->{BTMAC}"; + Log3($name, 3, "XiaomiBTLESens ($name) - defined with BTMAC $hash->{BTMAC}"); $modules{XiaomiBTLESens}{defptr}{ $hash->{BTMAC} } = $hash; return undef; @@ -280,7 +280,7 @@ sub Undef($$) { if ( defined( $hash->{helper}{RUNNING_PID} ) ); delete( $modules{XiaomiBTLESens}{defptr}{$mac} ); - Log3 $name, 3, "Sub XiaomiBTLESens_Undef ($name) - delete device $name"; + Log3($name, 3, "Sub XiaomiBTLESens_Undef ($name) - delete device $name"); return undef; } @@ -294,11 +294,11 @@ sub Attr(@) { RemoveInternalTimer($hash); readingsSingleUpdate( $hash, "state", "disabled", 1 ); - Log3 $name, 3, "XiaomiBTLESens ($name) - disabled"; + Log3($name, 3, "XiaomiBTLESens ($name) - disabled"); } elsif ( $cmd eq "del" ) { - Log3 $name, 3, "XiaomiBTLESens ($name) - enabled"; + Log3($name, 3, "XiaomiBTLESens ($name) - enabled"); } } @@ -307,12 +307,12 @@ sub Attr(@) { return "check disabledForIntervals Syntax HH:MM-HH:MM or 'HH:MM-HH:MM HH:MM-HH:MM ...'" unless ( $attrVal =~ /^((\d{2}:\d{2})-(\d{2}:\d{2})\s?)+$/ ); - Log3 $name, 3, "XiaomiBTLESens ($name) - disabledForIntervals"; + Log3($name, 3, "XiaomiBTLESens ($name) - disabledForIntervals"); stateRequest($hash); } elsif ( $cmd eq "del" ) { - Log3 $name, 3, "XiaomiBTLESens ($name) - enabled"; + Log3($name, 3, "XiaomiBTLESens ($name) - enabled"); readingsSingleUpdate( $hash, "state", "active", 1 ); } } @@ -322,35 +322,35 @@ sub Attr(@) { if ( $cmd eq "set" ) { if ( $attrVal < 120 ) { - Log3 $name, 3, -"XiaomiBTLESens ($name) - interval too small, please use something >= 120 (sec), default is 300 (sec)"; + Log3($name, 3, +"XiaomiBTLESens ($name) - interval too small, please use something >= 120 (sec), default is 300 (sec)"); return "interval too small, please use something >= 120 (sec), default is 300 (sec)"; } else { $hash->{INTERVAL} = $attrVal; - Log3 $name, 3, - "XiaomiBTLESens ($name) - set interval to $attrVal"; + Log3($name, 3, + "XiaomiBTLESens ($name) - set interval to $attrVal"); } } elsif ( $cmd eq "del" ) { $hash->{INTERVAL} = 300; - Log3 $name, 3, "XiaomiBTLESens ($name) - set interval to default"; + Log3($name, 3, "XiaomiBTLESens ($name) - set interval to default"); } } elsif ( $attrName eq "blockingCallLoglevel" ) { if ( $cmd eq "set" ) { $hash->{loglevel} = $attrVal; - Log3 $name, 3, - "XiaomiBTLESens ($name) - set blockingCallLoglevel to $attrVal"; + Log3($name, 3, + "XiaomiBTLESens ($name) - set blockingCallLoglevel to $attrVal"); } elsif ( $cmd eq "del" ) { $hash->{loglevel} = 4; - Log3 $name, 3, - "XiaomiBTLESens ($name) - set blockingCallLoglevel to default"; + Log3($name, 3, + "XiaomiBTLESens ($name) - set blockingCallLoglevel to default"); } } @@ -495,8 +495,8 @@ sub stateRequestTimer($) { InternalTimer( gettimeofday() + $hash->{INTERVAL} + int( rand(300) ), "XiaomiBTLESens_stateRequestTimer", $hash ); - Log3 $name, 4, - "XiaomiBTLESens ($name) - stateRequestTimer: Call Request Timer"; + Log3($name, 4, + "XiaomiBTLESens ($name) - stateRequestTimer: Call Request Timer"); } sub Set($$@) { @@ -591,8 +591,8 @@ sub CreateParamGatttool($@) { my $name = $hash->{NAME}; my $mac = $hash->{BTMAC}; - Log3 $name, 4, - "XiaomiBTLESens ($name) - Run CreateParamGatttool with mod: $mod"; + Log3($name, 4, + "XiaomiBTLESens ($name) - Run CreateParamGatttool with mod: $mod"); if ( $mod eq 'read' ) { $hash->{helper}{RUNNING_PID} = BlockingCall( @@ -606,8 +606,8 @@ sub CreateParamGatttool($@) { readingsSingleUpdate( $hash, "state", "read sensor data", 1 ); - Log3 $name, 5, -"XiaomiBTLESens ($name) - Read XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle"; + Log3($name, 5, +"XiaomiBTLESens ($name) - Read XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle"); } elsif ( $mod eq 'write' ) { @@ -627,8 +627,8 @@ sub CreateParamGatttool($@) { readingsSingleUpdate( $hash, "state", "write sensor data", 1 ); - Log3 $name, 5, -"XiaomiBTLESens ($name) - Write XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle|$value"; + Log3($name, 5, +"XiaomiBTLESens ($name) - Write XiaomiBTLESens_ExecGatttool_Run $name|$mac|$mod|$handle|$value"); } } @@ -685,8 +685,8 @@ sub ExecGatttool_Run($) { my $gatttoolCmdlineStaticEscaped = BTLE_CmdlinePreventGrepFalsePositive("gatttool -i $hci -b $mac"); my $psCommand = AttrVal( $name, 'psCommand', 'ps ax' ); - Log3 $name, 5, -"XiaomiBTLESens ($name) - ExecGatttool_Run: Execute Command $psCommand | grep -E $gatttoolCmdlineStaticEscaped"; + Log3($name, 5, +"XiaomiBTLESens ($name) - ExecGatttool_Run: Execute Command $psCommand | grep -E $gatttoolCmdlineStaticEscaped"); # $grepGatttool = qx(ps ax| grep -E \'$gatttoolCmdlineStaticEscaped\') $grepGatttool = @@ -699,8 +699,8 @@ qx(ssh $sshHost '$psCommand | grep -E "$gatttoolCmdlineStaticEscaped"') if ( $sshHost ne 'none' ); if ( not $grepGatttool =~ /^\s*$/ ) { - Log3 $name, 3, -"XiaomiBTLESens ($name) - ExecGatttool_Run: another gatttool process is running. waiting..."; + Log3($name, 3, +"XiaomiBTLESens ($name) - ExecGatttool_Run: another gatttool process is running. waiting..."); sleep(1); } else { @@ -713,17 +713,17 @@ qx(ssh $sshHost '$psCommand | grep -E "$gatttoolCmdlineStaticEscaped"') my $returnCode = 1; do { - Log3 $name, 5, -"XiaomiBTLESens ($name) - ExecGatttool_Run: call gatttool with command: $cmd and loop $loop"; + Log3($name, 5, +"XiaomiBTLESens ($name) - ExecGatttool_Run: call gatttool with command: $cmd and loop $loop"); - ( $returnString, $returnCode ) = Gatttool_executeCommand($cmd); + ($returnString, $returnCode) = Gatttool_executeCommand($cmd); @gtResult = split( ": ", $returnString ); # @gtResult = split( ": ", qx($cmd) ); - Log3 $name, 5, + Log3($name, 5, "XiaomiBTLESens ($name) - ExecGatttool_Run: gatttool loop result " - . join( ",", @gtResult ); + . join( ",", @gtResult )); $loop++; $returnCode = 2 @@ -731,13 +731,13 @@ qx(ssh $sshHost '$psCommand | grep -E "$gatttoolCmdlineStaticEscaped"') # } while ( $loop < 5 and $gtResult[0] eq 'connect error' ); } while ( $loop < 5 and $returnCode != 0 ); - Log3 $name, 3, -"XiaomiBTLESens ($name) - ExecGatttool_Run: errorcode: \"$returnCode\", ErrorString: \"$returnString\"" + Log3($name, 3, +"XiaomiBTLESens ($name) - ExecGatttool_Run: errorcode: \"$returnCode\", ErrorString: \"$returnString\"") if ( $returnCode != 0 ); - Log3 $name, 4, + Log3($name, 4, "XiaomiBTLESens ($name) - ExecGatttool_Run: gatttool result " - . join( ",", @gtResult ); + . join( ",", @gtResult )); $handle = '0x35' if ( $sshHost ne 'none' @@ -791,18 +791,18 @@ sub ExecGatttool_Done($) { delete( $hash->{helper}{RUNNING_PID} ); - Log3 $name, 5, -"XiaomiBTLESens ($name) - ExecGatttool_Done: Helper is disabled. Stop processing" + Log3($name, 5, +"XiaomiBTLESens ($name) - ExecGatttool_Done: Helper is disabled. Stop processing") if ( $hash->{helper}{DISABLED} ); return if ( $hash->{helper}{DISABLED} ); - Log3 $name, 5, -"XiaomiBTLESens ($name) - ExecGatttool_Done: gatttool return string: $string"; + Log3($name, 5, +"XiaomiBTLESens ($name) - ExecGatttool_Done: gatttool return string: $string"); my $decode_json = eval { decode_json($json_notification) }; if ($@) { - Log3 $name, 4, -"XiaomiBTLESens ($name) - ExecGatttool_Done: JSON error while request: $@"; + Log3($name, 4, +"XiaomiBTLESens ($name) - ExecGatttool_Done: JSON error while request: $@"); } if ( $respstate eq 'ok' @@ -836,8 +836,8 @@ sub ExecGatttool_Aborted($) { 'The BlockingCall Process terminated unexpectedly. Timedout'; WriteReadings( $hash, \%readings ); - Log3 $name, 4, -"XiaomiBTLESens ($name) - ExecGatttool_Aborted: The BlockingCall Process terminated unexpectedly. Timedout"; + Log3($name, 4, +"XiaomiBTLESens ($name) - ExecGatttool_Aborted: The BlockingCall Process terminated unexpectedly. Timedout"); } sub ProcessingNotification($@) { @@ -847,21 +847,21 @@ sub ProcessingNotification($@) { my $name = $hash->{NAME}; my $readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - ProcessingNotification"; + Log3($name, 4, "XiaomiBTLESens ($name) - ProcessingNotification"); if ( AttrVal( $name, 'model', 'none' ) eq 'flowerSens' ) { if ( $handle eq '0x38' ) { ### Flower Sens - Read Firmware and Battery Data - Log3 $name, 4, - "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x38"; + Log3($name, 4, + "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x38"); $readings = FlowerSensHandle0x38( $hash, $notification ); } elsif ( $handle eq '0x35' ) { ### Flower Sens - Read Sensor Data - Log3 $name, 4, - "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x35"; + Log3($name, 4, + "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x35"); $readings = FlowerSensHandle0x35( $hash, $notification ); } @@ -870,29 +870,29 @@ sub ProcessingNotification($@) { elsif ( AttrVal( $name, 'model', 'none' ) eq 'thermoHygroSens' ) { if ( $handle eq '0x18' ) { ### Thermo/Hygro Sens - Read Battery Data - Log3 $name, 4, - "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x18"; + Log3($name, 4, + "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x18"); $readings = ThermoHygroSensHandle0x18( $hash, $notification ); } elsif ( $handle eq '0x10' ) { ### Thermo/Hygro Sens - Read Sensor Data - Log3 $name, 4, - "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x10"; + Log3($name, 4, + "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x10"); $readings = ThermoHygroSensHandle0x10( $hash, $notification ); } elsif ( $handle eq '0x24' ) { ### Thermo/Hygro Sens - Read Firmware Data - Log3 $name, 4, - "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x24"; + Log3($name, 4, + "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x24"); $readings = ThermoHygroSensHandle0x24( $hash, $notification ); } elsif ( $handle eq '0x3' ) { ### Thermo/Hygro Sens - Read and Write Devicename - Log3 $name, 4, - "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x3"; + Log3($name, 4, + "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x3"); return CreateParamGatttool( $hash, 'read', $XiaomiModels{ AttrVal( $name, 'model', '' ) }{devicename} ) @@ -903,29 +903,29 @@ sub ProcessingNotification($@) { elsif ( AttrVal( $name, 'model', 'none' ) eq 'clearGrassSens' ) { if ( $handle eq '0x3b' ) { ### Clear Grass Sens - Read Battery Data - Log3 $name, 4, - "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x3b"; + Log3($name, 4, + "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x3b"); $readings = ClearGrassSensHandle0x3b( $hash, $notification ); } elsif ( $handle eq '0x1e' ) { ### Clear Grass Sens - Read Sensor Data - Log3 $name, 4, - "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x1e"; + Log3($name, 4, + "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x1e"); $readings = ClearGrassSensHandle0x1e( $hash, $notification ); } elsif ( $handle eq '0x2a' ) { ### Clear Grass Sens - Read Firmware Data - Log3 $name, 4, - "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x2a"; + Log3($name, 4, + "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x2a"); $readings = ClearGrassSensHandle0x2a( $hash, $notification ); } elsif ( $handle eq '0x3' ) { ### Clear Grass Sens - Read and Write Devicename - Log3 $name, 4, - "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x3"; + Log3($name, 4, + "XiaomiBTLESens ($name) - ProcessingNotification: handle 0x3"); return CreateParamGatttool( $hash, 'read', $XiaomiModels{ AttrVal( $name, 'model', '' ) }{devicename} ) @@ -944,7 +944,7 @@ sub FlowerSensHandle0x38($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - FlowerSens Handle0x38"; + Log3($name, 4, "XiaomiBTLESens ($name) - FlowerSens Handle0x38"); my @dataBatFw = split( " ", $notification ); @@ -970,7 +970,7 @@ sub FlowerSensHandle0x35($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - FlowerSens Handle0x35"; + Log3($name, 4, "XiaomiBTLESens ($name) - FlowerSens Handle0x35"); my @dataSensor = split( " ", $notification ); @@ -996,13 +996,13 @@ sub FlowerSensHandle0x35($$) { $readings{'moisture'} = hex( "0x" . $dataSensor[7] ); $readings{'fertility'} = hex( "0x" . $dataSensor[9] . $dataSensor[8] ); - Log3 $name, 4, + Log3($name, 4, "XiaomiBTLESens ($name) - FlowerSens Handle0x35 - lux: " . $readings{lux} . ", moisture: " . $readings{moisture} . ", fertility: " - . $readings{fertility}; + . $readings{fertility}); $hash->{helper}{CallBattery} = 0; return \%readings; @@ -1015,7 +1015,7 @@ sub ThermoHygroSensHandle0x18($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x18"; + Log3($name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x18"); chomp($notification); $notification =~ s/\s+//g; @@ -1037,7 +1037,7 @@ sub ThermoHygroSensHandle0x10($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x10"; + Log3($name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x10"); return stateRequest($hash) unless ( $notification =~ /^([0-9a-f]{2}(\s?))*$/ ); @@ -1073,7 +1073,7 @@ sub ThermoHygroSensHandle0x24($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x24"; + Log3($name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x24"); $notification =~ s/\s+//g; @@ -1090,7 +1090,7 @@ sub ThermoHygroSensHandle0x3($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x3"; + Log3($name, 4, "XiaomiBTLESens ($name) - Thermo/Hygro Sens Handle0x3"); $notification =~ s/\s+//g; @@ -1107,7 +1107,7 @@ sub ClearGrassSensHandle0x3b($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - Clear Grass Sens Handle0x3b"; + Log3($name, 4, "XiaomiBTLESens ($name) - Clear Grass Sens Handle0x3b"); chomp($notification); $notification =~ s/\s+//g; @@ -1129,7 +1129,7 @@ sub ClearGrassSensHandle0x1e($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - Clear Grass Sens Handle0x1e"; + Log3($name, 4, "XiaomiBTLESens ($name) - Clear Grass Sens Handle0x1e"); return stateRequest($hash) unless ( $notification =~ /^([0-9a-f]{2}(\s?))*$/ ); @@ -1154,7 +1154,7 @@ sub ClearGrassSensHandle0x2a($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - Clear Grass Sens Handle0x2a"; + Log3($name, 4, "XiaomiBTLESens ($name) - Clear Grass Sens Handle0x2a"); $notification =~ s/\s+//g; @@ -1171,7 +1171,7 @@ sub ClearGrassSensHandle0x3($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - Clear Grass Sens Handle0x3"; + Log3($name, 4, "XiaomiBTLESens ($name) - Clear Grass Sens Handle0x3"); $notification =~ s/\s+//g; @@ -1292,8 +1292,8 @@ sub WriteReadings($$) { ) if ( AttrVal( $name, 'maxTemp', 'none' ) ne 'none' ); } - Log3 $name, 4, - "XiaomiBTLESens ($name) - WriteReadings: Readings were written"; + Log3($name, 4, + "XiaomiBTLESens ($name) - WriteReadings: Readings were written"); $hash->{helper}{CallSensDataCounter} = 0; stateRequest($hash) if ( $hash->{helper}{CallBattery} == 1 ); @@ -1306,7 +1306,7 @@ sub ProcessingErrors($$) { my $name = $hash->{NAME}; my %readings; - Log3 $name, 4, "XiaomiBTLESens ($name) - ProcessingErrors"; + Log3($name, 4, "XiaomiBTLESens ($name) - ProcessingErrors"); $readings{'lastGattError'} = $notification; WriteReadings( $hash, \%readings );