mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[hydrawise] Remove the access token when the thing is removed (#14945)
Related to #14818 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
2b674dde01
commit
da1a95fbdd
@ -68,18 +68,18 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
|
||||
private static final String SCOPE = "all";
|
||||
private final List<HydrawiseControllerListener> controllerListeners = Collections
|
||||
.synchronizedList(new ArrayList<HydrawiseControllerListener>());
|
||||
private final HydrawiseGraphQLClient apiClient;
|
||||
private final OAuthClientService oAuthService;
|
||||
private final HttpClient httpClient;
|
||||
private final OAuthFactory oAuthFactory;
|
||||
private @Nullable OAuthClientService oAuthService;
|
||||
private @Nullable HydrawiseGraphQLClient apiClient;
|
||||
private @Nullable ScheduledFuture<?> pollFuture;
|
||||
private @Nullable Customer lastData;
|
||||
private int refresh;
|
||||
|
||||
public HydrawiseAccountHandler(final Bridge bridge, final HttpClient httpClient, final OAuthFactory oAuthFactory) {
|
||||
super(bridge);
|
||||
this.oAuthService = oAuthFactory.createOAuthClientService(getThing().toString(), AUTH_URL, AUTH_URL, CLIENT_ID,
|
||||
CLIENT_SECRET, SCOPE, false);
|
||||
oAuthService.addAccessTokenRefreshListener(this);
|
||||
this.apiClient = new HydrawiseGraphQLClient(httpClient, oAuthService);
|
||||
this.httpClient = httpClient;
|
||||
this.oAuthFactory = oAuthFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -88,14 +88,34 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
OAuthClientService oAuthService = oAuthFactory.createOAuthClientService(getThing().toString(), AUTH_URL,
|
||||
AUTH_URL, CLIENT_ID, CLIENT_SECRET, SCOPE, false);
|
||||
this.oAuthService = oAuthService;
|
||||
oAuthService.addAccessTokenRefreshListener(this);
|
||||
this.apiClient = new HydrawiseGraphQLClient(httpClient, oAuthService);
|
||||
logger.debug("Handler initialized.");
|
||||
scheduler.schedule(this::configure, 0, TimeUnit.SECONDS);
|
||||
scheduler.schedule(() -> configure(oAuthService), 0, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
logger.debug("Handler disposed.");
|
||||
clearPolling();
|
||||
OAuthClientService oAuthService = this.oAuthService;
|
||||
if (oAuthService != null) {
|
||||
oAuthService.removeAccessTokenRefreshListener(this);
|
||||
oAuthFactory.ungetOAuthService(getThing().toString());
|
||||
this.oAuthService = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRemoval() {
|
||||
OAuthClientService oAuthService = this.oAuthService;
|
||||
if (oAuthService != null) {
|
||||
oAuthFactory.deleteServiceAndAccessToken(getThing().toString());
|
||||
}
|
||||
super.handleRemoval();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -134,7 +154,7 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
|
||||
initPolling(delaySeconds, this.refresh);
|
||||
}
|
||||
|
||||
private void configure() {
|
||||
private void configure(OAuthClientService oAuthService) {
|
||||
HydrawiseAccountConfiguration config = getConfig().as(HydrawiseAccountConfiguration.class);
|
||||
try {
|
||||
if (!config.userName.isEmpty() && !config.password.isEmpty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user