From d72e9164a7fa149fdee6612cb32ba8af5d9bc5a2 Mon Sep 17 00:00:00 2001 From: Yannick Schaus Date: Fri, 17 Dec 2021 01:29:25 +0100 Subject: [PATCH] Fix Blockly timer code (#1236) Fix #1214. Signed-off-by: Yannick Schaus --- .../web/src/assets/definitions/blockly/blocks-timers.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-timers.js b/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-timers.js index ed357dd9a..d3c6176be 100644 --- a/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-timers.js +++ b/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-timers.js @@ -78,10 +78,9 @@ export default function defineOHBlocks_Timers (f7) { let timerName = Blockly.JavaScript.valueToCode(block, 'timerName', Blockly.JavaScript.ORDER_ATOMIC) let timerCode = Blockly.JavaScript.statementToCode(block, 'timerCode') - let code = `if (typeof this.timers[${timerName}] === 'undefined') {\n` + let code = `if (typeof this.timers[${timerName}] === 'undefined' || this.timers[${timerName}].hasTerminated()) {\n` code += ` this.timers[${timerName}] = ${scriptExecution}.createTimer(${zdt}.now().${delayunits}(${delay}), function () {\n` code += timerCode.replace(/^/gm, ' ') - code += ` this.timers[${timerName}] = undefined;\n` code += ' })\n' code += '}\n' return code @@ -130,15 +129,14 @@ export default function defineOHBlocks_Timers (f7) { let retrigger = block.getFieldValue('retrigger') let timerCode = Blockly.JavaScript.statementToCode(block, 'timerCode') - let code = `if (typeof this.timers[${timerName}] === 'undefined') {\n` + let code = `if (typeof this.timers[${timerName}] === 'undefined' || this.timers[${timerName}].hasTerminated()) {\n` code += ` this.timers[${timerName}] = ${scriptExecution}.createTimer(${zdt}.now().${delayUnits}(${delay}), function () {\n` code += timerCode.replace(/^/gm, ' ') - code += ` this.timers[${timerName}] = undefined;\n` code += ' })\n' code += '} else {\n' switch (retrigger) { case 'reschedule': - code += ` this.timers[${timerName}].reschedule(zonedDateTime.now().${delayUnits}(${delay}));\n` + code += ` this.timers[${timerName}].reschedule(${zdt}.now().${delayUnits}(${delay}));\n` break case 'cancel':