Skip to content

Commit

Permalink
[items] ItemPersistence: Add lastChange and nextChange methods (#350)
Browse files Browse the repository at this point in the history
Adds support for openhab/openhab-core#4259.

Also-by: Florian Hotze <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
  • Loading branch information
mherwege authored Jun 25, 2024
1 parent 7c4f5d0 commit a94e9fe
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,9 @@ Calling `Item.persistence` returns an `ItemPersistence` object with the followin
- .getAllStatesUntil(timestamp, serviceId) ⇒ `Array[PersistedItem]`
- .getAllStatesBetween(begin, end, serviceId) ⇒ `Array[PersistedItem]`
- .lastUpdate(serviceId) ⇒ `ZonedDateTime | null`
- .nextUpdate(serviceId) ⇒ `ZonedDateTime | null`
- .nextUpdate(serviceId) ⇒ `ZonedDateTime | null`
- .lastChange(serviceId) ⇒ `ZonedDateTime | null`
- .nextChange(serviceId) ⇒ `ZonedDateTime | null`
- .maximumSince(timestamp, serviceId) ⇒ `PersistedItem | null`
- .maximumUntil(timestamp, serviceId) ⇒ `PersistedItem | null`
- .maximumBetween(begin, end, serviceId) ⇒ `PersistedItem | null`
Expand Down
26 changes: 24 additions & 2 deletions src/items/item-persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,9 @@ class ItemPersistence {
* Query the last update time of a given Item.
*
* @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
* @returns {(time.ZonedDateTime | null)} point in time of the last historic update to Item, or <code>null</code> if there are no historic persisted updates
*/
* @returns {(time.ZonedDateTime | null)} point in time of the last historic update to Item, or <code>null</code>
if the current state is different from the last persisted state or there are no historic persisted updates
*/
lastUpdate (serviceId) {
return _ZDTOrNull(PersistenceExtensions.lastUpdate(this.rawItem, ...arguments));
}
Expand All @@ -291,6 +292,27 @@ class ItemPersistence {
return _ZDTOrNull(PersistenceExtensions.nextUpdate(this.rawItem, ...arguments));
}

/**
* Query the last change time of a given Item.
*
* @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
* @returns {(time.ZonedDateTime | null)} point in time of the last historic change to Item, or <code>null</code>
if the current state is different from the last persisted state or there are no historic persisted states
*/
lastChange (serviceId) {
return _ZDTOrNull(PersistenceExtensions.lastChange(this.rawItem, ...arguments));
}

/**
* Query the next change time of a given Item.
*
* @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
* @returns {(time.ZonedDateTime | null)} point in time of the first future change to Item, or <code>null</code> if there are no future persisted states
*/
nextChange (serviceId) {
return _ZDTOrNull(PersistenceExtensions.nextChange(this.rawItem, ...arguments));
}

/**
* Returns the previous state of a given Item.
*
Expand Down
20 changes: 18 additions & 2 deletions types/items/item-persistence.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ declare class ItemPersistence {
* Query the last update time of a given Item.
*
* @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
* @returns {(time.ZonedDateTime | null)} point in time of the last historic update to Item, or <code>null</code> if there are no historic persisted updates
*/
* @returns {(time.ZonedDateTime | null)} point in time of the last historic update to Item, or <code>null</code>
if the current state is different from the last persisted state or there are no historic persisted updates
*/
lastUpdate(serviceId?: string, ...args: any[]): (time.ZonedDateTime | null);
/**
* Query the next update time of a given Item.
Expand All @@ -69,6 +70,21 @@ declare class ItemPersistence {
* @returns {(time.ZonedDateTime | null)} point in time of the first future update to Item, or <code>null</code> if there are no future persisted updates
*/
nextUpdate(serviceId?: string, ...args: any[]): (time.ZonedDateTime | null);
/**
* Query the last change time of a given Item.
*
* @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
* @returns {(time.ZonedDateTime | null)} point in time of the last historic change to Item, or <code>null</code>
if the current state is different from the last persisted state or there are no historic persisted states
*/
lastChange(serviceId?: string, ...args: any[]): (time.ZonedDateTime | null);
/**
* Query the next change time of a given Item.
*
* @param {string} [serviceId] optional persistence service ID, if omitted, the default persistence service will be used
* @returns {(time.ZonedDateTime | null)} point in time of the first future change to Item, or <code>null</code> if there are no future persisted states
*/
nextChange(serviceId?: string, ...args: any[]): (time.ZonedDateTime | null);
/**
* Returns the previous state of a given Item.
*
Expand Down
2 changes: 1 addition & 1 deletion types/items/item-persistence.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a94e9fe

Please sign in to comment.