Skip to content

Commit

Permalink
strip unit from historic states (openhab#1782)
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Kreuzer <kai@openhab.org>
  • Loading branch information
kaikreuzer committed Nov 1, 2020
1 parent 5683cc2 commit 5a9c5e7
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.List;

import org.openhab.core.library.types.QuantityType;
import org.openhab.core.types.State;

/**
Expand All @@ -40,10 +41,16 @@ public ItemHistoryDTO() {
* @param time the time of the record
* @param state the state at this time
*/
@SuppressWarnings("rawtypes")
public void addData(Long time, State state) {
HistoryDataBean newVal = new HistoryDataBean();
newVal.time = time;
newVal.state = state.toString();
if (state instanceof QuantityType) {
// we strip the unit from the state, since historic item states are expected to be all in the default unit
newVal.state = ((QuantityType) state).toBigDecimal().toString();
} else {
newVal.state = state.toString();
}
data.add(newVal);
}

Expand Down

0 comments on commit 5a9c5e7

Please sign in to comment.