From 15cb68f84fcce809eb611ef0dbcc88cdd7ef8d0d Mon Sep 17 00:00:00 2001 From: markusbloch <> Date: Fri, 1 Aug 2014 21:56:21 +0000 Subject: [PATCH] PRESENCE: new state event "error" and "disabled"; minor log improvements git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@6341 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- CHANGED | 2 ++ FHEM/73_PRESENCE.pm | 31 +++++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CHANGED b/CHANGED index 2ea240bcc..0d22a3a98 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. + - feature: PRESENCE: new event "error" and "timeout" for state reading to indicate + a non successful check - bugfix: 70_Jabber: fixed UTF8 encoding/decoding of messages - feature: 10_OWServer autocreate coexists with OWXXX modules (Boris & ntruchsess) - feature: added 36_Level.pm diff --git a/FHEM/73_PRESENCE.pm b/FHEM/73_PRESENCE.pm index 3793c7ca9..7f4578d18 100755 --- a/FHEM/73_PRESENCE.pm +++ b/FHEM/73_PRESENCE.pm @@ -521,35 +521,35 @@ sub PRESENCE_StartLocalScan($;$) $hash->{STATE} = "active" if($hash->{STATE} eq "???"); - if(not $local) + if($local == 0) { - Log3 $name, 5, "PRESENCE ($name) - resetting Timer"; + Log3 $name, 5, "PRESENCE ($name) - stopping timer"; RemoveInternalTimer($hash); } if($mode eq "local-bluetooth") { - Log3 $name, 5, "PRESENCE ($name) - starting Blocking call for mode local-bluetooth"; + Log3 $name, 5, "PRESENCE ($name) - starting blocking call for mode local-bluetooth"; $hash->{helper}{RUNNING_PID} = BlockingCall("PRESENCE_DoLocalBluetoothScan", $name."|".$hash->{ADDRESS}."|".$local, "PRESENCE_ProcessLocalScan", 60, "PRESENCE_ProcessAbortedScan", $hash) unless(exists($hash->{helper}{RUNNING_PID})); } elsif($mode eq "lan-ping") { - Log3 $name, 5, "PRESENCE ($name) - starting Blocking call for mode lan-ping"; + Log3 $name, 5, "PRESENCE ($name) - starting blocking call for mode lan-ping"; $hash->{helper}{RUNNING_PID} = BlockingCall("PRESENCE_DoLocalPingScan", $name."|".$hash->{ADDRESS}."|".$local."|".AttrVal($name, "ping_count", "4"), "PRESENCE_ProcessLocalScan", 60, "PRESENCE_ProcessAbortedScan", $hash) unless(exists($hash->{helper}{RUNNING_PID})); } elsif($mode eq "fritzbox") { - Log3 $name, 5, "PRESENCE ($name) - starting Blocking call for mode fritzbox"; + Log3 $name, 5, "PRESENCE ($name) - starting blocking call for mode fritzbox"; $hash->{helper}{RUNNING_PID} = BlockingCall("PRESENCE_DoLocalFritzBoxScan", $name."|".$hash->{ADDRESS}."|".$local."|".AttrVal($name, "fritzbox_repeater", "0"), "PRESENCE_ProcessLocalScan", 60, "PRESENCE_ProcessAbortedScan", $hash) unless(exists($hash->{helper}{RUNNING_PID})); } elsif($mode eq "shellscript") { - Log3 $name, 5, "PRESENCE ($name) - starting Blocking call for mode shellscript"; + Log3 $name, 5, "PRESENCE ($name) - starting blocking call for mode shellscript"; $hash->{helper}{RUNNING_PID} = BlockingCall("PRESENCE_DoLocalShellScriptScan", $name."|".$hash->{helper}{call}."|".$local, "PRESENCE_ProcessLocalScan", 60, "PRESENCE_ProcessAbortedScan", $hash) unless(exists($hash->{helper}{RUNNING_PID})); } elsif($mode eq "function") { - Log3 $name, 5, "PRESENCE ($name) - starting Blocking call for mode function"; + Log3 $name, 5, "PRESENCE ($name) - starting blocking call for mode function"; $hash->{helper}{RUNNING_PID} = BlockingCall("PRESENCE_DoLocalFunctionScan", $name."|".$hash->{helper}{call}."|".$local, "PRESENCE_ProcessLocalScan", 60, "PRESENCE_ProcessAbortedScan", $hash) unless(exists($hash->{helper}{RUNNING_PID})); } } @@ -561,7 +561,7 @@ PRESENCE_DoLocalPingScan($) my ($string) = @_; my ($name, $device, $local, $count) = split("\\|", $string); - Log3 $name, 5, "PRESENCE_DoLocalPingScan: $string"; + Log3 $name, 5, "PRESENCE ($name) - starting ping scan: $string"; my $retcode; my $return; @@ -922,6 +922,7 @@ PRESENCE_ProcessLocalScan($) $a[3] =~ s/<>/\n/g; Log3 $hash->{NAME}, 2, "PRESENCE ($name) - error while processing check: ".$a[3]; + readingsBulkUpdate($hash, "state", "error"); } readingsEndUpdate($hash, 1); @@ -929,10 +930,14 @@ PRESENCE_ProcessLocalScan($) delete($hash->{helper}{RUNNING_PID}); #Schedule the next check withing $timeout if it is a regular run - unless($local) + if($local eq "0") { + my $seconds = ($a[2] eq "present" ? $hash->{TIMEOUT_PRESENT} : $hash->{TIMEOUT_NORMAL}); + + Log3 $hash->{NAME}, 4, "PRESENCE ($name) - rescheduling next check in $seconds seconds"; + RemoveInternalTimer($hash); - InternalTimer(gettimeofday()+($a[2] eq "present" ? $hash->{TIMEOUT_PRESENT} : $hash->{TIMEOUT_NORMAL}), "PRESENCE_StartLocalScan", $hash, 0) unless($hash->{helper}{DISABLED}); + InternalTimer(gettimeofday()+$seconds, "PRESENCE_StartLocalScan", $hash, 0) unless($hash->{helper}{DISABLED}); } } @@ -967,6 +972,8 @@ PRESENCE_ProcessAbortedScan($) InternalTimer(gettimeofday()+10, "PRESENCE_StartLocalScan", $hash, 0) unless($hash->{helper}{DISABLED}); Log 2, "PRESENCE ($name) - device could not be checked (retrying in 10 seconds)" } + + readingsSingleUpdate($hash, "state", "timeout",1); } 1; @@ -1197,7 +1204,7 @@ Options: