mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-01 00:19:00 +00:00
38_netatmo: new token refresh handling and fallback reading
git-svn-id: https://svn.fhem.de/fhem/trunk@28982 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
8ece88a058
commit
be84d2ca6d
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it
|
# Do not insert empty lines here, update check depends on it
|
||||||
|
- change: 38_netatmo: new token refresh handling and fallback reading
|
||||||
- bugfix: 76_SolarForecast: fix Warnings
|
- bugfix: 76_SolarForecast: fix Warnings
|
||||||
- change: 76_SolarForecast: set moduleAzimuth to attr setupStringAzimuth
|
- change: 76_SolarForecast: set moduleAzimuth to attr setupStringAzimuth
|
||||||
set moduleDeclination to setupStringDeclination
|
set moduleDeclination to setupStringDeclination
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Release 30 / 2024-06-08
|
# Release 31 / 2024-06-17
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
@ -449,9 +449,8 @@ netatmo_Define($$)
|
|||||||
$hash->{helper}{password} = $password;
|
$hash->{helper}{password} = $password;
|
||||||
$hash->{helper}{client_id} = $client_id;
|
$hash->{helper}{client_id} = $client_id;
|
||||||
$hash->{helper}{client_secret} = $client_secret;
|
$hash->{helper}{client_secret} = $client_secret;
|
||||||
$hash->{refresh_token} = $refresh_token if(!defined($hash->{refresh_token}));
|
$hash->{refresh_token} = $refresh_token;
|
||||||
$hash->{helper}{refresh_token} = $hash->{refresh_token};
|
$hash->{helper}{refresh_token} = $hash->{refresh_token};
|
||||||
$hash->{helper}{refresh_token} = $refresh_token if(!$hash->{helper}{refresh_token});
|
|
||||||
$hash->{helper}{last_refresh} = 0;
|
$hash->{helper}{last_refresh} = 0;
|
||||||
|
|
||||||
$hash->{helper}{INTERVAL} = 60*60 if( !$hash->{helper}{INTERVAL} );
|
$hash->{helper}{INTERVAL} = 60*60 if( !$hash->{helper}{INTERVAL} );
|
||||||
@ -2916,19 +2915,29 @@ netatmo_dispatch($$$)
|
|||||||
Log3 $name, 5, Dumper($json);
|
Log3 $name, 5, Dumper($json);
|
||||||
|
|
||||||
if( ref($json) eq "HASH" && $json->{error} ) {
|
if( ref($json) eq "HASH" && $json->{error} ) {
|
||||||
if(ref($json->{error}) ne "HASH") {
|
if(ref($json->{error}) ne "HASH") { #only error on login/token, error->message on other data communication
|
||||||
$hash->{STATE} = "LOGIN FAILED" if($hash->{SUBTYPE} eq "ACCOUNT");
|
$hash->{STATE} = "LOGIN FAILED" if($hash->{SUBTYPE} eq "ACCOUNT");
|
||||||
$hash->{status} = $json->{error};
|
|
||||||
Log3 $name, 2, "$name: json message error: ".$json->{error};
|
Log3 $name, 2, "$name: json message error: ".$json->{error};
|
||||||
readingsSingleUpdate( $hash, "active", $hash->{status}, 1 ) if($hash->{status} ne "no data");
|
readingsSingleUpdate( $hash, "active", $hash->{status}, 1 ) if($hash->{status} ne "no data");
|
||||||
if($param->{type} eq "token" && $json->{error} eq "invalid_grant"){
|
if($param->{type} eq "token" && $json->{error} eq "invalid_grant"){
|
||||||
#if($hash->{expires_at} <= int(gettimeofday())){
|
if($hash->{status} eq "invalid_grant error"){
|
||||||
$hash->{status} = "invalid_grant error";
|
|
||||||
$hash->{network} = "disconnected" if($hash->{SUBTYPE} eq "ACCOUNT");
|
$hash->{network} = "disconnected" if($hash->{SUBTYPE} eq "ACCOUNT");
|
||||||
|
CommandDeleteReading( undef, "$hash->{NAME} .refreshtoken" );
|
||||||
$attr{$name}{disable} = "1" if($hash->{SUBTYPE} eq "ACCOUNT");
|
$attr{$name}{disable} = "1" if($hash->{SUBTYPE} eq "ACCOUNT");
|
||||||
Log3 $name, 2, "$name: invalid refresh ticket, disabling module";
|
Log3 $name, 2, "$name: invalid refresh ticket, disabling module";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
#if($hash->{expires_at} <= int(gettimeofday())){
|
||||||
|
$hash->{status} = "invalid_grant error";
|
||||||
|
Log3 $name, 2, "$name: invalid refresh ticket, retrying once";
|
||||||
|
$hash->{helper}{refresh_token} = ReadingsVal($name, ".refreshtoken", undef);
|
||||||
|
InternalTimer(gettimeofday()+5, "netatmo_refreshToken", $hash, 0);
|
||||||
#}
|
#}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$hash->{status} = $json->{error};
|
||||||
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3366,6 +3375,8 @@ netatmo_parseToken($$)
|
|||||||
|
|
||||||
if($old_refresh ne $hash->{refresh_token}){
|
if($old_refresh ne $hash->{refresh_token}){
|
||||||
if($hash->{SUBTYPE} eq "ACCOUNT"){
|
if($hash->{SUBTYPE} eq "ACCOUNT"){
|
||||||
|
readingsSingleUpdate( $hash, ".refreshtoken", $json->{refresh_token}, 0 );
|
||||||
|
|
||||||
my @defarray = split(/ /, $hash->{DEF});
|
my @defarray = split(/ /, $hash->{DEF});
|
||||||
pop(@defarray);
|
pop(@defarray);
|
||||||
push(@defarray, $json->{refresh_token});
|
push(@defarray, $json->{refresh_token});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user