From 701a6159d7a8968a79e94bad6476a8758ecad85b Mon Sep 17 00:00:00 2001 From: J-N-K Date: Mon, 1 Jul 2024 23:26:58 +0200 Subject: [PATCH] [mongodb] Fix handling of GroupItems on restore (#16978) Related to https://github.com/openhab/openhab-core/pull/4257 Signed-off-by: Jan N. Klug --- .../mongodb/internal/MongoDBTypeConversions.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.persistence.mongodb/src/main/java/org/openhab/persistence/mongodb/internal/MongoDBTypeConversions.java b/bundles/org.openhab.persistence.mongodb/src/main/java/org/openhab/persistence/mongodb/internal/MongoDBTypeConversions.java index eb189861058..eaca9697b6b 100644 --- a/bundles/org.openhab.persistence.mongodb/src/main/java/org/openhab/persistence/mongodb/internal/MongoDBTypeConversions.java +++ b/bundles/org.openhab.persistence.mongodb/src/main/java/org/openhab/persistence/mongodb/internal/MongoDBTypeConversions.java @@ -26,6 +26,7 @@ import org.bson.types.Binary; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.items.GenericItem; +import org.openhab.core.items.GroupItem; import org.openhab.core.items.Item; import org.openhab.core.library.items.CallItem; import org.openhab.core.library.items.ColorItem; @@ -77,11 +78,12 @@ public class MongoDBTypeConversions { * @throws IllegalArgumentException If the item type is not supported. */ public static State getStateFromDocument(Item item, Document doc) { - BiFunction converter = ITEM_STATE_CONVERTERS.get(item.getClass()); + Item realItem = item instanceof GroupItem groupItem ? groupItem.getBaseItem() : item; + BiFunction converter = ITEM_STATE_CONVERTERS.get(realItem.getClass()); if (converter != null) { - return converter.apply(item, doc); + return converter.apply(realItem, doc); } else { - throw new IllegalArgumentException("Unsupported item type: " + item.getClass().getName()); + throw new IllegalArgumentException("Unsupported item type: " + realItem.getClass().getName()); } }