From fed69bc0ccb8d6a222892e4ba96e8778a0f87bc6 Mon Sep 17 00:00:00 2001 From: moises <> Date: Fri, 7 Jun 2024 23:03:38 +0000 Subject: [PATCH] 32_withings: improved token refresh timing git-svn-id: https://svn.fhem.de/fhem/trunk@28952 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/32_withings.pm | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 9b3a59ec5..8335af826 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # 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 + - bufgix: 32_withings: improved token refresh timing - change: 38_netatmo: improved disconnect handling on auth failure - change: 76_SolarForecast: set inverterStrings to attr setupInverterStrings !NOTE! save FHEM config after restart diff --git a/fhem/FHEM/32_withings.pm b/fhem/FHEM/32_withings.pm index c27283eb6..ed0d07860 100644 --- a/fhem/FHEM/32_withings.pm +++ b/fhem/FHEM/32_withings.pm @@ -10,7 +10,7 @@ # # ############################################################################## -# Release 18 / 2023-07-23 +# Release 19 / 2024-06-08 package main; @@ -1234,7 +1234,11 @@ sub withings_initUser($) { $attr{$name}{stateFormat} = "weight kg" if( !defined( $attr{$name}{stateFormat} ) ); InternalTimer(gettimeofday()+60, "withings_poll", $hash, 0); - withings_AuthRefresh($hash) if(defined(ReadingsVal($name,".refresh_token",undef))); + if(defined(ReadingsVal($name,".refresh_token",undef))){ + RemoveInternalTimer($hash, "withings_AuthRefresh"); + InternalTimer(gettimeofday()+12, "withings_AuthRefresh", $hash, 0); + } + } @@ -2894,10 +2898,10 @@ sub withings_Get($$@) { my $users = withings_getUsers($hash); my $ret; foreach my $user (@{$users}) { - $ret .= "$user->{id}\t\[$user->{shortname}\]\t$user->{publickey} \t$user->{usertype}/$user->{status}\t$user->{firstname} $user->{lastname}\n"; + $ret .= "$user->{id}\t\[$user->{shortname}\]\t$user->{usertype}/$user->{status}\t\t$user->{firstname} $user->{lastname}\n"; } - $ret = "id\tshort\tpublickey\tusertype/status\tname\n" . $ret if( $ret );; + $ret = "id\tshort\tusertype/status\tname\n" . $ret if( $ret );; $ret = "no users found" if( !$ret ); return $ret; } @@ -3899,7 +3903,7 @@ sub withings_AuthApp($;$) { readingsSingleUpdate( $userhash, ".refresh_token", $json->{body}{refresh_token}, 1 ) if(defined($json->{body}{refresh_token})); RemoveInternalTimer($userhash, "withings_AuthRefresh"); - InternalTimer(gettimeofday()+$json->{body}{expires_in}-60, "withings_AuthRefresh", $userhash, 0); + InternalTimer(gettimeofday()+$json->{body}{expires_in}-1800, "withings_AuthRefresh", $userhash, 0); #https://wbsapi.withings.net/notify?action=subscribe&access_token=a639e912dfc31a02cc01ea4f38de7fa4a1464c2e&callbackurl=http://fhem:remote@gu9mohkaxqdgpix5.myfritz.net/fhem/withings&appli=1&comment=fhem @@ -3958,7 +3962,7 @@ sub withings_AuthRefresh($) { $hash->{helper}{OAuthValid} = (int(time)+$json->{body}{expires_in}) if(defined($json->{body}{expires_in})); readingsSingleUpdate( $hash, ".refresh_token", $json->{body}{refresh_token}, 1 ) if(defined($json->{body}{refresh_token})); - InternalTimer(gettimeofday()+$json->{body}{expires_in}-60, "withings_AuthRefresh", $hash, 0); + InternalTimer(gettimeofday()+$json->{body}{expires_in}-1800, "withings_AuthRefresh", $hash, 0); #https://wbsapi.withings.net/notify?action=subscribe&access_token=a639e912dfc31a02cc01ea4f38de7fa4a1464c2e&callbackurl=http://fhem:remote@gu9mohkaxqdgpix5.myfritz.net/fhem/withings&appli=1&comment=fhem