mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Reduce redundant persistence of tariffs (#16222)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
4d94db0587
commit
6633cd7668
@ -381,6 +381,7 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
|
|||||||
private void updateTimeSeries() {
|
private void updateTimeSeries() {
|
||||||
TimeSeries spotPriceTimeSeries = new TimeSeries(REPLACE);
|
TimeSeries spotPriceTimeSeries = new TimeSeries(REPLACE);
|
||||||
Map<DatahubTariff, TimeSeries> datahubTimeSeriesMap = new HashMap<>();
|
Map<DatahubTariff, TimeSeries> datahubTimeSeriesMap = new HashMap<>();
|
||||||
|
Map<DatahubTariff, BigDecimal> datahubPreviousTariff = new HashMap<>();
|
||||||
for (DatahubTariff datahubTariff : DatahubTariff.values()) {
|
for (DatahubTariff datahubTariff : DatahubTariff.values()) {
|
||||||
datahubTimeSeriesMap.put(datahubTariff, new TimeSeries(REPLACE));
|
datahubTimeSeriesMap.put(datahubTariff, new TimeSeries(REPLACE));
|
||||||
}
|
}
|
||||||
@ -401,8 +402,14 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
|
|||||||
}
|
}
|
||||||
BigDecimal tariff = cacheManager.getTariff(datahubTariff, hourStart);
|
BigDecimal tariff = cacheManager.getTariff(datahubTariff, hourStart);
|
||||||
if (tariff != null) {
|
if (tariff != null) {
|
||||||
|
BigDecimal previousTariff = datahubPreviousTariff.get(datahubTariff);
|
||||||
|
if (previousTariff != null && tariff.equals(previousTariff)) {
|
||||||
|
// Skip redundant states.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
TimeSeries timeSeries = entry.getValue();
|
TimeSeries timeSeries = entry.getValue();
|
||||||
timeSeries.add(hourStart, getEnergyPrice(tariff, CURRENCY_DKK));
|
timeSeries.add(hourStart, getEnergyPrice(tariff, CURRENCY_DKK));
|
||||||
|
datahubPreviousTariff.put(datahubTariff, tariff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user