From 98ee2e31f93fd5ee083945dec09367d8752be7ab Mon Sep 17 00:00:00 2001 From: J-N-K Date: Sun, 14 Jul 2024 12:18:06 +0200 Subject: [PATCH] [rrd4j] Fix unit retrieval for group items (#17054) Reported on the forum Signed-off-by: Jan N. Klug Signed-off-by: Ciprian Pascu --- .../rrd4j/internal/RRD4jPersistenceService.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java index 3d8abb48ba3..ed3d3d10d91 100644 --- a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java +++ b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java @@ -443,6 +443,9 @@ public class RRD4jPersistenceService implements QueryablePersistenceService { Unit unit = null; try { item = itemRegistry.getItem(itemName); + if (item instanceof GroupItem groupItem) { + item = groupItem.getBaseItem(); + } if (item instanceof NumberItem numberItem) { // we already retrieve the unit here once as it is a very costly operation, // see https://github.com/openhab/openhab-addons/issues/8928 @@ -631,11 +634,14 @@ public class RRD4jPersistenceService implements QueryablePersistenceService { } } + /** + * Get the state Mapper for a given item + * + * @param item the item (in case of a group item, the base item has to be supplied) + * @param unit the unit to use + * @return the state mapper + */ private > DoubleFunction toStateMapper(@Nullable Item item, @Nullable Unit unit) { - if (item instanceof GroupItem groupItem) { - item = groupItem.getBaseItem(); - } - if (item instanceof SwitchItem && !(item instanceof DimmerItem)) { return (value) -> OnOffType.from(value != 0.0d); } else if (item instanceof ContactItem) {