Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IpAddonFinder: Skip installed addons #4013

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.addon.Addon;
import org.openhab.core.addon.AddonDiscoveryMethod;
import org.openhab.core.addon.AddonInfo;
import org.openhab.core.addon.AddonMatchProperty;
import org.openhab.core.addon.AddonParameter;
import org.openhab.core.addon.AddonService;
import org.openhab.core.common.ThreadPoolManager;
import org.openhab.core.config.discovery.addon.AddonFinder;
import org.openhab.core.config.discovery.addon.BaseAddonFinder;
import org.openhab.core.net.NetUtil;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -148,11 +152,14 @@ public class IpAddonFinder extends BaseAddonFinder {
private final Logger logger = LoggerFactory.getLogger(IpAddonFinder.class);
private final ScheduledExecutorService scheduler = ThreadPoolManager
.getScheduledPool(ThreadPoolManager.THREAD_POOL_NAME_COMMON);
private @Nullable AddonService addonService;
private @Nullable Future<?> scanJob = null;
Set<AddonInfo> suggestions = new HashSet<>();

public IpAddonFinder() {
@Activate
public IpAddonFinder(@Reference AddonService as) {
logger.trace("IpAddonFinder::IpAddonFinder");
this.addonService = as;
// start of scan will be triggered by setAddonCandidates to ensure addonCandidates are available
}

Expand Down Expand Up @@ -197,6 +204,16 @@ private void scan() {

logger.trace("Checking candidate: {}", candidate.getUID());

// skip scanning if already installed
if (addonService != null) {
@Nullable
holgerfriedrich marked this conversation as resolved.
Show resolved Hide resolved
Addon a = addonService.getAddon(candidate.getUID(), null);
if (a != null && a.isInstalled()) {
logger.trace("Skipping {}, already installed", candidate.getUID());
continue;
}
}

Map<String, String> parameters = method.getParameters().stream()
.collect(Collectors.toMap(AddonParameter::getName, AddonParameter::getValue));
Map<String, String> matchProperties = method.getMatchProperties().stream()
Expand Down