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 b6a5c5f43c7d7..94623f750b68f 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 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 @@ private void pollGroupePSAs() { @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 void initialize() { } } + @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;