strip unit from historic states (#1782)

Signed-off-by: Kai Kreuzer <kai@openhab.org>
pull/1789/head
Kai Kreuzer 2020-11-01 01:53:02 +01:00 committed by GitHub
parent 5683cc2472
commit 5a9c5e7d87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -15,6 +15,7 @@ package org.openhab.core.persistence.dto;
import java.util.ArrayList;
import java.util.List;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.types.State;
/**
@ -40,10 +41,16 @@ public class 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);
}