[automower] Remove the access token when the thing is removed (#14971)

Related to #14818

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2023-05-11 22:01:49 +02:00 committed by GitHub
parent 29edae9f21
commit 14e7109a25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,7 +54,7 @@ public class AutomowerBridgeHandler extends BaseBridgeHandler {
private final OAuthFactory oAuthFactory; private final OAuthFactory oAuthFactory;
private @NonNullByDefault({}) OAuthClientService oAuthService; private @Nullable OAuthClientService oAuthService;
private @Nullable ScheduledFuture<?> automowerBridgePollingJob; private @Nullable ScheduledFuture<?> automowerBridgePollingJob;
private @Nullable AutomowerBridge bridge; private @Nullable AutomowerBridge bridge;
private final HttpClient httpClient; private final HttpClient httpClient;
@ -85,7 +85,11 @@ public class AutomowerBridgeHandler extends BaseBridgeHandler {
stopAutomowerBridgePolling(currentBridge); stopAutomowerBridgePolling(currentBridge);
bridge = null; bridge = null;
} }
oAuthFactory.ungetOAuthService(thing.getUID().getAsString()); OAuthClientService oAuthService = this.oAuthService;
if (oAuthService != null) {
oAuthFactory.ungetOAuthService(thing.getUID().getAsString());
this.oAuthService = null;
}
} }
@Override @Override
@ -104,8 +108,9 @@ public class AutomowerBridgeHandler extends BaseBridgeHandler {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"@text/conf-error-invalid-polling-interval"); "@text/conf-error-invalid-polling-interval");
} else { } else {
oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(), HUSQVARNA_API_TOKEN_URL, OAuthClientService oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(),
null, appKey, appSecret, null, null); HUSQVARNA_API_TOKEN_URL, null, appKey, appSecret, null, null);
this.oAuthService = oAuthService;
if (bridge == null) { if (bridge == null) {
AutomowerBridge currentBridge = new AutomowerBridge(oAuthService, appKey, httpClient, scheduler); AutomowerBridge currentBridge = new AutomowerBridge(oAuthService, appKey, httpClient, scheduler);
@ -116,6 +121,12 @@ public class AutomowerBridgeHandler extends BaseBridgeHandler {
} }
} }
@Override
public void handleRemoval() {
oAuthFactory.deleteServiceAndAccessToken(thing.getUID().getAsString());
super.handleRemoval();
}
private void startAutomowerBridgePolling(AutomowerBridge bridge, @Nullable Integer pollingIntervalS) { private void startAutomowerBridgePolling(AutomowerBridge bridge, @Nullable Integer pollingIntervalS) {
ScheduledFuture<?> currentPollingJob = automowerBridgePollingJob; ScheduledFuture<?> currentPollingJob = automowerBridgePollingJob;
if (currentPollingJob == null) { if (currentPollingJob == null) {