-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from florian-h05/name-timers
Allow passing names to created timers
- Loading branch information
Showing
8 changed files
with
98 additions
and
23 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
.vscode | ||
.vscode | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { actions, time } = require('openhab'); | ||
|
||
/** | ||
* Utility function to create a named timer. | ||
* | ||
* The name can be set with the name parameter or is autogenerated from the ruleUID (for UI) or filename and the timer's key (if available). | ||
* | ||
* @param {*} when any representation of time or duration, see {@link https://openhab.github.io/openhab-js/time.html#.toZDT time.toZDT} | ||
* @param {function} func function to call when the timer expires | ||
* @param {*} [arg] argument to pass to the timer | ||
* @param {string} [name] name for the timer | ||
* @param {string} [key] key of the timer to append to the generated name | ||
* @returns openHAB Java {@link https://www.openhab.org/javadoc/latest/org/openhab/core/model/script/actions/timer Timer} | ||
*/ | ||
const createTimer = (when, func, arg, name, key) => { | ||
const timeout = time.toZDT(when); | ||
if (name === null || name === undefined) { | ||
if (global.ruleUID !== undefined) { // Use UI ruleUID and key if available | ||
name = 'ui.' + global.ruleUID + ((key !== undefined) ? '.' + key : ''); | ||
} else if (global['javax.script.filename'] !== undefined) { // Use filename and key if available | ||
name = 'file.' + global['javax.script.filename'].replace(/^.*[\\/]/, '') + ((key !== undefined) ? '.' + key : ''); | ||
} | ||
} | ||
return actions.ScriptExecution.createTimerWithArgument(name, timeout, arg, func); | ||
}; | ||
|
||
module.exports = { | ||
createTimer | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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