[velux] fix discovery service de- and re- registration (#8673)

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
This commit is contained in:
Andrew Fiddian-Green 2020-10-08 18:13:35 +01:00 committed by GitHub
parent 937c7a3a45
commit 178e657d80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View 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;
}
}
}