Skip to content

Commit

Permalink
Fix startup of background discovery (#4323)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
lolodomo authored Jul 17, 2024
1 parent 6f0add0 commit 0a5886c
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@ protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Se
int timeout, boolean backgroundDiscoveryEnabledByDefault) throws IllegalArgumentException {
super(supportedThingTypes, timeout, backgroundDiscoveryEnabledByDefault);
this.thingClazz = thingClazz;
this.backgroundDiscoveryEnabled = backgroundDiscoveryEnabledByDefault;
}

protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, @Nullable Set<ThingTypeUID> supportedThingTypes,
int timeout) throws IllegalArgumentException {
super(supportedThingTypes, timeout);
this.thingClazz = thingClazz;
this(thingClazz, supportedThingTypes, timeout, true);
}

protected AbstractThingHandlerDiscoveryService(Class<T> thingClazz, int timeout) throws IllegalArgumentException {
super(timeout);
this.thingClazz = thingClazz;
this(thingClazz, null, timeout);
}

@Override
Expand Down Expand Up @@ -86,15 +85,17 @@ public void activate(@Nullable Map<String, Object> 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);
}
}

@Override
public void modified(@Nullable Map<String, Object> 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();
Expand Down

0 comments on commit 0a5886c

Please sign in to comment.