Skip to content

[rules] Expose _getTriggeredData & Adjust for backward compat with UI scripts#466

Merged
florian-h05 merged 1 commit intoopenhab:mainfrom
florian-h05:rules-eventdata
Aug 29, 2025
Merged

[rules] Expose _getTriggeredData & Adjust for backward compat with UI scripts#466
florian-h05 merged 1 commit intoopenhab:mainfrom
florian-h05:rules-eventdata

Conversation

@florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Aug 29, 2025

Closes #443.

Description

  • Exposes the _getTriggeredData utility from the rules namespace, which converts the Java event data to pure JS.
  • Adds optional backwards compatibilty with the pure Java event object in UI-based environments by adding its event properties to the event object if a flag is set. Accessing these properties logs warnings.
  • One minor breaking change for UI-based environments: The .payload property of _getTriggeredData returns a object, the pure Java version returns a JSON string that has to be parsed by the user.

Testing

I used the following script to check for potential differences / verify same behaviour:

var newEvent = rules._getTriggeredData(ctx, true)

console.error('itemState')
console.log(event.itemState)
console.log(newEvent.itemState)

console.error('oldItemState')
console.log(event.oldItemState)
console.log(newEvent.oldItemState)

console.error('itemCommand')
console.log(event.itemCommand)
console.log(newEvent.itemCommand)

console.error('itemName')
console.log(event.itemName)
console.log(newEvent.itemName)

console.error('type')
console.log(event.type)
console.log(newEvent.type)

console.error('event')
console.log(event.event)
console.log(newEvent.event)

console.error('payload')
console.log(event.payload)
console.log(newEvent.payload)

… scripts

Closes openhab#443.

Signed-off-by: Florian Hotze <dev@florianhotze.com>
@florian-h05 florian-h05 added this to the to be released milestone Aug 29, 2025
@florian-h05 florian-h05 requested a review from a team as a code owner August 29, 2025 08:50
@florian-h05 florian-h05 added the enhancement New feature or request label Aug 29, 2025
@florian-h05 florian-h05 requested review from Copilot and removed request for a team August 29, 2025 08:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR exposes the internal _getTriggeredData utility function from the rules namespace to convert Java event data to JavaScript objects, while adding optional backward compatibility for UI-based environments.

  • Exposes _getTriggeredData function in the module exports for external use
  • Adds backward compatibility layer with deprecated property warnings for UI scripts
  • Introduces parameter to control backward compatibility behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@florian-h05 florian-h05 merged commit 4bc6692 into openhab:main Aug 29, 2025
5 checks passed
@florian-h05 florian-h05 deleted the rules-eventdata branch August 29, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose _getTriggeredData as a utility for managed rules

2 participants