|
74 | 74 | import org.openhab.core.service.StartLevelService; |
75 | 75 | import org.openhab.core.types.State; |
76 | 76 | import org.openhab.core.types.TimeSeries; |
| 77 | +import org.openhab.core.types.TimeSeries.Entry; |
77 | 78 | import org.openhab.core.types.UnDefType; |
78 | 79 | import org.osgi.service.component.annotations.Activate; |
79 | 80 | import org.osgi.service.component.annotations.Component; |
@@ -339,6 +340,7 @@ public void timeSeriesUpdated(Item item, TimeSeries timeSeries) { |
339 | 340 | // discard empty time series |
340 | 341 | return; |
341 | 342 | } |
| 343 | + |
342 | 344 | persistenceServiceContainers.values().stream() |
343 | 345 | .filter(psc -> psc.persistenceService instanceof ModifiablePersistenceService) |
344 | 346 | .forEach(container -> Stream |
@@ -375,6 +377,33 @@ public void timeSeriesUpdated(Item item, TimeSeries timeSeries) { |
375 | 377 | } |
376 | 378 | }); |
377 | 379 | })); |
| 380 | + |
| 381 | + State state = item.getState(); |
| 382 | + if (UnDefType.NULL.equals(state)) { |
| 383 | + Iterator<Entry> iter = timeSeries.getStates().iterator(); |
| 384 | + Instant entryTs = null; |
| 385 | + State entryState = null; |
| 386 | + Instant now = Instant.now(); |
| 387 | + boolean endLoop = false; |
| 388 | + |
| 389 | + while (!endLoop && iter.hasNext()) { |
| 390 | + Entry entry = iter.next(); |
| 391 | + if (entry.timestamp().isBefore(now)) { |
| 392 | + entryTs = entry.timestamp(); |
| 393 | + entryState = entry.state(); |
| 394 | + } else { |
| 395 | + endLoop = true; |
| 396 | + } |
| 397 | + } |
| 398 | + |
| 399 | + GenericItem genericItem = (GenericItem) item; |
| 400 | + if (entryState != null) { |
| 401 | + ZonedDateTime zdt = entryTs.atZone(ZoneId.systemDefault()); |
| 402 | + genericItem.removeStateChangeListener(PersistenceManagerImpl.this); |
| 403 | + genericItem.setState(entryState, null, zdt, null); |
| 404 | + genericItem.addStateChangeListener(PersistenceManagerImpl.this); |
| 405 | + } |
| 406 | + } |
378 | 407 | } |
379 | 408 |
|
380 | 409 | @Override |
|
0 commit comments