]> git.basschouten.com Git - openhab-addons.git/commitdiff
[velux] fix discovery service de- and re- registration (#8673)
authorAndrew Fiddian-Green <software@whitebear.ch>
Thu, 8 Oct 2020 17:13:35 +0000 (18:13 +0100)
committerGitHub <noreply@github.com>
Thu, 8 Oct 2020 17:13:35 +0000 (19:13 +0200)
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
bundles/org.openhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/factory/VeluxHandlerFactory.java

index 41b8708c44fe9965f6a98d342f7b65654ae789a6..0be2f1d7ca696b7bc34f39c556bbe04f87c26f22 100644 (file)
@@ -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;
                 }
             }
         }