From 3ae72c92e5dd36ad57fb77c2b9fb7e3773d31045 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Fri, 5 May 2023 22:16:24 +0200 Subject: [PATCH] [groupepsa] Remove the access token when the thing is removed (#14943) Related to #14818 Signed-off-by: Laurent Garnier --- .../internal/bridge/GroupePSABridgeHandler.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java index b6a5c5f43..94623f750 100644 --- a/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java +++ b/bundles/org.openhab.binding.groupepsa/src/main/java/org/openhab/binding/groupepsa/internal/bridge/GroupePSABridgeHandler.java @@ -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;