2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

49_Arlo.pm: login again after invalid access token error

git-svn-id: https://svn.fhem.de/fhem/trunk@20219 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
maluk 2019-09-21 16:34:16 +00:00
parent 0d41a53e95
commit df8e3406bf

View File

@ -445,7 +445,8 @@ sub Arlo_BlockingRequest($$;$$$$) {
sub Arlo_DefaultCallback($$$) { sub Arlo_DefaultCallback($$$) {
my ($hash, $err, $jsonData) = @_; my ($hash, $err, $jsonData) = @_;
my $name = $modules{$MODULE}{defptr}{"account"}{NAME}; my $account = $modules{$MODULE}{defptr}{"account"};
my $name = $account->{NAME};
if ($err) { if ($err) {
Log3 $name, 2, "Error occured when calling Arlo daemon: $err"; Log3 $name, 2, "Error occured when calling Arlo daemon: $err";
return undef; return undef;
@ -463,6 +464,12 @@ sub Arlo_DefaultCallback($$$) {
if ($origin && $data->{error} eq '2059' && $data->{reason} eq 'Device is offline.') { if ($origin && $data->{error} eq '2059' && $data->{reason} eq 'Device is offline.') {
readingsSingleUpdate($origin, 'state', 'offline', 1) if (ReadingsVal($origin->{NAME}, 'state', '') ne 'offline'); readingsSingleUpdate($origin, 'state', 'offline', 1) if (ReadingsVal($origin->{NAME}, 'state', '') ne 'offline');
$logLevel = 5; $logLevel = 5;
} elsif ($data->{error} eq '1022' && $data->{reason} eq 'Access token is invalid') {
Log3 $name, 3, "Arlo access token was invalid. Reconnect to Arlo.";
if ($hash->{STATE} eq 'active') {
Arlo_Login($account);
}
$logLevel = 5;
} }
} }
Log3 $name, $logLevel, "Arlo call was not successful: $jsonData"; Log3 $name, $logLevel, "Arlo call was not successful: $jsonData";
@ -959,6 +966,8 @@ sub Arlo_Login($) {
return; return;
} }
$hash->{STATE} = 'inactive';
my $password = encode_base64($hash->{helper}{password}, ''); my $password = encode_base64($hash->{helper}{password}, '');
my $input = {email => $hash->{helper}{username}, password => $password, EnvSource => 'prod', language => 'de'}; my $input = {email => $hash->{helper}{username}, password => $password, EnvSource => 'prod', language => 'de'};
my $postData = encode_json $input; my $postData = encode_json $input;