Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rrd4j] Fix unit retrieval for group items #17054

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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