From 3597f55bbd227d724aa28d3845c67ba4926fddfa Mon Sep 17 00:00:00 2001 From: Mark Herwege Date: Mon, 1 Jul 2024 13:55:32 +0200 Subject: [PATCH] fix startup (#16971) Signed-off-by: Mark Herwege Signed-off-by: Ciprian Pascu --- .../internal/SystemInfoBindingConstants.java | 6 ++++-- .../internal/SystemInfoHandlerFactory.java | 13 ++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SystemInfoBindingConstants.java b/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SystemInfoBindingConstants.java index 5563c66fb01..ea3beab5e59 100644 --- a/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SystemInfoBindingConstants.java +++ b/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SystemInfoBindingConstants.java @@ -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 /** diff --git a/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SystemInfoHandlerFactory.java b/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SystemInfoHandlerFactory.java index 7f92c8d5bdc..3fa5e00a1df 100644 --- a/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SystemInfoHandlerFactory.java +++ b/bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SystemInfoHandlerFactory.java @@ -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 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; }