From 3507b77ca9f944c00434d8bf96cb5ce5d1cd97bc Mon Sep 17 00:00:00 2001 From: joerg1985 <16140691+joerg1985@users.noreply.github.com> Date: Thu, 8 Feb 2024 07:49:03 +0100 Subject: [PATCH] [rrd4j] Reuse the state for identical values (#16379) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörg Sautter Signed-off-by: Ciprian Pascu --- .../rrd4j/internal/RRD4jPersistenceService.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 0fedb56922f..c8ee865a1cd 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 @@ -491,9 +491,21 @@ public class RRD4jPersistenceService implements QueryablePersistenceService { long ts = result.getFirstTimestamp(); ZonedDateTime zdt = ZonedDateTime.ofInstant(Instant.ofEpochSecond(ts), ZoneId.systemDefault()); long step = result.getRowCount() > 1 ? result.getStep() : 0; + + double prevValue = Double.NaN; + State prevState = null; for (double value : result.getValues(DATASOURCE_STATE)) { if (!Double.isNaN(value) && (((ts >= start) && (ts <= end)) || (start == end))) { - RRD4jItem rrd4jItem = new RRD4jItem(itemName, toState.apply(value), zdt); + State state; + + if (prevValue == value) { + state = prevState; + } else { + prevState = state = toState.apply(value); + prevValue = value; + } + + RRD4jItem rrd4jItem = new RRD4jItem(itemName, state, zdt); items.add(rrd4jItem); } zdt = zdt.plusSeconds(step);