2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-21 20:06:18 +00:00

optimizing disabled-attribute for some race conditions

git-svn-id: https://svn.fhem.de/fhem/trunk@3433 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2013-07-15 22:09:18 +00:00
parent f488484516
commit ca2d545c31

View File

@ -309,24 +309,27 @@ PRESENCE_Attr(@)
{ {
if($a[3] eq "0") if($a[3] eq "0")
{ {
$hash->{helper}{DISABLED} = 0;
readingsSingleUpdate($hash, "state", "defined",0); readingsSingleUpdate($hash, "state", "defined",0) if(exists($hash->{helper}{DISABLED}) and $hash->{helper}{DISABLED} == 1);
if(defined($hash->{DeviceName})) if(defined($hash->{DeviceName}))
{ {
if(defined($hash->{FD})) if(defined($hash->{FD}))
{ {
PRESENCE_DoInit($hash); PRESENCE_DoInit($hash) if(exists($hash->{helper}{DISABLED}));
$hash->{helper}{DISABLED} = 0;
} }
else else
{ {
$hash->{helper}{DISABLED} = 0;
DevIo_OpenDev($hash, 0, "PRESENCE_DoInit"); DevIo_OpenDev($hash, 0, "PRESENCE_DoInit");
} }
} }
else else
{ {
$hash->{helper}{DISABLED} = 0;
PRESENCE_StartLocalScan($hash); PRESENCE_StartLocalScan($hash);
} }
$hash->{helper}{DISABLED} = 0;
} }
elsif($a[3] eq "1") elsif($a[3] eq "1")
{ {
@ -345,21 +348,24 @@ PRESENCE_Attr(@)
} }
elsif($a[0] eq "del" && $a[2] eq "disable") elsif($a[0] eq "del" && $a[2] eq "disable")
{ {
$hash->{helper}{DISABLED} = 0;
readingsSingleUpdate($hash, "state", "defined",0); readingsSingleUpdate($hash, "state", "defined",0) if(exists($hash->{helper}{DISABLED}) and $hash->{helper}{DISABLED} == 1);
if(defined($hash->{DeviceName})) if(defined($hash->{DeviceName}))
{ {
if(defined($hash->{FD})) if(defined($hash->{FD}))
{ {
PRESENCE_DoInit($hash); PRESENCE_DoInit($hash) if(exists($hash->{helper}{DISABLED}));
$hash->{helper}{DISABLED} = 0;
} }
else else
{ {
$hash->{helper}{DISABLED} = 0;
DevIo_OpenDev($hash, 0, "PRESENCE_DoInit"); DevIo_OpenDev($hash, 0, "PRESENCE_DoInit");
} }
} }
else else
{ {
$hash->{helper}{DISABLED} = 0;
PRESENCE_StartLocalScan($hash); PRESENCE_StartLocalScan($hash);
} }
} }
@ -438,14 +444,11 @@ PRESENCE_DoInit($)
my ($hash) = @_; my ($hash) = @_;
unless($hash->{helper}{DISABLED}) if( not exists($hash->{helper}{DISABLED}) or exists($hash->{helper}{DISABLED}) and $hash->{helper}{DISABLED} == 1)
{ {
readingsSingleUpdate($hash, "state", "active",0);
DevIo_SimpleWrite($hash, $hash->{ADDRESS}."|".$hash->{TIMEOUT_NORMAL}."\n", 0); DevIo_SimpleWrite($hash, $hash->{ADDRESS}."|".$hash->{TIMEOUT_NORMAL}."\n", 0);
} }
else
{
readingsSingleUpdate($hash, "state", "disabled",1);
}
} }