Reduce redundant persistence of tariffs (#16222)

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-01-07 11:30:20 +01:00 committed by Kai Kreuzer
parent 4d94db0587
commit 6633cd7668

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);
}
}
}