From c9c3dbfea15230e58e3c8acee4619d4c6a4e881d Mon Sep 17 00:00:00 2001 From: markusbloch <> Date: Mon, 15 Jul 2013 22:09:18 +0000 Subject: [PATCH] optimizing disabled-attribute for some race conditions git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@3433 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/73_PRESENCE.pm | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/FHEM/73_PRESENCE.pm b/FHEM/73_PRESENCE.pm index a10bc92ac..0d4f6a686 100755 --- a/FHEM/73_PRESENCE.pm +++ b/FHEM/73_PRESENCE.pm @@ -309,24 +309,27 @@ PRESENCE_Attr(@) { 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->{FD})) { - PRESENCE_DoInit($hash); + PRESENCE_DoInit($hash) if(exists($hash->{helper}{DISABLED})); + $hash->{helper}{DISABLED} = 0; } else { + $hash->{helper}{DISABLED} = 0; DevIo_OpenDev($hash, 0, "PRESENCE_DoInit"); } } else { + $hash->{helper}{DISABLED} = 0; PRESENCE_StartLocalScan($hash); } - + $hash->{helper}{DISABLED} = 0; } elsif($a[3] eq "1") { @@ -345,21 +348,24 @@ PRESENCE_Attr(@) } 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->{FD})) { - PRESENCE_DoInit($hash); + PRESENCE_DoInit($hash) if(exists($hash->{helper}{DISABLED})); + $hash->{helper}{DISABLED} = 0; } else { + $hash->{helper}{DISABLED} = 0; DevIo_OpenDev($hash, 0, "PRESENCE_DoInit"); } } else { + $hash->{helper}{DISABLED} = 0; PRESENCE_StartLocalScan($hash); } } @@ -438,14 +444,11 @@ PRESENCE_DoInit($) 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); } - else - { - readingsSingleUpdate($hash, "state", "disabled",1); - } }