Skip to content

Commit

Permalink
Update 2.3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Zehir committed Dec 27, 2023
1 parent 68e015a commit 2a59ee0
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 74 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] :construction:

## [2.3.11] - 2023-12-27 ![Relative date](https://img.shields.io/date/1703697133?label=)

### Fixed

- Fix more JSONata Expression handling for Node-Red 4.0. @Zehir
- Fix default value for node status of deconz-battery. @Zehir
- Fix deconz-battery node filter not showing devices with `state.battery`. (#228) @Zehir
- Fix HomeKit attribute BatteryLevel and StatusLowBattery for devices with `state.battery`. @Zehir

## [2.3.10] - 2023-12-14 ![Relative date](https://img.shields.io/date/1702556236?label=)

### Fixed
Expand Down
30 changes: 18 additions & 12 deletions deconz.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = function (RED) {
/**
* Enable http route to JSON itemlist for each controller (controller id passed as GET query parameter)
*/
RED.httpAdmin.get(NODE_PATH + "itemlist", function (req, res) {
RED.httpAdmin.get(NODE_PATH + "itemlist", async function (req, res) {
try {
let config = req.query;
let controller = RED.nodes.getNode(config.controllerID);
Expand All @@ -64,13 +64,18 @@ module.exports = function (RED) {
req.query.query !== undefined &&
["json", "jsonata"].includes(queryType)
) {
query = RED.util.evaluateNodeProperty(
req.query.query,
queryType,
RED.nodes.getNode(req.query.nodeID),
{},
undefined
);
query = await new Promise((resolve, reject) => {
RED.util.evaluateNodeProperty(
req.query.query,
queryType,
RED.nodes.getNode(req.query.nodeID),
{},
(err, value) => {
if (err) reject(err);
else resolve(value);
}
);
});
}
} catch (e) {
return res.json({
Expand Down Expand Up @@ -290,6 +295,7 @@ module.exports = function (RED) {
if (controller && controller.constructor.name === "ServerNode") {
let fakeNode = { server: controller };
let cp = new CommandParser(config.command, {}, fakeNode);
await cp.build();
let devices = [];
for (let path of config.device_list) {
let device = controller.device_list.getDeviceByPath(path);
Expand All @@ -299,25 +305,25 @@ module.exports = function (RED) {
console.warn(`Error : Device not found : '${path}'`);
}
}
let requests = cp.getRequests(fakeNode, devices);
let requests = await cp.getRequests(fakeNode, devices);
for (const [request_id, request] of requests.entries()) {
const response = await got(
controller.api.url.main() + request.endpoint,
{
method: "PUT",
retry:
Utils.getNodeProperty(
(await Utils.getNodeProperty(
config.command.arg.retryonerror,
this,
{}
) || 0,
)) || 0,
json: request.params,
responseType: "json",
timeout: 2000, // TODO make configurable ?
}
);
await Utils.sleep(
Utils.getNodeProperty(config.delay, this, {}) || 50
(await Utils.getNodeProperty(config.delay, this, {})) || 50
);
}
res.status(200).end();
Expand Down
6 changes: 3 additions & 3 deletions nodes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ module.exports = function (RED) {
// Load the config
let config = node.config;
let methods = ["GET", "POST", "PUT", "DELETE"];
let method = Utils.getNodeProperty(
let method = await Utils.getNodeProperty(
config.specific.method,
node,
message_in,
methods
);
// Make sure the method is valid
if (!methods.includes(method)) method = "GET";
let endpoint = Utils.getNodeProperty(
let endpoint = await Utils.getNodeProperty(
config.specific.endpoint,
node,
message_in
);
let payload = Utils.getNodeProperty(
let payload = await Utils.getNodeProperty(
config.specific.payload,
node,
message_in
Expand Down
2 changes: 1 addition & 1 deletion nodes/battery.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
required: false
},
statustext_type: {
value: "default",
value: "auto",
required: true
},
search_type: {
Expand Down
17 changes: 9 additions & 8 deletions nodes/out.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module.exports = function (RED) {
return;
}

let delay = Utils.getNodeProperty(
let delay = await Utils.getNodeProperty(
node.config.specific.delay,
this,
message_in
Expand Down Expand Up @@ -169,7 +169,7 @@ module.exports = function (RED) {
let resultMsgs = [];
let errorMsgs = [];
let resultTimings = ["never", "after_command", "at_end"];
let resultTiming = Utils.getNodeProperty(
let resultTiming = await Utils.getNodeProperty(
node.config.specific.result,
this,
message_in,
Expand All @@ -185,7 +185,7 @@ module.exports = function (RED) {
// Make sure that all expected config are defined
const command = Object.assign({}, defaultCommand, saved_command);
if (command.type === "pause") {
let sleep_delay = Utils.getNodeProperty(
let sleep_delay = await Utils.getNodeProperty(
command.arg.delay,
this,
message_in
Expand All @@ -211,7 +211,8 @@ module.exports = function (RED) {

try {
let cp = new CommandParser(command, message_in, node);
let requests = cp.getRequests(node, devices);
await cp.build();
let requests = await cp.getRequests(node, devices);
let request_count = requests.length;
for (const [request_id, request] of requests.entries()) {
try {
Expand All @@ -238,11 +239,11 @@ module.exports = function (RED) {
{
method: "PUT",
retry:
Utils.getNodeProperty(
(await Utils.getNodeProperty(
command.arg.retryonerror,
this,
message_in
) || 0,
)) || 0,
json: request.params,
responseType: "json",
timeout: 2000, // TODO make configurable ?
Expand Down Expand Up @@ -343,12 +344,12 @@ module.exports = function (RED) {
}

if (
Utils.getNodeProperty(
(await Utils.getNodeProperty(
command.arg.aftererror,
this,
message_in,
["continue", "stop"]
) === "stop"
)) === "stop"
)
return;

Expand Down
6 changes: 4 additions & 2 deletions nodes/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ module.exports = function (RED) {
}
}

updateNodeStatus(node, msgToSend) {
async updateNodeStatus(node, msgToSend) {
if (node.server.ready === false) {
node.status({
fill: "red",
Expand Down Expand Up @@ -885,7 +885,7 @@ module.exports = function (RED) {
node.status({
fill: "green",
shape: "dot",
text: Utils.getNodeProperty(
text: await Utils.getNodeProperty(
{
type: node.config.statustext_type,
value: node.config.statustext,
Expand Down Expand Up @@ -924,6 +924,8 @@ module.exports = function (RED) {
break;
case "deconz-battery":
let battery = dotProp.get(firstmsg, "meta.config.battery");
if (battery === undefined)
battery = dotProp.get(firstmsg, "meta.state.battery");
if (battery === undefined) return;
node.status({
fill:
Expand Down
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-deconz",
"version": "2.3.10",
"version": "2.3.11",
"description": "deCONZ connectivity nodes for node-red",
"keywords": [
"deconz",
Expand Down
6 changes: 6 additions & 0 deletions src/editor/DeconzDeviceListEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@ class DeconzDeviceListEditor extends DeconzEditor {
options.keepOnlyMatched = true;
params.query = JSON.stringify({
type: "match",
method: "OR",
match: {
"config.battery": {
type: "complex",
operator: "!==",
value: undefined,
},
"state.battery": {
type: "complex",
operator: "!==",
value: undefined,
},
},
});
}
Expand Down
Loading

0 comments on commit 2a59ee0

Please sign in to comment.