From 321c443aa3078eeae83c770a5b4febd57d8d4c86 Mon Sep 17 00:00:00 2001 From: Mark Hilbush Date: Wed, 30 Dec 2020 16:55:41 -0500 Subject: [PATCH] [persistence] Fix varianceSince and deviationSince (#2036) Signed-off-by: Mark Hilbush --- .../core/persistence/extensions/PersistenceExtensions.java | 1 + .../core/persistence/extensions/PersistenceExtensionsTest.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java index a71611587d4..c0e2168d75c 100644 --- a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java +++ b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/extensions/PersistenceExtensions.java @@ -397,6 +397,7 @@ public static DecimalType varianceSince(Item item, ZonedDateTime timestamp, Stri BigDecimal average = averageSince.toBigDecimal(), sum = BigDecimal.ZERO; int count = 0; + it = result.iterator(); while (it.hasNext()) { HistoricItem historicItem = it.next(); DecimalType value = historicItem.getState().as(DecimalType.class); diff --git a/bundles/org.openhab.core.persistence/src/test/java/org/openhab/core/persistence/extensions/PersistenceExtensionsTest.java b/bundles/org.openhab.core.persistence/src/test/java/org/openhab/core/persistence/extensions/PersistenceExtensionsTest.java index aa55276c279..c153dabe071 100644 --- a/bundles/org.openhab.core.persistence/src/test/java/org/openhab/core/persistence/extensions/PersistenceExtensionsTest.java +++ b/bundles/org.openhab.core.persistence/src/test/java/org/openhab/core/persistence/extensions/PersistenceExtensionsTest.java @@ -236,6 +236,7 @@ public void testMinimumSwitchSince() { assertEquals(OnOffType.ON, historicItem.getState()); } + @Test public void testVarianceSince() { numberItem.setState(new DecimalType(3025)); @@ -262,6 +263,7 @@ public void testVarianceSince() { assertNull(variance); } + @Test public void testDeviationSince() { numberItem.setState(new DecimalType(3025));