diff --git a/fhem/CHANGED b/fhem/CHANGED index 8dae5da4e..fa05a6bf9 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. # Do not insert empty lines here, update check depends on it. + - feature: PIONEERAVR: new attribute: checkConnection - change: do no parse empty lines in 57_Calendar.pm - bugfix: 10_SOMFY.pm: save enc-key and rolling-code as reading instead of attribute to prevent loss of control after FHEM restart. diff --git a/fhem/FHEM/70_PIONEERAVR.pm b/fhem/FHEM/70_PIONEERAVR.pm index 809824938..64669e55f 100644 --- a/fhem/FHEM/70_PIONEERAVR.pm +++ b/fhem/FHEM/70_PIONEERAVR.pm @@ -118,7 +118,7 @@ PIONEERAVR_Initialize($) { $hash->{GetFn} = "PIONEERAVR_Get"; $hash->{SetFn} = "PIONEERAVR_Set"; $hash->{AttrFn} = "PIONEERAVR_Attr"; - $hash->{AttrList}= "logTraffic:0,1,2,3,4,5 ". + $hash->{AttrList}= "logTraffic:0,1,2,3,4,5 checkConnection:enable,disable ". $readingFnAttributes; # remotecontrol @@ -1339,11 +1339,14 @@ sub PIONEERAVR_Read($) # We delete the current "inactivity timer" and set a new timer # to check if connection to the Pioneer AV receiver is still working in 120s - my $in120s = gettimeofday()+120; - $hash->{helper}{nextConnectionCheck} = $in120s; - RemoveInternalTimer($hash); - InternalTimer($in120s, "PIONEERAVR_checkConnection", $hash, 0); - Log3 $hash,5,"PIONEERAVR $name: Connection is up --- Check again in 120s --> Internal timer (120s) set"; + if (AttrVal($name, "checkConnection", "enable") eq "enable" ) { + my $in120s = gettimeofday()+120; + $hash->{helper}{nextConnectionCheck} = $in120s; + RemoveInternalTimer($hash); + InternalTimer($in120s, "PIONEERAVR_checkConnection", $hash, 0); + Log3 $hash,5,"PIONEERAVR $name: Connection is up --- Check again in 120s --> Internal timer (120s) set"; + } + readingsEndUpdate($hash, 1); $hash->{PARTIAL} = $buf; } @@ -1385,7 +1388,7 @@ sub PIONEERAVR_Reopen($) { my $ret = DevIo_OpenDev($hash, 1, undef); if ($hash->{STATE} eq "opened") { Log3 $name, 5, "PIONEERAVR $name: PIONEERAVR_Reopen() -> now opened"; - readingsSingleUpdate($hash , "connectionState" , "opened" , 1 ); + #readingsSingleUpdate($hash , "connectionState" , "opened" , 1 ); PIONEERAVR_statusUpdate($hash); } return $ret; @@ -1395,15 +1398,19 @@ sub PIONEERAVR_Reopen($) { # connection check 3s after writing sub PIONEERAVR_Write($$) { my ($hash, $msg) = @_; + my $name= $hash->{NAME}; $msg= $msg."\r\n"; my $logMsg = "SimpleWrite " . dq($msg); PIONEERAVR_Log($hash, undef, $logMsg); DevIo_SimpleWrite($hash, $msg, 0); - my $now3 = gettimeofday()+3; - if ($hash->{helper}{nextConnectionCheck} > $now3) { - $hash->{helper}{nextConnectionCheck} = $now3; - RemoveInternalTimer($hash); - InternalTimer($now3, "PIONEERAVR_checkConnection", $hash, 0); + + if (AttrVal($name, "checkConnection", "enable") eq "enable" ) { + my $now3 = gettimeofday()+3; + if ($hash->{helper}{nextConnectionCheck} > $now3) { + $hash->{helper}{nextConnectionCheck} = $now3; + RemoveInternalTimer($hash); + InternalTimer($now3, "PIONEERAVR_checkConnection", $hash, 0); + } } } @@ -1438,23 +1445,17 @@ sub PIONEERAVR_checkConnection ($) { # not connected! Log3 $name, 5, "PIONEERAVR $name: PIONEERAVR_checkConnection() --- reopen()"; PIONEERAVR_Reopen($hash); - } - #restore state $hash->{STATE} - Log3 $name, 5, "PIONEERAVR $name: PIONEERAVR_checkConnection() --- state after PIONEERAVR_Reopen(): ".$hash->{STATE}." state: $state ConnState: ".dq($connState); - if (($hash->{STATE} eq "opened" || $hash->{STATE} eq "connected" ) && ($state eq "on" || $state eq "off")){ - #readingsSingleUpdate($hash, "state", $state,1 ); + Log3 $name, 5, "PIONEERAVR $name: PIONEERAVR_checkConnection() --- state after PIONEERAVR_Reopen(): ".$hash->{STATE}." state: $state ConnState: ".dq($connState); + } else { + # we got a reply -> connection is good -> restore state + Log3 $name, 5, "PIONEERAVR $name: PIONEERAVR_checkConnection() --- state: ".$hash->{STATE}." restored to: $state"; $hash->{STATE} = $state; - Log3 $name, 5, "PIONEERAVR $name: PIONEERAVR_checkConnection() --- state: $state restored to: ".$hash->{STATE}; - } elsif ($hash->{STATE} eq "disconnected") { - Log3 $name, 3, "PIONEERAVR $name: PIONEERAVR_checkConnection() --- state (discon): ".$hash->{STATE}; - readingsBeginUpdate($hash); - readingsBulkUpdate($hash, "connectionState","disconnected",1 ); - #readingsBulkUpdate($hash, "state", $hash->{STATE},1 ); - readingsEndUpdate($hash, 1); + } + if (AttrVal($name, "checkConnection", "enable") eq "enable" ) { + $hash->{helper}{nextConnectionCheck} = gettimeofday()+120; + InternalTimer($hash->{helper}{nextConnectionCheck}, "PIONEERAVR_checkConnection", $hash, 0); + Log3 $name, 5, "PIONEERAVR $name: PIONEERAVR_checkConnection(): set internaltimer(120s)"; } - #RemoveInternalTimer($hash); - $hash->{helper}{nextConnectionCheck} = gettimeofday()+120; - InternalTimer($hash->{helper}{nextConnectionCheck}, "PIONEERAVR_checkConnection", $hash, 0); } ######################################################### sub PIONEERAVR_statusUpdate($) { @@ -1644,6 +1645,7 @@ RC_layout_PioneerAVR() { Attributes