[nanoleaf] Stop the HTTP client when disposing the thing handler (#14459)

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2023-02-20 20:28:27 +01:00 committed by GitHub
parent 1f877cae6d
commit d33f6916d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,6 +91,7 @@ import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.binding.BaseBridgeHandler;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.ThingHandlerService;
import org.openhab.core.thing.util.ThingWebClientUtil;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.slf4j.Logger;
@ -147,7 +148,7 @@ public class NanoleafControllerHandler extends BaseBridgeHandler implements Nano
}
private void initializeTouchHttpClient() {
String httpClientName = thing.getUID().getId();
String httpClientName = ThingWebClientUtil.buildWebClientConsumerName(thing.getUID(), null);
try {
httpClientSSETouchEvent = httpClientFactory.createHttpClient(httpClientName);
@ -290,6 +291,14 @@ public class NanoleafControllerHandler extends BaseBridgeHandler implements Nano
@Override
public void dispose() {
stopAllJobs();
HttpClient localHttpClientSSETouchEvent = this.httpClientSSETouchEvent;
if (localHttpClientSSETouchEvent != null) {
try {
localHttpClientSSETouchEvent.stop();
} catch (Exception e) {
}
this.httpClientSSETouchEvent = null;
}
super.dispose();
logger.debug("Disposing handler for Nanoleaf controller {}", getThing().getUID());
}