Skip to content

Commit

Permalink
[jsscripting] Upgrade to openhab-js 5.3.1 (#16985)
Browse files Browse the repository at this point in the history
Depends on #16979.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
  • Loading branch information
florian-h05 authored Jul 4, 2024
1 parent 2d7c9a2 commit 2d41202
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
44 changes: 30 additions & 14 deletions bundles/org.openhab.automation.jsscripting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,15 @@ var response = actions.HTTP.sendHttpGetRequest('<url>');

Replace `<url>` with the request url.

#### Ping Actions

See [openhab-js : actions.Ping](https://openhab.github.io/openhab-js/actions.html#.Ping) for complete documentation.

```javascript
// Check if a host is reachable
var reachable = actions.Ping.checkVitality(host, port, timeout); // host: string, port: int, timeout: int
```

#### ScriptExecution Actions

The `ScriptExecution` actions provide the `callScript(string scriptName)` method, which calls a script located at the `$OH_CONF/scripts` folder, as well as the `createTimer` method.
Expand Down Expand Up @@ -737,44 +746,51 @@ There are three different types of notifications:
- Standard Notifications: Sent to the registered devices of the specified user and shown as notification on his devices.
- Log Notifications: Only shown in the notification log, e.g. inside the Android and iOS Apps.
In addition to that, notifications can be updated later be re-using the same `referenceId` and hidden/removed either by `referenceId` or `tag`.
To send these three types of notifications, use the `notificationBuilder(message)` method of the `actions` namespace.
It returns a new `NotificationBuilder` object, which by default sends a broadcast notification and provides the following methods:
- `.logOnly()`: Send a log notification only.
- `.hide()`: Hides notifications with the specified `referenceId` or `tag`.
- `.addUserId(emailAddress)`: By adding the email address(es) of specific openHAB Cloud user(s), the notification is only sent to this (these) user(s).
- `.withIcon(icon)`: Sets the icon of the notification.
- `.withSeverity(link)`: Sets the severity of the notification.
- `.withTag(tag)`: Sets the tag of the notification. Used for grouping notifications and to hide/remove groups of notifications.
- `.withTitle(title)`: Sets the title of the notification.
- `.addUserId(emailAddress)`: By adding the email address(es) of specific openHAB Cloud user(s), the notification is only sent to this (these) user(s).
- `.withOnClickAction(action)`: Sets the action to be performed when the notification is clicked.
- `.withReferenceId(referenceId)`: Sets the reference ID of the notification. If none is set, but it might be useful, a random UUID will be generated.
The reference ID can be used to update or hide the notification later by using the same reference ID again.
- `.withOnClickAction(action)`: Sets the action to be executed when the notification is clicked.
- `.withMediaAttachmentUrl(mediaAttachmentUrl)`: Sets the URL of a media attachment to be displayed with the notification. This URL must be reachable by the push notification client.
- `.addActionButton(title, action)`: Adds an action button to the notification. Please note that due to Android and iOS limitations, only three action buttons are supported.
- `.send()`: Sends the notification.
- `.addActionButton(label, action)`: Adds an action button to the notification. Please note that due to Android and iOS limitations, only three action buttons are supported.
- `.send()``string|null`: Sends the notification and returns the reference ID or `null` for log notifications and when hiding notifications.
The syntax for the `action` parameter is described in [openHAB Cloud Connector: Action Syntax](https://www.openhab.org/addons/integrations/openhabcloud/#action-syntax).
The syntax for the `action` parameter is described in [openHAB Cloud Connector: Action Syntax](https://www.openhab.org/addons/integrations/openhabcloud/#action-syntax).
The syntax for the `mediaAttachmentUrl` parameter is described in [openHAB Cloud Connector](https://www.openhab.org/addons/integrations/openhabcloud/).
```javascript
// Send a simple broadcast notification
actions.notificationBuilder('Hello World!').send();
// Send a broadcast notification with icon, severity and title
// Send a broadcast notification with icon, tag and title
actions.notificationBuilder('Hello World!')
.withIcon('f7:bell_fill').withSeverity('important').withTitle('Important Notification').send();
// Send a broadcast notification with icon, severity, title, media attachment URL and actions
.withIcon('f7:bell_fill').withTag('important').withTitle('Important Notification').send();
// Send a broadcast notification with icon, tag, title, media attachment URL and actions
actions.notificationBuilder('Hello World!')
.withIcon('f7:bell_fill').withSeverity('important').withTitle('Important Notification').
.withIcon('f7:bell_fill').withTag('important').withTitle('Important Notification')
.withOnClickAction('ui:navigate:/page/my_floorplan_page').withMediaAttachmentUrl('http://example.com/image.jpg')
.addActionButton('Turn Kitchen Light ON=command:KitchenLights:ON').addActionButton('Turn Kitchen Light OFF=command:KitchenLights:OFF').send();

// Send a simple standard notification to two specific users
actions.notificationBuilder('Hello World!').addUserId('florian@example.com').addUserId('florian@example.org').send();
// Send a standard notification with icon, severity and title to two specific users
// Send a standard notification with icon, tag and title to two specific users
actions.notificationBuilder('Hello World!').addUserId('florian@example.com').addUserId('florian@example.org')
.withIcon('f7:bell_fill').withSeverity('important').withTitle('Important notification').send();
.withIcon('f7:bell_fill').withTag('important').withTitle('Important notification').send();

// Sends a simple log notification
actions.notificationBuilder('Hello World!').logOnly().send();
// Sends a simple log notification with icon and severity
// Sends a simple log notification with icon and tag
actions.notificationBuilder('Hello World!').logOnly()
.withIcon('f7:bell_fill').withSeverity('important').send();
.withIcon('f7:bell_fill').withTag('important').send();
```
See [openhab-js : actions.NotificationBuilder](https://openhab.github.io/openhab-js/actions.html#.notificationBuilder) for complete documentation.
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.automation.jsscripting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</bnd.importpackage>
<graal.version>22.0.0.2</graal.version> <!-- DO NOT UPGRADE: 22.0.0.2 is the latest version working on armv7l / OpenJDK 11.0.16 & armv7l / Zulu 17.0.5+8 -->
<oh.version>${project.version}</oh.version>
<ohjs.version>openhab@5.3.0</ohjs.version>
<ohjs.version>openhab@5.3.1</ohjs.version>
</properties>

<build>
Expand Down

0 comments on commit 2d41202

Please sign in to comment.