Skip to content

Commit

Permalink
correct some logMethod calls (#657)
Browse files Browse the repository at this point in the history
* 00_SIGNALduino.pm

Fixed serveral SIGNALduino_Log3 calls. Changed them to hash->{logMethod}->(


* tests/test_logging-definition.txt

Exit test with deactivated eventlogging
  • Loading branch information
sidey79 authored Sep 15, 2019
1 parent aebe9eb commit d0fe760
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGED
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
15.09.2019
00_SIGNALduino.pm: fix some logging issues with disabled eventlogging
09.09.2019
00_SIGNALduino.pm: fix warning
06.09.2019
Expand Down
37 changes: 19 additions & 18 deletions FHEM/00_SIGNALduino.pm
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ sub SIGNALduino_Connect($$)

# damit wird die err-msg nur einmal ausgegeben
if (!defined($hash->{disConnFlag}) && $err) {
SIGNALduino_Log3($hash, 3, "$hash->{NAME}: ${err}");
$hash->{logMethod}->($hash->{NAME}, 3, "$hash->{NAME}: ${err}");
$hash->{disConnFlag} = 1;
}
}
Expand Down Expand Up @@ -1088,7 +1088,7 @@ SIGNALduino_ResetDevice($)
my ($hash) = @_;
my $name = $hash->{NAME};

SIGNALduino_Log3 $hash, 3, "$name reset";
$hash->{logMethod}->($name, 3, "$name reset");
DevIo_CloseDev($hash);
my $ret = DevIo_OpenDev($hash, 0, "SIGNALduino_DoInit", 'SIGNALduino_Connect');

Expand All @@ -1100,9 +1100,8 @@ sub
SIGNALduino_CloseDevice($)
{
my ($hash) = @_;
my $name = $hash->{NAME};

SIGNALduino_Log3 $hash, 2, "$name closed";
$hash->{logMethod}->($hash->{NAME}, 2, "$hash->{NAME} closed");
RemoveInternalTimer($hash);
DevIo_CloseDev($hash);
readingsSingleUpdate($hash, "state", "closed", 1);
Expand Down Expand Up @@ -1332,15 +1331,14 @@ SIGNALduino_SendFromQueue($$)
{
my ($hash, $msg) = @_;
my $name = $hash->{NAME};

if($msg ne "") {
SIGNALduino_XmitLimitCheck($hash,$msg);
#DevIo_SimpleWrite($hash, $msg . "\n", 2);
$hash->{sendworking} = 1;
SIGNALduino_SimpleWrite($hash,$msg);
if ($msg =~ m/^S(R|C|M);/) {
$hash->{getcmd}->{cmd} = 'sendraw';
SIGNALduino_Log3 $hash, 4, "$name SendrawFromQueue: msg=$msg"; # zu testen der Queue, kann wenn es funktioniert auskommentiert werden
$hash->{logMethod}->($name, 4, "$name SendrawFromQueue: msg=$msg"); # zu testen der Queue, kann wenn es funktioniert auskommentiert werden
}
elsif ($msg eq "C99") {
$hash->{getcmd}->{cmd} = 'ccregAll';
Expand Down Expand Up @@ -1402,7 +1400,7 @@ SIGNALduino_Read($)
my $debug = AttrVal($name,"debug",0);

my $SIGNALduinodata = $hash->{PARTIAL};
SIGNALduino_Log3 $name, 5, "$name/RAW READ: $SIGNALduinodata/$buf" if ($debug);
$hash->{logMethod}->($name, 5, "$name/RAW READ: $SIGNALduinodata/$buf") if ($debug);
$SIGNALduinodata .= $buf;

while($SIGNALduinodata =~ m/\n/) {
Expand All @@ -1420,7 +1418,7 @@ SIGNALduino_Read($)
my $mH;
my $part = "";
my $partD;
SIGNALduino_Log3 $name, 5, "$name/RAW rmsg: $rmsg";
$hash->{logMethod}->($name, 5, "$name/RAW rmsg: $rmsg");

foreach my $msgPart (@msg_parts) {
next if ($msgPart eq "");
Expand Down Expand Up @@ -1539,7 +1537,7 @@ SIGNALduino_Read($)
delete($hash->{getcmd});
}
} else {
SIGNALduino_Log3 $name, 4, "$name/msg READ: Received answer ($rmsg) for ". $hash->{getcmd}->{cmd}." does not match $regexp";
$hash->{logMethod}->($name, 4, "$name/msg READ: Received answer ($rmsg) for ". $hash->{getcmd}->{cmd}." does not match $regexp");
}
}
}
Expand Down Expand Up @@ -1597,12 +1595,12 @@ sub SIGNALduino_ParseHttpResponse

if($err ne "") # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist
{
SIGNALduino_Log3 $name, 3, "$name: error while requesting ".$param->{url}." - $err"; # Eintrag fuers Log
$hash->{logMethod}->($name, 3, "$name: error while requesting ".$param->{url}." - $err"); # Eintrag fuers Log
}
elsif($param->{code} eq "200" && $data ne "") # wenn die Abfrage erfolgreich war ($data enthaelt die Ergebnisdaten des HTTP Aufrufes)
{

SIGNALduino_Log3 $name, 3, "url ".$param->{url}." returned: ".length($data)." bytes Data"; # Eintrag fuers Log
$hash->{logMethod}->($name, 3, "url ".$param->{url}." returned: ".length($data)." bytes Data"); # Eintrag fuers Log

if ($param->{command} eq "flash")
{
Expand Down Expand Up @@ -1636,7 +1634,7 @@ sub SIGNALduino_ParseHttpResponse
}
}
} else {
SIGNALduino_Log3 $name, 3, "$name: undefined error while requesting ".$param->{url}." - $err - code=".$param->{code}; # Eintrag fuers Log
$hash->{logMethod}->($name, 3, "$name: undefined error while requesting ".$param->{url}." - $err - code=".$param->{code}); # Eintrag fuers Log
}
}

Expand Down Expand Up @@ -2330,7 +2328,7 @@ sub SIGNALduino_Parse_MU($$$$@)
$startLogStr = "StartStr: $startStr first found at $message_start";
Debug "rawData = $rawData" if ($debug);
Debug "startStr $startStr found. Message starts at $message_start" if ($debug);
SIGNALduino_Log3 $name, 5, "$name: substr: $rawData"; # todo: entfernen
#SIGNALduino_Log3 $name, 5, "$name: substr: $rawData"; # todo: entfernen
}

}
Expand Down Expand Up @@ -2384,7 +2382,7 @@ sub SIGNALduino_Parse_MU($$$$@)
while ( $rawData =~ m/$regex/g) {
my $length_str="";
$nrRestart++;
SIGNALduino_Log3 $name, 5, "part is $1 starts at position $-[0] and ends at ". pos $rawData;
$hash->{logMethod}->($name, 5, "part is $1 starts at position $-[0] and ends at ". pos $rawData);

my @pairs = unpack "(a$signal_width)*", $1;

Expand All @@ -2395,7 +2393,7 @@ sub SIGNALduino_Parse_MU($$$$@)
}

