Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rules] Add original input to event for file-based rules #334

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ items.replaceItem({
tags: ['Lightbulb'],
channels: {
'binding:thing:device:hallway#light': {},
'binding:thing:device:livingroom#light': {
profile: 'system:follow'
'binding:thing:device:livingroom#light': {
profile: 'system:follow'
}
},
metadata: {
Expand Down Expand Up @@ -1360,8 +1360,9 @@ This table gives an overview over the `event` object:
| `triggerType` | all except `PWMTrigger`, `PIDTrigger` | Type of trigger that triggered event | N/A |
| `eventClass` | all | Java class name of the triggering event | N/A |
| `module` | all | (user-defined or auto-generated) name of trigger | N/A |
| `raw` | all | Original contents of the event including data passed from a calling rule | N/A |

All properties are typeof `string`.
All properties are typeof `string` except for properties contained by `raw` which are unmodified from the original types.

Please note that when using `GenericEventTrigger`, the available properties depend on the chosen event types.
It is not possible for the openhab-js library to provide type conversions for all properties of all openHAB events, as those are too many.
Expand Down Expand Up @@ -1408,7 +1409,7 @@ Follow these steps to create your own library (it's called a CommonJS module):
function someFunction () {
console.log('Hello from your personal library!');
}

module.exports = {
someProperty,
someFunction
Expand Down
4 changes: 4 additions & 0 deletions src/rules/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @property {string} triggerType for all triggers except {@link triggers.PWMTrigger}, {@link triggers.PIDTrigger}: Type of trigger that triggered event
* @property {string} eventClass for all triggers: Java class name of the triggering event
* @property {string} module (user-defined or auto-generated) name of trigger
* @property {*} raw original contents of the event including data passed from a calling rule
* @property {*} payload if provided by event: payload of event in Java data types
*/

Expand Down Expand Up @@ -359,6 +360,9 @@ function _getTriggeredData (input) {
const event = input.get('event');
const data = {};

// Add input to data to passthrough any properties not captured below
data.raw = input;

// Dynamically added properties, depending on their availability

// Item triggers
Expand Down
4 changes: 4 additions & 0 deletions types/rules/rules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export type EventObject = {
* (user-defined or auto-generated) name of trigger
*/
module: string;
/**
* original contents of the event including data passed from a calling rule
*/
raw: any;
/**
* if provided by event: payload of event in Java data types
*/
Expand Down
2 changes: 1 addition & 1 deletion types/rules/rules.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading