From c6bf1d543ba195476e8391dd886b928f6b5ec4ab Mon Sep 17 00:00:00 2001 From: Marcus Davies <55892693+marcus-j-davies@users.noreply.github.com> Date: Sun, 10 Sep 2023 16:26:36 +0100 Subject: [PATCH] Node RED 3.1 --- CHANGELOG.md | 9 +++++ package.json | 8 ++--- zwave-js/cmd-factory.js | 78 +++++++++++++++++++++++++++++++++++------ 3 files changed, 80 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68e402a2..5495d5db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # node-red-contrib-zwave-js Change Log + - 8.2.1 + + **Changes** + - Bump ZWave JS + + **Bug Fixes** + - Address Node RED 3.1 **evaluateJSONataExpression** Warning + + - 8.2.0 **Changes** diff --git a/package.json b/package.json index 6b7f98fa..1ef34ec8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-zwave-js", - "version": "8.2.0", + "version": "8.2.1", "license": "MIT", "description": "The most powerful, high performing and highly polished Z-Wave node for Node-RED based on Z-Wave JS. If you want a fully featured Z-Wave framework in your Node-RED instance, you have found it.", "dependencies": { @@ -8,11 +8,11 @@ "lodash": "^4.17.21", "winston": "^3.10.0", "winston-transport": "^4.5.0", - "zwave-js": "^11.6.0" + "zwave-js": "^11.14.1" }, "devDependencies": { - "eslint": "^8.45.0", - "prettier": "^3.0.0" + "eslint": "^8.49.0", + "prettier": "^3.0.3" }, "scripts": { "validate": "node-red-dev validate -o validation_result.json" diff --git a/zwave-js/cmd-factory.js b/zwave-js/cmd-factory.js index e18b9d3f..41830786 100644 --- a/zwave-js/cmd-factory.js +++ b/zwave-js/cmd-factory.js @@ -29,45 +29,79 @@ module.exports = function (RED) { } } - function ValueAPI(msg, send) { + let _AwaiterResolver; + const Awaiter = () => { + return new Promise((Resolve) => { + _AwaiterResolver = Resolve; + }); + }; + + async function ValueAPI(msg, send) { let NodeID = undefined; let Endpoint = undefined; let Value = undefined; let ValueID = undefined; let Options = undefined; + let Waiter; + if (config.node !== undefined && config.node.length > 0) { + Waiter = Awaiter(); const EXP = RED.util.prepareJSONataExpression(config.node, RedNode); - NodeID = RED.util.evaluateJSONataExpression(EXP, msg); + RED.util.evaluateJSONataExpression(EXP, msg, (Err, Res) => { + NodeID = Res; + _AwaiterResolver(); + }); + await Promise.all([Waiter]); } if (config.endpoint !== undefined && config.endpoint.length > 0) { + Waiter = Awaiter(); const EXP = RED.util.prepareJSONataExpression(config.endpoint, RedNode); - Endpoint = RED.util.evaluateJSONataExpression(EXP, msg); + RED.util.evaluateJSONataExpression(EXP, msg, (Err, Res) => { + Endpoint = Res; + _AwaiterResolver(); + }); + await Promise.all([Waiter]); } if (config.vapiValueId !== undefined && config.vapiValueId.length > 0) { + Waiter = Awaiter(); const EXP = RED.util.prepareJSONataExpression( config.vapiValueId, RedNode ); - ValueID = RED.util.evaluateJSONataExpression(EXP, msg); + RED.util.evaluateJSONataExpression(EXP, msg, (Err, Res) => { + ValueID = Res; + _AwaiterResolver(); + }); + await Promise.all([Waiter]); } if (config.vapiOptions !== undefined && config.vapiOptions.length > 0) { + Waiter = Awaiter(); const EXP = RED.util.prepareJSONataExpression( config.vapiOptions, RedNode ); - Options = RED.util.evaluateJSONataExpression(EXP, msg); + RED.util.evaluateJSONataExpression(EXP, msg, (Err, Res) => { + Options = Res; + _AwaiterResolver(); + }); + await Promise.all([Waiter]); } if (config.vapiValue !== undefined && config.vapiValue.length > 0) { + Waiter = Awaiter(); const EXP = RED.util.prepareJSONataExpression( config.vapiValue, RedNode ); - Value = RED.util.evaluateJSONataExpression(EXP, msg); + RED.util.evaluateJSONataExpression(EXP, msg, (Err, Res) => { + Value = Res; + _AwaiterResolver(); + }); + await Promise.all([Waiter]); } if (ValueID === undefined) { @@ -120,34 +154,56 @@ module.exports = function (RED) { } } - function CCAPI(msg, send) { + async function CCAPI(msg, send) { let NodeID = undefined; let Endpoint = undefined; let Params = undefined; const NoEvent = config.noEvent || false; let ForceUpdate = undefined; + let Waiter; + if (config.node !== undefined && config.node.length > 0) { + Waiter = Awaiter(); const EXP = RED.util.prepareJSONataExpression(config.node, RedNode); - NodeID = RED.util.evaluateJSONataExpression(EXP, msg); + RED.util.evaluateJSONataExpression(EXP, msg, (Err, Res) => { + NodeID = Res; + _AwaiterResolver(); + }); + await Promise.all([Waiter]); } if (config.endpoint !== undefined && config.endpoint.length > 0) { + Waiter = Awaiter(); const EXP = RED.util.prepareJSONataExpression(config.endpoint, RedNode); - Endpoint = RED.util.evaluateJSONataExpression(EXP, msg); + RED.util.evaluateJSONataExpression(EXP, msg, (Err, Res) => { + Endpoint = Res; + _AwaiterResolver(); + }); + await Promise.all([Waiter]); } if (config.params !== undefined && config.params.length > 0) { + Waiter = Awaiter(); const EXP = RED.util.prepareJSONataExpression(config.params, RedNode); - Params = RED.util.evaluateJSONataExpression(EXP, msg); + RED.util.evaluateJSONataExpression(EXP, msg, (Err, Res) => { + Params = Res; + _AwaiterResolver(); + }); + await Promise.all([Waiter]); } if (config.forceUpdate !== undefined && config.forceUpdate.length > 0) { + Waiter = Awaiter(); const EXP = RED.util.prepareJSONataExpression( config.forceUpdate, RedNode ); - ForceUpdate = RED.util.evaluateJSONataExpression(EXP, msg); + RED.util.evaluateJSONataExpression(EXP, msg, (Err, Res) => { + ForceUpdate = Res; + _AwaiterResolver(); + }); + await Promise.all([Waiter]); } if (Params !== undefined) {