Skip to content

Commit cb2033f

Browse files
committed
simplify
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
1 parent 8d90658 commit cb2033f

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/internal/PersistenceManagerImpl.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public void timeSeriesUpdated(Item item, TimeSeries timeSeries) {
389389
ScheduledCompletableFuture<?> forecastJob = container.forecastJobs.get(item.getName());
390390
if (forecastJob == null || forecastJob.getScheduledTime()
391391
.isAfter(s.timestamp().atZone(ZoneId.systemDefault()))) {
392-
container.scheduleNextForecastForItem(item.getName(), s.timestamp(), s.state());
392+
container.scheduleNextForecastForItem(item, s.timestamp(), s.state());
393393
}
394394
});
395395
// update current item state if last entry in timeseries is after last update of item
@@ -637,13 +637,15 @@ private void restoreItemStateIfPossible(Item item) {
637637
return persistedItem;
638638
}
639639

640-
public void scheduleNextForecastForItem(String itemName, Instant time, State state) {
640+
public void scheduleNextForecastForItem(Item item, Instant time, State state) {
641+
String itemName = item.getName();
641642
ScheduledFuture<?> oldJob = forecastJobs.remove(itemName);
642643
if (oldJob != null) {
643644
oldJob.cancel(true);
644645
}
645-
forecastJobs.put(itemName, scheduler.at(() -> restoreItemState(itemName, state), time));
646-
logger.trace("Scheduled forecasted value for {} at {}", itemName, time);
646+
forecastJobs.put(itemName,
647+
scheduler.at(() -> restoreItemState(item, time.atZone(ZoneId.systemDefault()), state), time));
648+
logger.trace("Scheduled forecasted value for {} at {}", item.getName(), time);
647649
}
648650

649651
public void scheduleNextPersistedForecastForItem(String itemName) {
@@ -663,20 +665,13 @@ public void scheduleNextPersistedForecastForItem(String itemName) {
663665
HistoricItem next = result.next();
664666
Instant timestamp = next.getInstant();
665667
if (timestamp.isAfter(Instant.now())) {
666-
scheduleNextForecastForItem(itemName, timestamp, next.getState());
668+
scheduleNextForecastForItem(item, timestamp, next.getState());
667669
break;
668670
}
669671
}
670672
}
671673
}
672674

673-
private void restoreItemState(String itemName, State state) {
674-
Item item = itemRegistry.get(itemName);
675-
if (item != null) {
676-
restoreItemState(item, ZonedDateTime.now(), state);
677-
}
678-
}
679-
680675
private void restoreItemState(Item item, ZonedDateTime timestamp, State state) {
681676
PersistedItem persistedItem = new PersistedItem() {
682677

0 commit comments

Comments
 (0)