From ddf94a0cc156bcca7aba8143b085b3824e6797ea Mon Sep 17 00:00:00 2001 From: Marcus Davies <55892693+marcus-j-davies@users.noreply.github.com> Date: Tue, 12 Sep 2023 21:35:40 +0100 Subject: [PATCH] Address Node RED 3.1 changes (#62) --- package.json | 2 +- src/nodes/Protect.ts | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5c2c918..cff91bd 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/nodes/Protect.ts b/src/nodes/Protect.ts index 9d51fd2..e366eaa 100644 --- a/src/nodes/Protect.ts +++ b/src/nodes/Protect.ts @@ -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 @@ -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') {