if ($nrRestart == 1) {
SIGNALduino_Log3 $name, 5, "$name: Starting demodulation ($startLogStr " . "regex: $regex Pos $message_start) length_min_max (".$length_min."..".$length_max.") length=".scalar @pairs;
$hash->{logMethod}->($name, 5, "$name: Starting demodulation ($startLogStr " . "regex: $regex Pos $message_start) length_min_max (".$length_min."..".$length_max.") length=".scalar @pairs);
} else {
$hash->{logMethod}->($name, 5, "$name: $nrRestart. try demodulation$length_str at Pos $-[0]");
}
Expand Down Expand Up @@ -2577,7 +2575,7 @@ SIGNALduino_Parse_MC($$$$@)
}
} else {
$res="undef" if (!defined($res));
SIGNALduino_Log3 $name, 5, "$name: protocol does not match return from method: ($res)" ;
$hash->{logMethod}->($name, 5, "$name: protocol does not match return from method: ($res)") ;

}
}
Expand Down Expand Up @@ -2823,8 +2821,11 @@ SIGNALduino_Attr(@)
{
if ($aVal == 1) {
$hash->{logMethod} = \&::SIGNALduino_Log3;
Log3 $name, 3, "Enable eventlogging";
} else {
$hash->{logMethod} = \&::Log3;
Log3 $name, 3, "Disable eventlogging";

}
}

Expand Down Expand Up @@ -4550,7 +4551,7 @@ sub SIGNALduino_githubParseHttpResponse($$$)
my $set_return = SIGNALduino_Set($hash,$name,"flash",$asset->{browser_download_url}); # $hash->{SetFn
if(defined($set_return))
{
SIGNALduino_Log3 $name, 3, "$name: Error while trying to download firmware: $set_return";
$hash->{logMethod}->($name, 3, "$name: Error while trying to download firmware: $set_return");
}
last;

Expand All @@ -4559,7 +4560,7 @@ sub SIGNALduino_githubParseHttpResponse($$$)

}
} elsif (!defined($hardware)) {
SIGNALduino_Log3 $name, 5, "$name: SIGNALduino_githubParseHttpResponse hardware is not defined";
$hash->{logMethod}->($name, 5, "$name: SIGNALduino_githubParseHttpResponse hardware is not defined");
} # wenn
# Damit ist die Abfrage zuende.
# Evtl. einen InternalTimer neu schedulen
Expand Down
2 changes: 1 addition & 1 deletion UnitTest/tests/test_logging-definition.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
defmod test_logging UnitTest dummyDuino (
{
my $mock = Mock::Sub->new;
CommandAttr(undef,"$target eventlogging 0");
my $DoTrigger = $mock->mock("DoTrigger");

subtest "Check logMethod with with attr eventlogging 0" => sub {
Expand All @@ -22,6 +21,7 @@ subtest "Check logMethod with attr eventlogging 1" => sub {

is($DoTrigger->called_count, 1, "check if DoTrigger is called from SIGNALduino_Log3");
};
CommandAttr(undef,"$target eventlogging 0");

}
)
2 changes: 1 addition & 1 deletion controls_signalduino.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
UPD 2019-09-10_07:11:22 202522 FHEM/00_SIGNALduino.pm
UPD 2019-09-15_23:20:58 202676 FHEM/00_SIGNALduino.pm
UPD 2017-06-23_17:43:38 14541 FHEM/10_FS10.pm
UPD 2016-09-18_21:22:06 10111 FHEM/14_BresserTemeo.pm
UPD 2018-11-11_22:35:33 13616 FHEM/14_FLAMINGO.pm
Expand Down

0 comments on commit d0fe760

Please sign in to comment.