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<>());
}
ServiceRegistration<?> discoveryServiceRegistration = this.discoveryServiceRegistration;
if (discoveryServiceRegistration != null) {
discoveryServiceRegistration.unregister();
+ this.discoveryServiceRegistration = null;
}
}
}