Reduce redundant persistence of tariffs (#16222)

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Jacob Laursen 2024-01-07 11:30:20 +01:00 committed by Ciprian Pascu
parent 6d36fa92e3
commit 6f58845767

View File

@ -381,6 +381,7 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
private void updateTimeSeries() {
TimeSeries spotPriceTimeSeries = new TimeSeries(REPLACE);
Map<DatahubTariff, TimeSeries> datahubTimeSeriesMap = new HashMap<>();
Map<DatahubTariff, BigDecimal> 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);
}
}
}