From 6633cd76687f74b25030759a6ce9d614db13463b Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Sun, 7 Jan 2024 11:30:20 +0100 Subject: [PATCH] Reduce redundant persistence of tariffs (#16222) Signed-off-by: Jacob Laursen --- .../internal/handler/EnergiDataServiceHandler.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/handler/EnergiDataServiceHandler.java b/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/handler/EnergiDataServiceHandler.java index 3386ecd52e5..b1fc9fdf433 100644 --- a/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/handler/EnergiDataServiceHandler.java +++ b/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/handler/EnergiDataServiceHandler.java @@ -381,6 +381,7 @@ public class EnergiDataServiceHandler extends BaseThingHandler { private void updateTimeSeries() { TimeSeries spotPriceTimeSeries = new TimeSeries(REPLACE); Map datahubTimeSeriesMap = new HashMap<>(); + Map datahubPreviousTariff = new HashMap<>(); for (DatahubTariff datahubTariff : DatahubTariff.values()) { datahubTimeSeriesMap.put(datahubTariff, new TimeSeries(REPLACE)); } @@ -401,8 +402,14 @@ public class EnergiDataServiceHandler extends BaseThingHandler { } BigDecimal tariff = cacheManager.getTariff(datahubTariff, hourStart); if (tariff != null) { + BigDecimal previousTariff = datahubPreviousTariff.get(datahubTariff); + if (previousTariff != null && tariff.equals(previousTariff)) { + // Skip redundant states. + continue; + } TimeSeries timeSeries = entry.getValue(); timeSeries.add(hourStart, getEnergyPrice(tariff, CURRENCY_DKK)); + datahubPreviousTariff.put(datahubTariff, tariff); } } }