From 6e1424ac8bcd9ee5fb4caccc9d708c226ddba4d2 Mon Sep 17 00:00:00 2001 From: Adimarantis <> Date: Tue, 16 Jan 2024 21:35:23 +0000 Subject: [PATCH] 58_RPI_1Wire: fix state and STATE setting git-svn-id: https://svn.fhem.de/fhem/trunk@28387 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/58_RPI_1Wire.pm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fhem/FHEM/58_RPI_1Wire.pm b/fhem/FHEM/58_RPI_1Wire.pm index 4bab5736c..895805d71 100755 --- a/fhem/FHEM/58_RPI_1Wire.pm +++ b/fhem/FHEM/58_RPI_1Wire.pm @@ -87,9 +87,10 @@ sub RPI_1Wire_Init { # my ( $hash, $args, $check ) = @_; Log3 $hash->{NAME}, 2, $hash->{NAME}.": Init: $args $check"; if (! -e "$w1_path") { - $hash->{STATE} ="No 1-Wire Bus found"; - Log3 $hash->{NAME}, 3, $hash->{NAME}.": Init: $hash->{STATE}"; - return $hash->{STATE}; + my $state="No 1-Wire Bus found"; + readingsSingleUpdate($hash,"state",$state,0); + Log3 $hash->{NAME}, 3, $hash->{NAME}.": Init: $state"; + return $state; } my @a = split("[ \t]+", $args); @@ -168,7 +169,8 @@ sub RPI_1Wire_Init { # RPI_1Wire_SetConversion($hash,$conv_time); } RPI_1Wire_GetConfig($hash); - $hash->{STATE} = "Initialized"; + my $state = "Initialized"; + readingsSingleUpdate($hash,"state",$state,0); Log3 $hash->{NAME}, 3, $hash->{NAME}.": Init done for $device $family $id $type"; RPI_1Wire_DeviceUpdate($hash); return; @@ -178,6 +180,7 @@ sub RPI_1Wire_GetDevices { my ($hash) = @_; Log3 $hash->{NAME}, 3 , $hash->{NAME}.": GetDevices"; my @devices; + print $ms_path.$hash->{id}."/w1_master_slaves"."\n"; if (open(my $fh, "<", $ms_path.$hash->{id}."/w1_master_slaves")) { while (my $device = <$fh>) { chomp $device; #remove \n @@ -307,8 +310,9 @@ sub RPI_1Wire_Switch { print $fh pack("C",$switch); close($fh); } else { - $hash->{STATE}="Error writing to $w1_path/$hash->{DEF}/output"; - return $hash->{STATE}; + my $state="Error writing to $w1_path/$hash->{DEF}/output"; + readingsSingleUpdate($hash,"state",$state,0); + return $state; } #After setting switch, read back to set readings correctly my $ret=RPI_1Wire_Poll($hash); @@ -673,8 +677,8 @@ sub RPI_1Wire_FinishFn { $state.="$par:$val "; } } - $hash->{STATE}=$state; - readingsEndUpdate($hash,1); + readingsEndUpdate($hash,1); + readingsSingleUpdate($hash,"state",$state,0); } sub RPI_1Wire_Attr { #