]> git.basschouten.com Git - openhab-addons.git/commitdiff
fix startup (#16971)
authorMark Herwege <mherwege@users.noreply.github.com>
Mon, 1 Jul 2024 11:55:32 +0000 (13:55 +0200)
committerGitHub <noreply@github.com>
Mon, 1 Jul 2024 11:55:32 +0000 (13:55 +0200)
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SystemInfoBindingConstants.java
bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SystemInfoHandlerFactory.java

index 5563c66fb01e74ddb6da074cfdd2be477b701823..ea3beab5e59a60c162dedc044e8b631ac5f62cec 100644 (file)
@@ -28,8 +28,10 @@ public class SystemInfoBindingConstants {
 
     public static final String BINDING_ID = "systeminfo";
 
-    public static final ThingTypeUID THING_TYPE_COMPUTER = new ThingTypeUID(BINDING_ID, "computer");
-    public static final ThingTypeUID THING_TYPE_COMPUTER_IMPL = new ThingTypeUID(BINDING_ID, "computer-impl");
+    public static final String THING_TYPE_COMPUTER_ID = "computer";
+    public static final ThingTypeUID THING_TYPE_COMPUTER = new ThingTypeUID(BINDING_ID, THING_TYPE_COMPUTER_ID);
+    public static final ThingTypeUID THING_TYPE_COMPUTER_IMPL = new ThingTypeUID(BINDING_ID,
+            THING_TYPE_COMPUTER_ID + "-impl");
 
     // Thing properties
     /**
index 7f92c8d5bdc7f6f31c800440bf649d98e4735e36..3fa5e00a1df10900dcfa0befe996f25a649c2859 100644 (file)
@@ -14,8 +14,6 @@ package org.openhab.binding.systeminfo.internal;
 
 import static org.openhab.binding.systeminfo.internal.SystemInfoBindingConstants.*;
 
-import java.util.Set;
-
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.systeminfo.internal.handler.SystemInfoHandler;
@@ -43,25 +41,22 @@ public class SystemInfoHandlerFactory extends BaseThingHandlerFactory {
     private @NonNullByDefault({}) SystemInfoInterface systeminfo;
     private @NonNullByDefault({}) SystemInfoThingTypeProvider thingTypeProvider;
 
-    private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_COMPUTER,
-            THING_TYPE_COMPUTER_IMPL);
-
     @Override
     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
-        return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
+        return BINDING_ID.equals(thingTypeUID.getBindingId())
+                && thingTypeUID.getId().startsWith(THING_TYPE_COMPUTER_ID);
     }
 
     @Override
     protected @Nullable ThingHandler createHandler(Thing thing) {
-        if (THING_TYPE_COMPUTER.equals(thing.getThingTypeUID())) {
+        ThingTypeUID thingTypeUID = thing.getThingTypeUID();
+        if (supportsThingType(thingTypeUID)) {
             if (thingTypeProvider.getThingType(THING_TYPE_COMPUTER_IMPL, null) == null) {
                 thingTypeProvider.createThingType(THING_TYPE_COMPUTER_IMPL);
                 // Save the current channels configs, will be restored after thing type change.
                 thingTypeProvider.storeChannelsConfig(thing);
             }
             return new SystemInfoHandler(thing, thingTypeProvider, systeminfo);
-        } else if (THING_TYPE_COMPUTER_IMPL.equals(thing.getThingTypeUID())) {
-            return new SystemInfoHandler(thing, thingTypeProvider, systeminfo);
         }
         return null;
     }