From 178e657d809395ce3a30e482c77f1dbd3b4b7035 Mon Sep 17 00:00:00 2001 From: Andrew Fiddian-Green Date: Thu, 8 Oct 2020 18:13:35 +0100 Subject: [PATCH] [velux] fix discovery service de- and re- registration (#8673) Signed-off-by: Andrew Fiddian-Green --- .../velux/internal/factory/VeluxHandlerFactory.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 41b8708c4..0be2f1d7c 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; } } }