From d604ef1bafd98ccf0e339f89e08f9927cab3154f Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Mon, 28 Feb 2022 14:50:57 +0100 Subject: [PATCH] fix bug Can't use string as a HASH ref error with newest firmware Can't use string ("updating synchrometer") as a HASH ref while "strict refs" [Ticket: no] --- controls_TeslaPowerwall2AC.txt | 2 +- lib/FHEM/Devices/Tesla/Powerwall.pm | 56 +++++++++++++++-------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/controls_TeslaPowerwall2AC.txt b/controls_TeslaPowerwall2AC.txt index b12fe2d..e97d5c6 100644 --- a/controls_TeslaPowerwall2AC.txt +++ b/controls_TeslaPowerwall2AC.txt @@ -1,2 +1,2 @@ UPD 2022-01-29_04:24:06 6874 FHEM/46_TeslaPowerwall2AC.pm -UPD 2022-02-19_20:54:38 28171 lib/FHEM/Devices/Tesla/Powerwall.pm +UPD 2022-02-28_14:49:01 28406 lib/FHEM/Devices/Tesla/Powerwall.pm diff --git a/lib/FHEM/Devices/Tesla/Powerwall.pm b/lib/FHEM/Devices/Tesla/Powerwall.pm index a26e4ba..ebbece0 100644 --- a/lib/FHEM/Devices/Tesla/Powerwall.pm +++ b/lib/FHEM/Devices/Tesla/Powerwall.pm @@ -521,7 +521,7 @@ sub ErrorHandling { } ## Fehler für neuen Token - ## {"code":401,"error":"User session not found from HEZwKy9lY17-gLagEdpyzk3IsJgUvrE1jTP_SBDTyDQ2PPU--A8kF_p2tRmBQRLVKYzR11ijhO0j6kOXFzmxcw==","message":"Invalid bearer token"} + ## {"code":401,"error":"User session not found from HEZwKy9lY17-gLagEdpyzk3IsJgUvrE1XFzmxcw==","message":"Invalid bearer token"} if ( $data =~ m#{"code":(\d+),"error":"(.+)","message":"(.+)"}\z#xms ) { @@ -712,35 +712,39 @@ sub ReadingsProcessing_Powerwalls { my $r1 = $_; my $hRef; for my $hRef ( @{ $decode_json->{$_} } ) { - for ( keys %{$hRef} ) { - $r1 =~ s/s$//xg; - $readings{qq(${r1}_${i}_${_})} = $hRef->{$_} - if ( ref( $hRef->{$_} ) ne 'ARRAY' - && ref( $hRef->{$_} ) ne 'HASH' - && defined( $hRef->{$_} ) ); + if ( ref($hRef) eq 'HASH' ) { + for ( keys %{$hRef} ) { + $r1 =~ s/s$//xg; + $readings{qq(${r1}_${i}_${_})} = $hRef->{$_} + if ( ref( $hRef->{$_} ) ne 'ARRAY' + && ref( $hRef->{$_} ) ne 'HASH' + && defined( $hRef->{$_} ) ); - if ( ref( $hRef->{$_} ) eq 'HASH' ) { - my $r2 = $_; - my $r3 = $hRef->{$_}; - for ( keys %{$r3} ) { - $readings{qq(${r1}_${i}_${r2}_${_})} = $r3->{$_} - if ( ref( $r3->{$_} ) ne 'ARRAY' - && defined( $r3->{$_} ) ); + if ( ref( $hRef->{$_} ) eq 'HASH' ) { + my $r2 = $_; + my $r3 = $hRef->{$_}; + for ( keys %{$r3} ) { + $readings{qq(${r1}_${i}_${r2}_${_})} = + $r3->{$_} + if ( ref( $r3->{$_} ) ne 'ARRAY' + && defined( $r3->{$_} ) ); - if ( ref( $r3->{$_} ) eq 'ARRAY' ) { - my $ii = 0; - my $r4 = $_; - for $hRef ( @{ $r3->{$_} } ) { - for ( keys %{$hRef} ) { - $r4 =~ s/s$//xg; - $readings{ + if ( ref( $r3->{$_} ) eq 'ARRAY' ) { + my $ii = 0; + my $r4 = $_; + for $hRef ( @{ $r3->{$_} } ) { + for ( keys %{$hRef} ) { + $r4 =~ s/s$//xg; + $readings{ qq(${r1}_${i}_${r2}_${r4}_${ii}_${_}) - } = $hRef->{$_} - if ( ref( $hRef->{$_} ) ne 'HASH' - && defined( $hRef->{$_} ) ); - } + } = $hRef->{$_} + if ( + ref( $hRef->{$_} ) ne 'HASH' + && defined( $hRef->{$_} ) ); + } - $ii++; + $ii++; + } } } }