]> git.basschouten.com Git - openhab-addons.git/commitdiff
[groupepsa] Remove the access token when the thing is removed (#14943)
authorlolodomo <lg.hc@free.fr>
Fri, 5 May 2023 20:16:24 +0000 (22:16 +0200)
committerGitHub <noreply@github.com>
Fri, 5 May 2023 20:16:24 +0000 (22:16 +0200)
Related to #14818

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java

index b6a5c5f43c7d7e066552fd585315afd48354e18d..94623f750b68f5ff7473f85c16c6a5785cfce11f 100644 (file)
@@ -13,7 +13,6 @@
 package org.openhab.binding.groupepsa.internal.bridge;
 
 import static org.openhab.binding.groupepsa.internal.GroupePSABindingConstants.THING_TYPE_BRIDGE;
-import static org.openhab.binding.groupepsa.internal.GroupePSABindingConstants.VendorConstants;
 
 import java.io.IOException;
 import java.util.Collection;
@@ -26,6 +25,7 @@ import java.util.concurrent.TimeUnit;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jetty.client.HttpClient;
+import org.openhab.binding.groupepsa.internal.GroupePSABindingConstants.VendorConstants;
 import org.openhab.binding.groupepsa.internal.discovery.GroupePSADiscoveryService;
 import org.openhab.binding.groupepsa.internal.rest.api.GroupePSAConnectApi;
 import org.openhab.binding.groupepsa.internal.rest.api.dto.Vehicle;
@@ -94,7 +94,10 @@ public class GroupePSABridgeHandler extends BaseBridgeHandler {
     @Override
     public void dispose() {
         stopGroupePSABridgePolling();
-        oAuthFactory.ungetOAuthService(thing.getUID().getAsString());
+        if (oAuthService != null) {
+            oAuthFactory.ungetOAuthService(thing.getUID().getAsString());
+            oAuthService = null;
+        }
     }
 
     @Override
@@ -138,6 +141,14 @@ public class GroupePSABridgeHandler extends BaseBridgeHandler {
         }
     }
 
+    @Override
+    public void handleRemoval() {
+        if (oAuthService != null) {
+            oAuthFactory.deleteServiceAndAccessToken(thing.getUID().getAsString());
+        }
+        super.handleRemoval();
+    }
+
     private void startGroupePSABridgePolling(@Nullable Integer pollingIntervalM) {
         if (groupepsaBridgePollingJob == null) {
             final long pollingIntervalToUse = pollingIntervalM == null ? DEFAULT_POLLING_INTERVAL_M : pollingIntervalM;