adding statusRequest command, minor improvements in "disabled"-handling
git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@2721 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -35,6 +35,8 @@ use DevIo;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sub
|
sub
|
||||||
PRESENCE_Initialize($)
|
PRESENCE_Initialize($)
|
||||||
{
|
{
|
||||||
@@ -46,6 +48,7 @@ PRESENCE_Initialize($)
|
|||||||
$hash->{ReadFn} = "PRESENCE_Read";
|
$hash->{ReadFn} = "PRESENCE_Read";
|
||||||
$hash->{ReadyFn} = "PRESENCE_Ready";
|
$hash->{ReadyFn} = "PRESENCE_Ready";
|
||||||
$hash->{GetFn} = "PRESENCE_Get";
|
$hash->{GetFn} = "PRESENCE_Get";
|
||||||
|
$hash->{SetFn} = "PRESENCE_Set";
|
||||||
$hash->{DefFn} = "PRESENCE_Define";
|
$hash->{DefFn} = "PRESENCE_Define";
|
||||||
$hash->{UndefFn} = "PRESENCE_Undef";
|
$hash->{UndefFn} = "PRESENCE_Undef";
|
||||||
$hash->{AttrFn} = "PRESENCE_Attr";
|
$hash->{AttrFn} = "PRESENCE_Attr";
|
||||||
@@ -182,6 +185,32 @@ PRESENCE_Undef($$)
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
PRESENCE_Set($@)
|
||||||
|
{
|
||||||
|
my ($hash, @a) = @_;
|
||||||
|
|
||||||
|
my $usage = ($hash->{MODE} ne "lan-bluetooth" ? "Unknown argument ".$a[1].", choose one of statusRequest " : undef);
|
||||||
|
|
||||||
|
if($a[1] eq "statusRequest")
|
||||||
|
{
|
||||||
|
if($hash->{MODE} ne "lan-bluetooth")
|
||||||
|
{
|
||||||
|
PRESENCE_StartLocalScan($hash, 1);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
##########################
|
##########################
|
||||||
@@ -196,6 +225,7 @@ PRESENCE_Attr(@)
|
|||||||
if($a[3] eq "0")
|
if($a[3] eq "0")
|
||||||
{
|
{
|
||||||
$hash->{helper}{DISABLED} = 0;
|
$hash->{helper}{DISABLED} = 0;
|
||||||
|
readingsSingleUpdate($hash, "state", "defined",0);
|
||||||
if(defined($hash->{DeviceName}))
|
if(defined($hash->{DeviceName}))
|
||||||
{
|
{
|
||||||
if(defined($hash->{FD}))
|
if(defined($hash->{FD}))
|
||||||
@@ -211,6 +241,7 @@ PRESENCE_Attr(@)
|
|||||||
{
|
{
|
||||||
PRESENCE_StartLocalScan($hash);
|
PRESENCE_StartLocalScan($hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
elsif($a[3] eq "1")
|
elsif($a[3] eq "1")
|
||||||
{
|
{
|
||||||
@@ -230,6 +261,7 @@ PRESENCE_Attr(@)
|
|||||||
elsif($a[0] eq "del" && $a[2] eq "disable")
|
elsif($a[0] eq "del" && $a[2] eq "disable")
|
||||||
{
|
{
|
||||||
$hash->{helper}{DISABLED} = 0;
|
$hash->{helper}{DISABLED} = 0;
|
||||||
|
readingsSingleUpdate($hash, "state", "defined",0);
|
||||||
if(defined($hash->{DeviceName}))
|
if(defined($hash->{DeviceName}))
|
||||||
{
|
{
|
||||||
if(defined($hash->{FD}))
|
if(defined($hash->{FD}))
|
||||||
@@ -341,35 +373,33 @@ PRESENCE_Ready($)
|
|||||||
# Functions for local testing with Blocking.pm to ensure a smooth FHEM processing
|
# Functions for local testing with Blocking.pm to ensure a smooth FHEM processing
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
sub
|
sub PRESENCE_StartLocalScan($;$)
|
||||||
PRESENCE_StartLocalScan($)
|
|
||||||
{
|
{
|
||||||
my ($hash) = @_;
|
my ($hash, $local) = @_;
|
||||||
|
|
||||||
|
$local = 0 unless(defined($local));
|
||||||
|
|
||||||
if($hash->{MODE} eq "local-bluetooth")
|
if($hash->{MODE} eq "local-bluetooth")
|
||||||
{
|
{
|
||||||
|
BlockingCall("PRESENCE_DoLocalBluetoothScan", $hash->{NAME}."|".$hash->{ADDRESS}."|".$local, "PRESENCE_ProcessLocalScan", 20);
|
||||||
BlockingCall("PRESENCE_DoLocalBluetoothScan", $hash->{NAME}."|".$hash->{ADDRESS}, "PRESENCE_ProcessLocalScan", 20);
|
|
||||||
}
|
}
|
||||||
elsif($hash->{MODE} eq "lan-ping")
|
elsif($hash->{MODE} eq "lan-ping")
|
||||||
{
|
{
|
||||||
BlockingCall("PRESENCE_DoLocalPingScan", $hash->{NAME}."|".$hash->{ADDRESS}, "PRESENCE_ProcessLocalScan", 20);
|
BlockingCall("PRESENCE_DoLocalPingScan", $hash->{NAME}."|".$hash->{ADDRESS}."|".$local, "PRESENCE_ProcessLocalScan", 20);
|
||||||
|
|
||||||
}
|
}
|
||||||
elsif($hash->{MODE} eq "fritzbox")
|
elsif($hash->{MODE} eq "fritzbox")
|
||||||
{
|
{
|
||||||
BlockingCall("PRESENCE_DoLocalFritzBoxScan", $hash->{NAME}."|".$hash->{ADDRESS}, "PRESENCE_ProcessLocalScan", 20);
|
BlockingCall("PRESENCE_DoLocalFritzBoxScan", $hash->{NAME}."|".$hash->{ADDRESS}."|".$local, "PRESENCE_ProcessLocalScan", 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
PRESENCE_DoLocalPingScan($$)
|
PRESENCE_DoLocalPingScan($)
|
||||||
{
|
{
|
||||||
|
|
||||||
my ($string) = @_;
|
my ($string) = @_;
|
||||||
my ($name, $device) = split("\\|", $string);
|
my ($name, $device, $local) = split("\\|", $string);
|
||||||
|
|
||||||
my $retcode;
|
my $retcode;
|
||||||
my $return;
|
my $return;
|
||||||
@@ -382,18 +412,18 @@ PRESENCE_DoLocalPingScan($$)
|
|||||||
if($pingtool)
|
if($pingtool)
|
||||||
{
|
{
|
||||||
$retcode = $pingtool->ping($device, 5);
|
$retcode = $pingtool->ping($device, 5);
|
||||||
$return = "$name|".($retcode ? "present" : "absent");
|
$return = "$name|$local|".($retcode ? "present" : "absent");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$return = "$name|error|Could not create a Net::Ping object.";
|
$return = "$name|$local|error|Could not create a Net::Ping object.";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$temp = qx(ping -c 4 $device);
|
$temp = qx(ping -c 4 $device);
|
||||||
$return = "$name|".($temp =~ /\d+ bytes from/ ? "present" : "absent");
|
$return = "$name|$local|".($temp =~ /\d+ bytes from/ ? "present" : "absent");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
@@ -404,7 +434,7 @@ sub
|
|||||||
PRESENCE_DoLocalFritzBoxScan($)
|
PRESENCE_DoLocalFritzBoxScan($)
|
||||||
{
|
{
|
||||||
my ($string) = @_;
|
my ($string) = @_;
|
||||||
my ($name, $device) = split("\\|", $string);
|
my ($name, $device, $local) = split("\\|", $string);
|
||||||
|
|
||||||
my $number=0;
|
my $number=0;
|
||||||
|
|
||||||
@@ -414,7 +444,7 @@ PRESENCE_DoLocalFritzBoxScan($)
|
|||||||
|
|
||||||
if(not $max =~ /^\s*\d+\s*$/)
|
if(not $max =~ /^\s*\d+\s*$/)
|
||||||
{
|
{
|
||||||
return "$name|error|could not execute ctlmgr_ctl";
|
return "$name|$local|error|could not execute ctlmgr_ctl";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -441,11 +471,11 @@ PRESENCE_DoLocalFritzBoxScan($)
|
|||||||
|
|
||||||
if($status == 1)
|
if($status == 1)
|
||||||
{
|
{
|
||||||
return "$name|present";
|
return "$name|$local|present";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return "$name|absent";
|
return "$name|$local|absent";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -455,7 +485,7 @@ sub
|
|||||||
PRESENCE_DoLocalBluetoothScan($)
|
PRESENCE_DoLocalBluetoothScan($)
|
||||||
{
|
{
|
||||||
my ($string) = @_;
|
my ($string) = @_;
|
||||||
my ($name, $device) = split("\\|", $string);
|
my ($name, $device, $local) = split("\\|", $string);
|
||||||
my $hcitool = qx(which hcitool);
|
my $hcitool = qx(which hcitool);
|
||||||
my $devname;
|
my $devname;
|
||||||
my $return;
|
my $return;
|
||||||
@@ -483,16 +513,16 @@ PRESENCE_DoLocalBluetoothScan($)
|
|||||||
|
|
||||||
if(not $devname =~ /^\s*$/)
|
if(not $devname =~ /^\s*$/)
|
||||||
{
|
{
|
||||||
$return = "$name|present|$devname";
|
$return = "$name|$local|present|$devname";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$return = "$name|absent";
|
$return = "$name|$local|absent";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$return = "$name|error|no hcitool binary found. Please check that the bluez-package is properly installed";
|
$return = "$name|$local|error|no hcitool binary found. Please check that the bluez-package is properly installed";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
@@ -509,31 +539,35 @@ PRESENCE_ProcessLocalScan($)
|
|||||||
my @a = split("\\|",$string);
|
my @a = split("\\|",$string);
|
||||||
|
|
||||||
my $hash = $defs{$a[0]};
|
my $hash = $defs{$a[0]};
|
||||||
|
my $local = $a[1];
|
||||||
|
|
||||||
return if($hash->{helper}{DISABLED});
|
return if($hash->{helper}{DISABLED});
|
||||||
|
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
if($a[1] eq "present")
|
if($a[2] eq "present")
|
||||||
{
|
{
|
||||||
readingsBulkUpdate($hash, "state", "present");
|
readingsBulkUpdate($hash, "state", "present");
|
||||||
readingsBulkUpdate($hash, "device_name", $a[2]) if(defined($a[2]));
|
readingsBulkUpdate($hash, "device_name", $a[3]) if(defined($a[3]));
|
||||||
}
|
}
|
||||||
elsif($a[1] eq "absent")
|
elsif($a[2] eq "absent")
|
||||||
{
|
{
|
||||||
readingsBulkUpdate($hash, "state", "absent");
|
readingsBulkUpdate($hash, "state", "absent");
|
||||||
}
|
}
|
||||||
elsif($a[1] eq "error")
|
elsif($a[2] eq "error")
|
||||||
{
|
{
|
||||||
Log GetLogLevel($hash->{NAME}, 2), "PRESENCE: error while processing device ".$hash->{NAME}." - ".$a[2];
|
Log GetLogLevel($hash->{NAME}, 2), "PRESENCE: error while processing device ".$hash->{NAME}." - ".$a[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
readingsEndUpdate($hash, 1);
|
readingsEndUpdate($hash, 1);
|
||||||
|
|
||||||
#Schedule the next check withing $timeout
|
#Schedule the next check withing $timeout if it is a regular run
|
||||||
|
unless($local)
|
||||||
|
{
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
InternalTimer(gettimeofday()+$hash->{TIMEOUT}, "PRESENCE_StartLocalScan", $hash, 0) unless($hash->{helper}{DISABLED});
|
InternalTimer(gettimeofday()+$hash->{TIMEOUT}, "PRESENCE_StartLocalScan", $hash, 0) unless($hash->{helper}{DISABLED});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
1;
|
1;
|
||||||
|
|
||||||
@@ -675,7 +709,7 @@ Options:
|
|||||||
<a name="PRESENCEset"></a>
|
<a name="PRESENCEset"></a>
|
||||||
<b>Set</b>
|
<b>Set</b>
|
||||||
<ul>
|
<ul>
|
||||||
N/A
|
<li><b>statusRequest</b> - (Only for local-bluetooth, lan-ping and fritzbox) - Schedules an immediatly check.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@@ -861,7 +895,7 @@ Options:
|
|||||||
<a name="PRESENCEset"></a>
|
<a name="PRESENCEset"></a>
|
||||||
<b>Set</b>
|
<b>Set</b>
|
||||||
<ul>
|
<ul>
|
||||||
N/A
|
<li><b>statusRequest</b> - (Nu für local-bluetooth, lan-ping and fritzbox) - Startet einen sofortigen Check.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user