From 25d09eccd599d1efebe3a108b04163518cdf880c Mon Sep 17 00:00:00 2001 From: borisneubert Date: Sun, 22 Dec 2013 21:08:44 +0000 Subject: [PATCH] additional patch for nonblocking mode git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@4444 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/11_OWDevice.pm | 55 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/fhem/FHEM/11_OWDevice.pm b/fhem/FHEM/11_OWDevice.pm index 49bd9f07e..0ad53bae1 100644 --- a/fhem/FHEM/11_OWDevice.pm +++ b/fhem/FHEM/11_OWDevice.pm @@ -471,40 +471,47 @@ OWDevice_UpdateValues($) { my $state; if($#polls>=0) { my $address= $hash->{fhem}{address}; + my $read_failed = 0; readingsBeginUpdate($hash); foreach my $reading (@polls) { my $value= OWDevice_ReadValue($hash,$reading); if(defined($value)) { readingsBulkUpdate($hash,$reading,$value); + } else { + $read_failed = 1; } } - if(@state) { - foreach my $reading (@state) { - my $value= ReadingsVal($hash->{NAME},$reading,undef); - if(defined($value)) { - $state .= "$reading: $value "; - } else { - $state .= "$reading: n/a "; + if( !$read_failed ) { + if(@state) { + foreach my $reading (@state) { + my $value= ReadingsVal($hash->{NAME},$reading,undef); + if(defined($value)) { + $state .= "$reading: $value "; + } else { + $state .= "$reading: n/a "; + } } } + if($alerting) { + my $dir= OWDevice_ReadFromServer($hash,"dir","/alarm/"); + my $alarm= (defined($dir) && $dir =~ m/$address/) ? 1 :0; + readingsBulkUpdate($hash,"alarm",$alarm); + $state .= "alarm: $alarm"; + } + if($interface eq "id") { + my $dir= OWDevice_ReadFromServer($hash,"dir","/"); + my $present= (defined($dir) && $dir =~ m/$address/) ? 1 :0; + readingsBulkUpdate($hash,"present",$present); + $state .= "present: $present"; + my $bus= OWDevice_ReadFromServer($hash,"find",$address); + my $location= (defined($bus)) ? $bus :"absent"; + readingsBulkUpdate($hash,"location",$location); + } + $state =~ s/\s+$//; + readingsBulkUpdate($hash,"state",$state,0); + } else { + readingsBulkUpdate($hash,"state","read failed",0); } - if($alerting) { - my $dir= OWDevice_ReadFromServer($hash,"dir","/alarm/"); - my $alarm= (defined($dir) && $dir =~ m/$address/) ? 1 :0; - readingsBulkUpdate($hash,"alarm",$alarm); - $state .= "alarm: $alarm"; - } - if($interface eq "id") { - my $dir= OWDevice_ReadFromServer($hash,"dir","/"); - my $present= (defined($dir) && $dir =~ m/$address/) ? 1 :0; - readingsBulkUpdate($hash,"present",$present); - $state .= "present: $present"; - my $bus= OWDevice_ReadFromServer($hash,"find",$address); - my $location= (defined($bus)) ? $bus :"absent"; - readingsBulkUpdate($hash,"location",$location); - } - $state =~ s/\s+$//; - readingsBulkUpdate($hash,"state",$state,0); readingsEndUpdate($hash,1); } RemoveInternalTimer($hash);