Skip to content

Commit

Permalink
docs: Move scriptLoaded/scriptUnloaded hooks under File Based Rules
Browse files Browse the repository at this point in the history
Also:
- title capitalization now reflecting code

Signed-off-by: Sami Salonen <ssalonen@gmail.com>
  • Loading branch information
ssalonen committed May 7, 2022
1 parent 667da08 commit 9f03898
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ binding](https://www.openhab.org/addons/automation/jsscripting/)
- [Require](#require)
- [Console](#console)
- [Timers](#timers)
- [ScriptLoaded](#scriptloaded)
- [ScriptUnLoaded](#scriptunloaded)
- [Paths](#paths)
- [Standard Library](#standard-library)
- [Items](#items)
Expand All @@ -43,6 +41,8 @@ binding](https://www.openhab.org/addons/automation/jsscripting/)
- [JSRule](#jsrule)
- [Rule Builder](#rule-builder)
- [Event Object](#event-object-1)
- [Initialization hook: scriptLoaded](#initialization-hook-scriptloaded)
- [Deinitialization hook: scriptUnloaded](#deinitialization-hook-scriptunloaded)
- [Advanced Scripting](#advanced-scripting)
- [@runtime](#runtime)

Expand Down Expand Up @@ -239,29 +239,6 @@ timer.reschedule(time.ZonedDateTime.now().plusSeconds(2)); // Logs 'Timer expire

See [openHAB JavaDoc - Timer](https://www.openhab.org/javadoc/latest/org/openhab/core/model/script/actions/timer) for full API documentation.

### ScriptLoaded

For file based scripts, this function will be called if found when the script is loaded.

```javascript
scriptLoaded = function () {
console.log("script loaded");
loadedDate = Date.now();
}
```

### ScriptUnLoaded

For file based scripts, this function will be called if found when the script is unloaded.

```javascript
scriptUnloaded = function () {
console.log("script unloaded");
//clean up rouge timers
clearInterval(timer);
}
```

### Paths

For [file based rules](#file-based-rules), scripts will be loaded from `automation/js` in the user configuration directory.
Expand Down Expand Up @@ -834,7 +811,31 @@ All properties are type of String.
You may use [utils.dumpObject(event)](https://openhab.github.io/openhab-js/utils.html#.dumpObject) to get all properties of an `event` object.
### Initialization hook: scriptLoaded
For file based scripts, this function will be called if found when the script is loaded.
```javascript
scriptLoaded = function () {
console.log("script loaded");
loadedDate = Date.now();
}
```
### Deinitialization hook: scriptUnloaded
For file based scripts, this function will be called if found when the script is unloaded.
```javascript
scriptUnloaded = function () {
console.log("script unloaded");
//clean up rouge timers
clearInterval(timer);
}
```
## Advanced Scripting
### @runtime
One can access many useful utilities and types using `require("@runtime")`, e.g.
Expand Down Expand Up @@ -909,4 +910,4 @@ var { ON, OFF, QuantityType } = require("@runtime")
`require("@runtime")` also defines "services" such as `items`, `things`, `rules`, `events`, `actions`, `ir`, `itemRegistry`.
You can use these services for backwards compatibility purposes or ease migration from JSR223 scripts.
Generally speaking, you should prefer to use [Standard Library](#standard-library) provided by this library instead.
Generally speaking, you should prefer to use [Standard Library](#standard-library) provided by this library instead.

0 comments on commit 9f03898

Please sign in to comment.