From d9a7ac4853a2694e1584cf74b2015a32c8ca20d9 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Sat, 19 Feb 2022 20:55:50 +0100 Subject: [PATCH] change condition to find out Invalid bearer token {"code":401,"error":"User session not found from HEZmxcw==","message":"Invalid bearer token"} [Ticket: no] --- controls_TeslaPowerwall2AC.txt | 2 +- lib/FHEM/Devices/Tesla/Powerwall.pm | 31 +++++++++++------------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/controls_TeslaPowerwall2AC.txt b/controls_TeslaPowerwall2AC.txt index 49042dd..b12fe2d 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-17_08:35:26 28294 lib/FHEM/Devices/Tesla/Powerwall.pm +UPD 2022-02-19_20:54:38 28171 lib/FHEM/Devices/Tesla/Powerwall.pm diff --git a/lib/FHEM/Devices/Tesla/Powerwall.pm b/lib/FHEM/Devices/Tesla/Powerwall.pm index 6dbd631..a26e4ba 100644 --- a/lib/FHEM/Devices/Tesla/Powerwall.pm +++ b/lib/FHEM/Devices/Tesla/Powerwall.pm @@ -161,12 +161,11 @@ sub Define { my $name = $aArg->[0]; my $host = $aArg->[2]; - $hash->{HOST} = $host; - $hash->{INTERVAL} = 300; - $hash->{VERSION} = version->parse($VERSION)->normal; - $hash->{NOTIFYDEV} = qq(global,$name); - $hash->{actionQueue} = []; - $hash->{helper}->{loginerr} = 0; + $hash->{HOST} = $host; + $hash->{INTERVAL} = 300; + $hash->{VERSION} = version->parse($VERSION)->normal; + $hash->{NOTIFYDEV} = qq(global,$name); + $hash->{actionQueue} = []; ::CommandAttr( undef, $name . q{ room Tesla} ) if ( ::AttrVal( $name, 'room', 'none' ) eq 'none' ); @@ -305,8 +304,6 @@ sub Get { return 'Unknown argument ' . $cmd . ', choose one of ' . $list; } - - $hash->{helper}->{loginerr} = 0 if $cmd eq 'login'; } return 'There are still path commands in the action queue' @@ -524,33 +521,29 @@ sub ErrorHandling { } ## Fehler für neuen Token - ## {"code":401,"error":"bad credentials","message":"Login Error"} + ## {"code":401,"error":"User session not found from HEZwKy9lY17-gLagEdpyzk3IsJgUvrE1jTP_SBDTyDQ2PPU--A8kF_p2tRmBQRLVKYzR11ijhO0j6kOXFzmxcw==","message":"Invalid bearer token"} - if ( $data =~ m#{"code":(\d+),"error":"(.+)","message":"(.+)"}$#xms ) { + if ( $data =~ m#{"code":(\d+),"error":"(.+)","message":"(.+)"}\z#xms ) { if ( $1 == 401 - && $2 eq 'bad credentials' - && $3 eq 'Login Error' - && $hash->{helper}->{loginerr} == 0 ) + && $2 =~ m#\AUser\ssession\snot\sfound\sfrom\s.*#xms + && $3 eq 'Invalid bearer token' ) { - $hash->{helper}->{loginerr} = 1; $hash->{actionQueue} = []; delete $hash->{TOKEN}; unshift @{ $hash->{actionQueue} }, 'login'; ::Log3 $name, 1, - "TeslaPowerwall2AC ($name) - Login Error. Empty action queue"; +"TeslaPowerwall2AC ($name) - Invalid bearer token. Empty action queue"; ::Log3 $name, 1, - "TeslaPowerwall2AC ($name) - Login Error. run relogin"; + "TeslaPowerwall2AC ($name) - Invalid bearer token. run relogin"; ::Log3 $name, 1, - "TeslaPowerwall2AC ($name) - Login Error. New action queue " +"TeslaPowerwall2AC ($name) - Invalid bearer token. New action queue " . join ',', @{ $hash->{actionQueue} }; return Write($hash); } - $hash->{helper}->{loginerr} = 0; - ::readingsBeginUpdate($hash); ::readingsBulkUpdate( $hash, 'state', $1, 1 );