Skip to content

Commit

Permalink
[rrd4j] Fix unit retrieval for group items (openhab#17054)
Browse files Browse the repository at this point in the history
Reported on the forum

Signed-off-by: Jan N. Klug <github@klug.nrw>
  • Loading branch information
J-N-K authored Jul 14, 2024
1 parent 0e78bd7 commit e735da1
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ public Iterable<HistoricItem> query(FilterCriteria filter) {
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
Expand Down Expand Up @@ -631,11 +634,14 @@ public ConsolFun getConsolidationFunction(RrdDb db) {
}
}

/**
* 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 <Q extends Quantity<Q>> DoubleFunction<State> toStateMapper(@Nullable Item item, @Nullable Unit<Q> 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) {
Expand Down

0 comments on commit e735da1

Please sign in to comment.