[groupepsa] Remove the access token when the thing is removed (#14943)

Related to #14818

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2023-05-05 22:16:24 +02:00 committed by GitHub
parent 5d65507584
commit 3ae72c92e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View 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;