Skip to content

Commit 701a615

Browse files
authored
[mongodb] Fix handling of GroupItems on restore (openhab#16978)
Related to openhab/openhab-core#4257 Signed-off-by: Jan N. Klug <[email protected]>
1 parent 82379f0 commit 701a615

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

bundles/org.openhab.persistence.mongodb/src/main/java/org/openhab/persistence/mongodb/internal/MongoDBTypeConversions.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.eclipse.jdt.annotation.NonNullByDefault;
2727
import org.eclipse.jdt.annotation.Nullable;
2828
import org.openhab.core.items.GenericItem;
29+
import org.openhab.core.items.GroupItem;
2930
import org.openhab.core.items.Item;
3031
import org.openhab.core.library.items.CallItem;
3132
import org.openhab.core.library.items.ColorItem;
@@ -77,11 +78,12 @@ public class MongoDBTypeConversions {
7778
* @throws IllegalArgumentException If the item type is not supported.
7879
*/
7980
public static State getStateFromDocument(Item item, Document doc) {
80-
BiFunction<Item, Document, State> converter = ITEM_STATE_CONVERTERS.get(item.getClass());
81+
Item realItem = item instanceof GroupItem groupItem ? groupItem.getBaseItem() : item;
82+
BiFunction<Item, Document, State> converter = ITEM_STATE_CONVERTERS.get(realItem.getClass());
8183
if (converter != null) {
82-
return converter.apply(item, doc);
84+
return converter.apply(realItem, doc);
8385
} else {
84-
throw new IllegalArgumentException("Unsupported item type: " + item.getClass().getName());
86+
throw new IllegalArgumentException("Unsupported item type: " + realItem.getClass().getName());
8587
}
8688
}
8789

0 commit comments

Comments
 (0)