diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-persistence.js b/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-persistence.js
index 73656b674b..2d800898aa 100644
--- a/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-persistence.js
+++ b/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-persistence.js
@@ -16,11 +16,18 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
this.appendDummyInput()
.appendField('get the')
.appendField(new Blockly.FieldDropdown([
- ['state average', 'averageSince'], ['state delta', 'deltaSince'],
- ['state deviation', 'deviationSince'], ['state variance', 'varianceSince'], ['evolution rate', 'evolutionRateSince'],
- ['state minimum', 'minimumSince'], ['state maximum', 'maximumSince'], ['state sum', 'sumSince'],
- ['previous state value', 'previousState'], ['previous state numeric value', 'previousNumericState'], ['previous state value time', 'previousStateTime'],
- ['historic state', 'historicState']
+ ['persisted state', 'persistedState'],
+ ['historic state average', 'averageSince'], ['future state average', 'averageUntil'],
+ ['historic state delta', 'deltaSince'], ['future state delta', 'deltaUntil'],
+ ['historic state deviation', 'deviationSince'], ['future state deviation', 'deviationUntil'],
+ ['historic state variance', 'varianceSince'], ['future state variance', 'varianceUntil'],
+ ['historic evolution rate', 'evolutionRateSince'], ['future evolution rate', 'evolutionRateUntil'],
+ ['historic state minimum', 'minimumSince'], ['future state minimum', 'minimumUntil'],
+ ['historic state maximum', 'maximumSince'], ['future state maximum', 'maximumUntil'],
+ ['historic state sum', 'sumSince'], ['future state sum', 'sumUntil'],
+ ['previous state value', 'previousState'], ['next state value', 'nextState'],
+ ['previous state numeric value', 'previousNumericState'], ['next state numeric value', 'nextNumericState'],
+ ['previous state value time', 'previousStateTime'], ['next state value time', 'nextStateTime']
], this.handleTypeSelection.bind(this)
), 'methodName')
this.methodName = this.getFieldValue('methodName')
@@ -35,23 +42,33 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
this.setInputsInline(false)
this.setOutput(true, null)
this.setColour(0)
- let thisBlock = this
- this.setTooltip(function () {
- let methodName = thisBlock.getFieldValue('methodName')
+ this.setTooltip(() => {
+ let methodName = this.getFieldValue('methodName')
let TIP = {
'averageSince': 'Gets the average value of the State of a persisted Item since a certain point in time. This method uses a time-weighted average calculation',
+ 'averageUntil': 'Gets the average value of the State of a persisted Item until a certain point in time. This method uses a time-weighted average calculation',
'deltaSince': 'Gets the difference in value of the State of a given Item since a certain point in time',
+ 'deltaUntil': 'Gets the difference in value of the State of a given Item until a certain point in time',
'deviationSince': 'Gets the standard deviation of the state of the given Item since a certain point in time',
+ 'deviationUntil': 'Gets the standard deviation of the state of the given Item until a certain point in time',
'varianceSince': 'Gets the variance of the state of the given Item since a certain point in time',
+ 'varianceUntil': 'Gets the variance of the state of the given Item until a certain point in time',
'evolutionRateSince': 'Gets the evolution rate of the state of a given Item since a certain point in time',
+ 'evolutionRateUntil': 'Gets the evolution rate of the state of a given Item until a certain point in time',
'minimumSince': 'Gets the minimum value of the State of a persisted Item since a certain point in time',
+ 'minimumUntil': 'Gets the minimum value of the State of a persisted Item until a certain point in time',
'maximumSince': 'Gets the maximum value of the State of a persisted Item since a certain point in time',
+ 'maximumUntil': 'Gets the maximum value of the State of a persisted Item until a certain point in time',
'sumSince': 'Gets the sum of the previous States of a persisted Item since a certain point in time',
+ 'sumUntil': 'Gets the sum of the previous States of a persisted Item until a certain point in time',
'previousState': 'Gets the previous state with option to skip to different value as current',
+ 'nextState': 'Gets the next state with option to skip to different value as current',
'previousNumericState': 'Gets the previous state without the unit with option to skip to different value as current',
+ 'nextNumericState': 'Gets the next state without the unit with option to skip to different value as current',
'previousStateTime': 'Gets the time when previous state last occurred with option to skip to different value as current',
- 'historicState': 'Gets the historic state at a certain point in time'
+ 'nextStateTime': 'Gets the time when next state will occur with option to skip to different value as current',
+ 'persisted': 'Gets the persisted state at a certain point in time'
}
return TIP[methodName]
})
@@ -68,7 +85,7 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
if (!persistenceNameInput.getShadowDom()) {
persistenceNameInput.setShadowDom(Blockly.utils.xml.textToDom(''))
}
- if (this.methodName === 'previousState' || this.methodName === 'previousNumericState' || this.methodName === 'previousStateTime') {
+ if (['previousState', 'nextState', 'previousNumericState', 'nextNumericState', 'previousStateTime', 'nextStateTime'].includes(this.methodName)) {
if (this.getInput('dayInfo')) {
this.removeInput('dayInfo')
}
@@ -83,7 +100,7 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
this.removeInput('skipPrevious')
}
- const preposition = (this.methodName === 'historicState') ? 'at' : 'since'
+ const preposition = (this.methodName === 'persistedState') ? 'at' : (this.methodName.endsWith('Until') ? 'until' : 'since')
if (!this.getInput('dayInfo')) {
this.appendValueInput('dayInfo')
@@ -121,28 +138,53 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
const persistenceExtension = (persistenceName === '\'default\'') ? '' : `, ${persistenceName}`
switch (methodName) {
+ // Returning JS PersistedItem (GraalJS) or org.openhab.core.persistence.HistoricItem
case 'maximumSince':
+ case 'maximumUntil':
case 'minimumSince':
- case 'historicState':
+ case 'minimumUntil':
+ case 'persistedState':
dayInfo = javascriptGenerator.valueToCode(block, 'dayInfo', javascriptGenerator.ORDER_NONE)
- code = (isGraalJs) ? `${itemCode}.history.${methodName}(${dayInfo}${persistenceExtension})?.state` : `${persistence}.${methodName}(${itemCode}, ${dayInfo}${persistenceExtension}).getState()`
+ code = (isGraalJs) ? `${itemCode}.persistence.${methodName}(${dayInfo}${persistenceExtension})?.state` : `${persistence}.${methodName}(${itemCode}, ${dayInfo}${persistenceExtension}).getState()`
break
case 'previousState':
- code = (isGraalJs) ? `${itemCode}.history.previousState(${skipPrevious}${persistenceExtension})?.state` : `${persistence}.previousState(${itemCode},${skipPrevious}${persistenceExtension}).getState()`
+ case 'nextState':
+ code = (isGraalJs) ? `${itemCode}.persistence.${methodName}(${skipPrevious}${persistenceExtension})?.state` : `${persistence}.${methodName}(${itemCode},${skipPrevious}${persistenceExtension}).getState()`
break
case 'previousNumericState':
- code = (isGraalJs) ? `${itemCode}.history.previousState(${skipPrevious}${persistenceExtension})?.numericState` : `${persistence}.previousState(${itemCode},${skipPrevious}${persistenceExtension}).getNumericState()`
+ code = (isGraalJs) ? `${itemCode}.persistence.previousState(${skipPrevious}${persistenceExtension})?.numericState` : `${persistence}.previousState(${itemCode},${skipPrevious}${persistenceExtension}).getNumericState()`
+ break
+ case 'nextNumericState':
+ code = (isGraalJs) ? `${itemCode}.persistence.nextState(${skipPrevious}${persistenceExtension})?.numericState` : `${persistence}.nextState(${itemCode},${skipPrevious}${persistenceExtension}).getNumericState()`
break
case 'previousStateTime':
- code = (isGraalJs) ? `${itemCode}.history.previousState(${skipPrevious}${persistenceExtension})?.timestamp` : `${persistence}.previousState(${itemCode},${skipPrevious}${persistenceExtension}).getTimestamp()`
+ code = (isGraalJs) ? `${itemCode}.persistence.previousState(${skipPrevious}${persistenceExtension})?.timestamp` : `${persistence}.previousState(${itemCode},${skipPrevious}${persistenceExtension}).getTimestamp()`
+ break
+ case 'nextStateTime':
+ code = (isGraalJs) ? `${itemCode}.persistence.nextState(${skipPrevious}${persistenceExtension})?.timestamp` : `${persistence}.nextState(${itemCode},${skipPrevious}${persistenceExtension}).getTimestamp()`
+ break
+
+ // Returning JS PersistedState (GraalJS) or org.openhab.core.types.State
+ case 'averageSince':
+ case 'averageUntil':
+ case 'deltaSince':
+ case 'deltaUntil':
+ case 'deviationSince':
+ case 'deviationUntil':
+ case 'sumSince':
+ case 'sumUntil':
+ case 'varianceSince':
+ case 'varianceUntil':
+ dayInfo = javascriptGenerator.valueToCode(block, 'dayInfo', javascriptGenerator.ORDER_NONE)
+ code = (isGraalJs) ? `${itemCode}.persistence.${methodName}(${dayInfo}${persistenceExtension})?.numericState` : `parseFloat(${persistence}.${methodName}(${itemCode}, ${dayInfo}${persistenceExtension}).getState())`
break
default:
dayInfo = javascriptGenerator.valueToCode(block, 'dayInfo', javascriptGenerator.ORDER_NONE)
- code = (isGraalJs) ? `${itemCode}.history.${methodName}(${dayInfo}${persistenceExtension})` : `${persistence}.${methodName}(${itemCode}, ${dayInfo}${persistenceExtension})`
+ code = (isGraalJs) ? `${itemCode}.persistence.${methodName}(${dayInfo}${persistenceExtension})` : `${persistence}.${methodName}(${itemCode}, ${dayInfo}${persistenceExtension})`
break
}
@@ -166,7 +208,7 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
persistenceNameInput.setShadowDom(Blockly.utils.xml.textToDom(''))
}
this.appendValueInput('dayInfo')
- .appendField(new Blockly.FieldDropdown([['has changed since', 'changedSince'], ['has been updated since', 'updatedSince']]), 'methodName')
+ .appendField(new Blockly.FieldDropdown([['has changed since', 'changedSince'], ['will have changed until', 'changedUntil'], ['has been updated since', 'updatedSince'], ['will have been updated until', 'updatedUntil']]), 'methodName')
.setAlign(Blockly.ALIGN_RIGHT)
.setCheck(['ZonedDateTime'])
@@ -179,7 +221,9 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
let methodName = thisBlock.getFieldValue('methodName')
let TIP = {
'changedSince': 'Checks if the State of the Item has (ever) changed since a certain point in time',
- 'updatedSince': 'Checks if the State of the Item has been updated since a certain point in time'
+ 'changedUntil': 'Checks if the State of the Item will have (ever) changed until a certain point in time',
+ 'updatedSince': 'Checks if the State of the Item has been updated since a certain point in time',
+ 'updatedUntil': 'Checks if the State of the Item will have been updated until a certain point in time'
}
return TIP[methodName]
})
@@ -194,19 +238,17 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
*/
javascriptGenerator.forBlock['oh_persist_changed'] = function (block) {
const itemName = javascriptGenerator.valueToCode(block, 'itemName', javascriptGenerator.ORDER_ATOMIC)
-
const inputType = blockGetCheckedInputType(block, 'itemName')
- let itemCode = generateItemCode(itemName, inputType)
-
const methodName = block.getFieldValue('methodName')
const dayInfo = javascriptGenerator.valueToCode(block, 'dayInfo', javascriptGenerator.ORDER_NONE)
-
const persistenceName = javascriptGenerator.valueToCode(block, 'persistenceName', javascriptGenerator.ORDER_NONE)
const persistenceExtension = (persistenceName === '\'default\'') ? '' : `, ${persistenceName}`
+ let itemCode = generateItemCode(itemName, inputType)
+
if (isGraalJs) {
- return [`${itemCode}.history.${methodName}(${dayInfo}${persistenceExtension})`, javascriptGenerator.ORDER_NONE]
+ return [`${itemCode}.persistence.${methodName}(${dayInfo}${persistenceExtension})`, javascriptGenerator.ORDER_NONE]
} else {
const { dtf, zdt, getZonedDatetime } = addDateSupport()
const persistence = addPersistence()
@@ -221,7 +263,11 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
Blockly.Blocks['oh_get_persistence_lastupdate'] = {
init: function () {
this.appendDummyInput()
- .appendField('last updated date of')
+ .appendField(new Blockly.FieldDropdown([
+ ['last', 'lastUpdate'], ['next', 'nextUpdate']
+ ]), 'methodName')
+ this.appendDummyInput()
+ .appendField(' updated date of')
this.appendValueInput('itemName')
.setCheck(['String', 'oh_item', 'oh_itemtype'])
const persistenceNameInput = this.appendValueInput('persistenceName')
@@ -234,8 +280,16 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
this.setInputsInline(true)
this.setOutput(true, 'ZonedDateTime')
this.setColour(0)
- this.setTooltip('Get the last update time of the provided item')
this.setHelpUrl('https://www.openhab.org/docs/configuration/blockly/rules-blockly-persistence.html#provide-last-updated-date-of-an-item')
+
+ this.setTooltip(() => {
+ const methodName = this.getFieldValue('methodName')
+ const TIP = {
+ 'lastUpdate': 'Get the last update time of the provided item',
+ 'nextUpdate': 'Get the next update time of the provided item'
+ }
+ return TIP[methodName]
+ })
}
}
@@ -244,6 +298,7 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
* Code part
*/
javascriptGenerator.forBlock['oh_get_persistence_lastupdate'] = function (block) {
+ const methodName = block.getFieldValue('methodName')
const itemName = javascriptGenerator.valueToCode(block, 'itemName', javascriptGenerator.ORDER_ATOMIC)
const inputType = blockGetCheckedInputType(block, 'itemName')
const persistenceName = javascriptGenerator.valueToCode(block, 'persistenceName', javascriptGenerator.ORDER_NONE)
@@ -252,11 +307,11 @@ export default function defineOHBlocks_Persistence (f7, isGraalJs, persistenceSe
let itemCode = generateItemCode(itemName, inputType)
if (isGraalJs) {
- return [`${itemCode}.history.lastUpdate(${persistenceExtension})`, 0]
+ return [`${itemCode}.persistence.${methodName}(${persistenceExtension})`, 0]
} else {
const { dtf, zdt, getZonedDatetime } = addDateSupport()
const persistence = addPersistence()
- let code = `${persistence}.lastUpdate(${itemCode}${persistenceExtension})`
+ let code = `${persistence}.${methodName}(${itemCode}${persistenceExtension})`
return [code, 0]
}
}