Fix TimeSeries policy REPLACE not being applied (#4298)

Fixes #4297

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-07-06 20:38:20 +02:00 committed by GitHub
parent 87ad314c02
commit 340996f971
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -218,6 +218,10 @@ public class PersistenceExtensions {
TimeZoneProvider tzProvider = timeZoneProvider;
ZoneId timeZone = tzProvider != null ? tzProvider.getTimeZone() : ZoneId.systemDefault();
if (service instanceof ModifiablePersistenceService modifiableService) {
if (timeSeries.getPolicy() == TimeSeries.Policy.REPLACE) {
internalRemoveAllStatesBetween(item, timeSeries.getBegin().atZone(timeZone),
timeSeries.getEnd().atZone(timeZone), serviceId);
}
timeSeries.getStates()
.forEach(s -> modifiableService.store(item, s.timestamp().atZone(timeZone), s.state()));
return;