-
-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persistence restore lastState and lastStateChange on startup #4463
Open
mherwege
wants to merge
2
commits into
openhab:main
Choose a base branch
from
mherwege:persistence_last_adjustments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+333
−50
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...rg.openhab.core.persistence/src/main/java/org/openhab/core/persistence/PersistedItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) 2010-2024 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.persistence; | ||
|
||
import java.time.Instant; | ||
import java.time.ZonedDateTime; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.types.State; | ||
|
||
/** | ||
* This interface is used by persistence services to represent the full persisted state of an item, including the | ||
* previous state, and last update and change timestamps. | ||
* It can be used in restoring the full state of an item. | ||
* | ||
* @author Mark Herwege - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public interface PersistedItem extends HistoricItem { | ||
|
||
/** | ||
* returns the timestamp of the last state change of the persisted item | ||
* | ||
* @return the timestamp of the last state change of the item | ||
*/ | ||
@Nullable | ||
ZonedDateTime getLastStateChange(); | ||
|
||
/** | ||
* returns the timestamp of the last state change of the persisted item | ||
* | ||
* @return the timestamp of the last state change of the item | ||
*/ | ||
@Nullable | ||
default Instant getLastStateChangeInstant() { | ||
ZonedDateTime lastStateChange = getLastStateChange(); | ||
return lastStateChange != null ? lastStateChange.toInstant() : null; | ||
} | ||
|
||
/** | ||
* returns the last state of the item | ||
* | ||
* @return the last state | ||
*/ | ||
@Nullable | ||
State getLastState(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not done before querying the persistence service?
It seems that we could've avoided running the query unnecessarily if the state was already initialised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, as the query runs in a separate thread, the item state may have changed in between starting the query and returning the result.
@J-N-K introduced this. I didn't find more explanation for it, but this was my interpretation. So I think it should remain there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, but I think it would also make sense to check it beforehand as well.
But perhaps if that were the case, such change could be added later, and separately from this PR.