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

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

index 8969c0bf79f55b88daca38b3863bb9d0b708342c..db483b3b1fdc4f9ad105031feeb66ade9b031ff2 100644 (file)
@@ -84,7 +84,7 @@ public class HomeConnectBridgeHandler extends BaseBridgeHandler {
     private @Nullable List<Event> eventHistory;
 
     private @NonNullByDefault({}) OAuthClientService oAuthClientService;
-    private @NonNullByDefault({}) String oAuthServiceHandleId;
+    private @Nullable String oAuthServiceHandleId;
     private @NonNullByDefault({}) HomeConnectApiClient apiClient;
     private @NonNullByDefault({}) HomeConnectEventSourceClient eventSourceClient;
 
@@ -221,6 +221,15 @@ public class HomeConnectBridgeHandler extends BaseBridgeHandler {
         }
     }
 
+    @Override
+    public void handleRemoval() {
+        String handleId = this.oAuthServiceHandleId;
+        if (handleId != null) {
+            oAuthFactory.deleteServiceAndAccessToken(handleId);
+        }
+        super.handleRemoval();
+    }
+
     @Override
     public Collection<Class<? extends ThingHandlerService>> getServices() {
         return Collections.singleton(HomeConnectDiscoveryService.class);
@@ -285,7 +294,10 @@ public class HomeConnectBridgeHandler extends BaseBridgeHandler {
         eventSourceClient.getLatestEvents().clear();
         eventSourceClient.dispose(immediate);
 
-        oAuthFactory.ungetOAuthService(oAuthServiceHandleId);
+        String handleId = this.oAuthServiceHandleId;
+        if (handleId != null) {
+            oAuthFactory.ungetOAuthService(handleId);
+        }
         homeConnectServlet.removeBridgeHandler(this);
     }