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

Community Marketplace add-ons show the version range from the topic after being installed #4521

Open
Nadahar opened this issue Dec 26, 2024 · 2 comments
Labels
bug An unexpected problem or unintended behavior of the Core

Comments

@Nadahar
Copy link

Nadahar commented Dec 26, 2024

The version range string from the forum topic is used for compatibility checks. The topic is also used as the name of the add-on. When parsing the community marketplace entries, the range string is stripped from the topic string.

However, when an add-on is installed, the version range is not stripped. The "full topic" is stored in the JSONDB, and is later retrieved from there for already installed add-ons, leading to the version range being displayed in the UI whenever the add-on name is displayed.

Expected Behavior

Add-on names should be displayed without the version range also when installed locally.

Current Behavior

Add-on names include the version range string after they are installed.

9526079a644ad61d017080983ea5bd44e1c06949

Possible Solution

I managed to fix this with the following:

 .../internal/community/CommunityMarketplaceAddonService.java | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java
index 3d791d447..ca62ac7cc 100644
--- a/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java
+++ b/bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/internal/community/CommunityMarketplaceAddonService.java
@@ -437,8 +437,18 @@ public class CommunityMarketplaceAddonService extends AbstractRemoteAddonService
         boolean installed = addonHandlers.stream()
                 .anyMatch(handler -> handler.supports(type, contentType) && handler.isInstalled(uid));
 
+        String title = topic.title;
+        int compatibilityStart = topic.title.lastIndexOf("["); // version range always starts with [
+        if (topic.title.lastIndexOf(" ") < compatibilityStart) { // check includes [ not present
+            String potentialRange = topic.title.substring(compatibilityStart);
+            Matcher matcher = BundleVersion.RANGE_PATTERN.matcher(potentialRange);
+            if (matcher.matches()) {
+                title = topic.title.substring(0, compatibilityStart).trim();
+            }
+        }
+
         Addon.Builder builder = Addon.create(uid).withType(type).withId(id).withContentType(contentType)
-                .withLabel(topic.title).withImageLink(topic.imageUrl)
+                .withLabel(title).withImageLink(topic.imageUrl)
                 .withLink(COMMUNITY_TOPIC_URL + topic.id.toString())
                 .withAuthor(topic.postStream.posts[0].displayUsername).withMaturity(maturity)
                 .withDetailedDescription(detailedDescription).withInstalled(installed).withProperties(properties);

This logic could be made more "elegant" and robust (like also working if there's no space between the name and the version range, not depending on the start bracket being [ etc.), but I just copied the existing logic to make sure they work exactly the same.

I'm sure some will say that this should have been a PR - but that's not an option because the CLA requires you to state your full name and e-mail in public. As such, there isn't any point in "making the logic more robust" either, since my code won't be used anyway. I'm merely posting it here as a "suggestion" of how this could be solved.

Steps to Reproduce (for Bugs)

Install an add-on that has a version range string (for example Mill LAN Binding) and refresh the marketplace page - or add a new Thing manually and watch the binding name in the "select binding" dialog.

@Nadahar Nadahar added the bug An unexpected problem or unintended behavior of the Core label Dec 26, 2024
@Nadahar Nadahar changed the title Community Marketplace add-ons shows the version range from the topic after being installed Community Marketplace add-ons show the version range from the topic after being installed Dec 26, 2024
@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/millheat-local-api-development-questions/160139/145

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/marketplace-versioning-with-embedded-resource/161421/5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of the Core
Projects
None yet
Development

No branches or pull requests

2 participants