Skip to content

Commit

Permalink
[mongodb] Fix handling of GroupItems on restore (openhab#16978)
Browse files Browse the repository at this point in the history
Related to openhab/openhab-core#4257

Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K authored Jul 1, 2024
1 parent 82379f0 commit 701a615
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -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<Item, Document, State> converter = ITEM_STATE_CONVERTERS.get(item.getClass());
Item realItem = item instanceof GroupItem groupItem ? groupItem.getBaseItem() : item;
BiFunction<Item, Document, State> 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());
}
}

Expand Down

0 comments on commit 701a615

Please sign in to comment.