From f0e9caae5e8852a69549245c3add7eeeb2896246 Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:33:10 +0100 Subject: [PATCH 1/7] Update package.json --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 23d7512..c64f486 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,9 @@ "Siri" ], "dependencies": { + "async": "^3.2.5", "axios": ">=1.6.5", - "express": "^4.18.2", + "express": "^4.18.2", "fakegato-history": "NebzHB/fakegato-history#master" }, "devDependencies": { From abc540b40af6c8d63c80c88ac8e85ea7098ccf11 Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:43:46 +0100 Subject: [PATCH 2/7] Queues pour cmd et scenarios --- lib/jeedom-api.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/jeedom-api.js b/lib/jeedom-api.js index 7de41bb..c1a4e5b 100755 --- a/lib/jeedom-api.js +++ b/lib/jeedom-api.js @@ -16,6 +16,7 @@ /* jshint esversion: 6,node: true */ 'use strict'; const axios = require('axios'); +const async = require('async'); var DEV_DEBUG; function JeedomClient(url, apikey, Plateform, myPlugin) { @@ -26,6 +27,17 @@ function JeedomClient(url, apikey, Plateform, myPlugin) { this.log = this.Plateform.log; this.myPlugin = myPlugin || "mobile"; DEV_DEBUG = Plateform.DEV_DEBUG || false; + this.queue = async.queue((task, callback) => { + if(task.type==='cmd') { + this._executeDeviceAction(task.ID, task.action, task.param) + .then(result => callback(null, result)) + .catch(err => callback(err, null)); + } else if(task.type==='scenario') { + this._executeScenarioAction(task.ID, task.action) + .then(result => callback(null, result)) + .catch(err => callback(err, null)); + } + }, 1); } JeedomClient.prototype.getModel = function() { @@ -220,6 +232,15 @@ JeedomClient.prototype.updateModelInfo = function(ID,value,internal=false) { }; JeedomClient.prototype.executeDeviceAction = function(ID, action, param) { + return new Promise((resolve, reject) => { + this.queue.push({ID, action, param, type:'cmd'}, (err, result) => { + if (err) reject(err); + else resolve(result); + }); + }); +}; + +JeedomClient.prototype._executeDeviceAction = function(ID, action, param) { var that = this; var options = {}; var url = that.url; @@ -257,6 +278,15 @@ JeedomClient.prototype.executeDeviceAction = function(ID, action, param) { }; JeedomClient.prototype.executeScenarioAction = function(ID, action) { + return new Promise((resolve, reject) => { + this.queue.push({ID, action, type:'scenario'}, (err, result) => { + if (err) reject(err); + else resolve(result); + }); + }); +}; + +JeedomClient.prototype._executeScenarioAction = function(ID, action) { var that = this; var url = that.url; From 586b2a9d8eb9672f40c6a3b4bb776c5aaa48951b Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:45:28 +0100 Subject: [PATCH 3/7] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c64f486..0275870 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@nebz/homebridge-jeedom", "version": "v1.7.0", - "cust_serial": "0008", + "cust_serial": "0009", "description": "Homebridge plugin for Jeedom ", "main": "index.js", "private":true, From 88cd069bc07d5b6b5b9f06c03a7070288122f82c Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:12:15 +0100 Subject: [PATCH 4/7] Update jeedom-api.js --- lib/jeedom-api.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/jeedom-api.js b/lib/jeedom-api.js index c1a4e5b..bb1dd26 100755 --- a/lib/jeedom-api.js +++ b/lib/jeedom-api.js @@ -18,6 +18,7 @@ const axios = require('axios'); const async = require('async'); var DEV_DEBUG; +var USE_QUEUES=true; function JeedomClient(url, apikey, Plateform, myPlugin) { this.apikey = apikey; @@ -30,12 +31,12 @@ function JeedomClient(url, apikey, Plateform, myPlugin) { this.queue = async.queue((task, callback) => { if(task.type==='cmd') { this._executeDeviceAction(task.ID, task.action, task.param) - .then(result => callback(null, result)) - .catch(err => callback(err, null)); + .then(result => callback(null, result)) + .catch(err => callback(err, null)); } else if(task.type==='scenario') { this._executeScenarioAction(task.ID, task.action) - .then(result => callback(null, result)) - .catch(err => callback(err, null)); + .then(result => callback(null, result)) + .catch(err => callback(err, null)); } }, 1); } @@ -232,12 +233,13 @@ JeedomClient.prototype.updateModelInfo = function(ID,value,internal=false) { }; JeedomClient.prototype.executeDeviceAction = function(ID, action, param) { - return new Promise((resolve, reject) => { - this.queue.push({ID, action, param, type:'cmd'}, (err, result) => { - if (err) reject(err); - else resolve(result); - }); - }); + if(!USE_QUEUES) return this._executeDeviceAction(ID, action, param); + return new Promise((resolve, reject) => { + this.queue.push({ID, action, param, type:'cmd'}, (err, result) => { + if (err) reject(err); + else resolve(result); + }); + }); }; JeedomClient.prototype._executeDeviceAction = function(ID, action, param) { @@ -278,12 +280,13 @@ JeedomClient.prototype._executeDeviceAction = function(ID, action, param) { }; JeedomClient.prototype.executeScenarioAction = function(ID, action) { - return new Promise((resolve, reject) => { - this.queue.push({ID, action, type:'scenario'}, (err, result) => { - if (err) reject(err); - else resolve(result); - }); - }); + if(!USE_QUEUES) return this._executeScenarioAction(ID, action); + return new Promise((resolve, reject) => { + this.queue.push({ID, action, type:'scenario'}, (err, result) => { + if (err) reject(err); + else resolve(result); + }); + }); }; JeedomClient.prototype._executeScenarioAction = function(ID, action) { From cd841ee4fed84c8b4a9c652e2a9086c1a94c91e7 Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:20:32 +0100 Subject: [PATCH 5/7] Update jeedom-api.js --- lib/jeedom-api.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/jeedom-api.js b/lib/jeedom-api.js index bb1dd26..1e4a9c5 100755 --- a/lib/jeedom-api.js +++ b/lib/jeedom-api.js @@ -18,7 +18,7 @@ const axios = require('axios'); const async = require('async'); var DEV_DEBUG; -var USE_QUEUES=true; +const USE_QUEUES=1; function JeedomClient(url, apikey, Plateform, myPlugin) { this.apikey = apikey; @@ -38,7 +38,7 @@ function JeedomClient(url, apikey, Plateform, myPlugin) { .then(result => callback(null, result)) .catch(err => callback(err, null)); } - }, 1); + }, ((USE_QUEUES===0)?1:USE_QUEUES)); } JeedomClient.prototype.getModel = function() { @@ -233,11 +233,11 @@ JeedomClient.prototype.updateModelInfo = function(ID,value,internal=false) { }; JeedomClient.prototype.executeDeviceAction = function(ID, action, param) { - if(!USE_QUEUES) return this._executeDeviceAction(ID, action, param); + if(USE_QUEUES === 0) { return this._executeDeviceAction(ID, action, param); } return new Promise((resolve, reject) => { this.queue.push({ID, action, param, type:'cmd'}, (err, result) => { - if (err) reject(err); - else resolve(result); + if (err) { reject(err); } + else { resolve(result); } }); }); }; @@ -280,11 +280,11 @@ JeedomClient.prototype._executeDeviceAction = function(ID, action, param) { }; JeedomClient.prototype.executeScenarioAction = function(ID, action) { - if(!USE_QUEUES) return this._executeScenarioAction(ID, action); + if(USE_QUEUES === 0) { return this._executeScenarioAction(ID, action); } return new Promise((resolve, reject) => { this.queue.push({ID, action, type:'scenario'}, (err, result) => { - if (err) reject(err); - else resolve(result); + if (err) { reject(err); } + else { resolve(result); } }); }); }; From efb84a8ed2f490198f21fb44ae598f6e92b6accd Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:32:15 +0100 Subject: [PATCH 6/7] Update jeedom-api.js --- lib/jeedom-api.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/jeedom-api.js b/lib/jeedom-api.js index 1e4a9c5..34c48a8 100755 --- a/lib/jeedom-api.js +++ b/lib/jeedom-api.js @@ -31,12 +31,12 @@ function JeedomClient(url, apikey, Plateform, myPlugin) { this.queue = async.queue((task, callback) => { if(task.type==='cmd') { this._executeDeviceAction(task.ID, task.action, task.param) - .then(result => callback(null, result)) - .catch(err => callback(err, null)); + .then((result) => callback(null, result)) + .catch((err) => callback(err, null)); } else if(task.type==='scenario') { this._executeScenarioAction(task.ID, task.action) - .then(result => callback(null, result)) - .catch(err => callback(err, null)); + .then((result) => callback(null, result)) + .catch((err) => callback(err, null)); } }, ((USE_QUEUES===0)?1:USE_QUEUES)); } From 0c2482df88bb908f7e96cf3cf112491401965c58 Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:34:47 +0100 Subject: [PATCH 7/7] Update jeedom-api.js --- lib/jeedom-api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jeedom-api.js b/lib/jeedom-api.js index 34c48a8..25b82bf 100755 --- a/lib/jeedom-api.js +++ b/lib/jeedom-api.js @@ -18,7 +18,7 @@ const axios = require('axios'); const async = require('async'); var DEV_DEBUG; -const USE_QUEUES=1; +const USE_QUEUES=1; // 0 = NO, or 1 or 2 etc for the concurrent tasks function JeedomClient(url, apikey, Plateform, myPlugin) { this.apikey = apikey;