From: Andrew Fiddian-Green Date: Thu, 8 Oct 2020 17:13:35 +0000 (+0100) Subject: [velux] fix discovery service de- and re- registration (#8673) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=178e657d809395ce3a30e482c77f1dbd3b4b7035;p=openhab-addons.git [velux] fix discovery service de- and re- registration (#8673) Signed-off-by: Andrew Fiddian-Green --- diff --git a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/factory/VeluxHandlerFactory.java b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/factory/VeluxHandlerFactory.java index 41b8708c44..0be2f1d7ca 100644 --- a/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/factory/VeluxHandlerFactory.java +++ b/bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/factory/VeluxHandlerFactory.java @@ -68,14 +68,12 @@ public class VeluxHandlerFactory extends BaseThingHandlerFactory { private void registerDeviceDiscoveryService(VeluxBridgeHandler bridgeHandler) { logger.trace("registerDeviceDiscoveryService({}) called.", bridgeHandler); - boolean createNew = false; VeluxDiscoveryService discoveryService = this.discoveryService; if (discoveryService == null) { - discoveryService = new VeluxDiscoveryService(localization); - createNew = true; + discoveryService = this.discoveryService = new VeluxDiscoveryService(localization); } discoveryService.addBridge(bridgeHandler); - if (createNew) { + if (discoveryServiceRegistration == null) { discoveryServiceRegistration = bundleContext.registerService(DiscoveryService.class.getName(), discoveryService, new Hashtable<>()); } @@ -90,6 +88,7 @@ public class VeluxHandlerFactory extends BaseThingHandlerFactory { ServiceRegistration discoveryServiceRegistration = this.discoveryServiceRegistration; if (discoveryServiceRegistration != null) { discoveryServiceRegistration.unregister(); + this.discoveryServiceRegistration = null; } } }