From 0a5886c7e75a9dc9cc3f92c761712ace27cba3d7 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Wed, 17 Jul 2024 19:50:51 +0200 Subject: [PATCH] Fix startup of background discovery (#4323) Apply the same logic in AbstractThingHandlerDiscoveryService as in AbstractDiscoveryService to determine if background discovery should be enabled or disabled. Fix openhab/openhab-addons#17089 Signed-off-by: Laurent Garnier --- .../AbstractThingHandlerDiscoveryService.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/AbstractThingHandlerDiscoveryService.java b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/AbstractThingHandlerDiscoveryService.java index 377c8e62fdf..0dd7aa12594 100644 --- a/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/AbstractThingHandlerDiscoveryService.java +++ b/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/AbstractThingHandlerDiscoveryService.java @@ -48,17 +48,16 @@ protected AbstractThingHandlerDiscoveryService(Class thingClazz, @Nullable Se int timeout, boolean backgroundDiscoveryEnabledByDefault) throws IllegalArgumentException { super(supportedThingTypes, timeout, backgroundDiscoveryEnabledByDefault); this.thingClazz = thingClazz; + this.backgroundDiscoveryEnabled = backgroundDiscoveryEnabledByDefault; } protected AbstractThingHandlerDiscoveryService(Class thingClazz, @Nullable Set supportedThingTypes, int timeout) throws IllegalArgumentException { - super(supportedThingTypes, timeout); - this.thingClazz = thingClazz; + this(thingClazz, supportedThingTypes, timeout, true); } protected AbstractThingHandlerDiscoveryService(Class thingClazz, int timeout) throws IllegalArgumentException { - super(timeout); - this.thingClazz = thingClazz; + this(thingClazz, null, timeout); } @Override @@ -86,7 +85,8 @@ public void activate(@Nullable Map config) { // thing handler is set. This is correctly handled in initialize if (config != null) { backgroundDiscoveryEnabled = ConfigParser.valueAsOrElse( - config.get(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY), Boolean.class, false); + config.get(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY), Boolean.class, + backgroundDiscoveryEnabled); } } @@ -94,7 +94,8 @@ public void activate(@Nullable Map config) { public void modified(@Nullable Map config) { if (config != null) { boolean enabled = ConfigParser.valueAsOrElse( - config.get(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY), Boolean.class, false); + config.get(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY), Boolean.class, + backgroundDiscoveryEnabled); if (backgroundDiscoveryEnabled && !enabled) { stopBackgroundDiscovery();