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