Skip to content

Commit

Permalink
Address Node RED 3.1 changes (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-j-davies authored Sep 12, 2023
1 parent 185391c commit ddf94a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-unifi-os",
"version": "0.9.0",
"version": "0.9.1",
"description": "Nodes to access UniFi data using endpoints and websockets",
"main": "build/nodes/unifi.js",
"scripts": {
Expand Down
21 changes: 19 additions & 2 deletions src/nodes/Protect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ module.exports = (RED: NodeAPI) => {
}, parseInt(self.config.delayedSnapshotTime))
}

// Awaiter (Node RED 3.1 evaluateJSONataExpression )
let _AwaiterResolver: (value?: unknown) => void
const Awaiter = () => {
return new Promise((Resolve) => {
_AwaiterResolver = Resolve
})
}

// Register our interest in Protect Updates.
const handleUpdate = async (data: any) => {
/* This is to mirror the output pin assigmnets
Expand Down Expand Up @@ -337,15 +345,24 @@ module.exports = (RED: NodeAPI) => {
}
}

let Waiter

if (identifiedEvent.metadata.valueExpression) {
Waiter = Awaiter()
const EXP = RED.util.prepareJSONataExpression(
identifiedEvent.metadata.valueExpression,
self
)
UserPL.payload.value = RED.util.evaluateJSONataExpression(
RED.util.evaluateJSONataExpression(
EXP,
data
data,
(_err, res) => {
UserPL.payload.value = res
_AwaiterResolver()
}
)

await Promise.all([Waiter])
}

if (self.config.snapshotMode === 'None') {
Expand Down

0 comments on commit ddf94a0

Please sign in to comment.