Skip to content

Commit

Permalink
Queues pour cmd et scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
NebzHB authored Jan 24, 2024
1 parent f0e9caa commit abc540b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/jeedom-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))

Check failure on line 33 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Mixed spaces and tabs

Check failure on line 33 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected parentheses around arrow function argument

Check failure on line 33 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Mixed spaces and tabs

Check failure on line 33 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected parentheses around arrow function argument

Check failure on line 33 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Mixed spaces and tabs

Check failure on line 33 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Expected parentheses around arrow function argument
.catch(err => callback(err, null));

Check failure on line 34 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Mixed spaces and tabs

Check failure on line 34 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected parentheses around arrow function argument

Check failure on line 34 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Mixed spaces and tabs

Check failure on line 34 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected parentheses around arrow function argument

Check failure on line 34 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Mixed spaces and tabs

Check failure on line 34 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Expected parentheses around arrow function argument
} else if(task.type==='scenario') {
this._executeScenarioAction(task.ID, task.action)
.then(result => callback(null, result))

Check failure on line 37 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Mixed spaces and tabs

Check failure on line 37 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected parentheses around arrow function argument

Check failure on line 37 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Mixed spaces and tabs

Check failure on line 37 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected parentheses around arrow function argument

Check failure on line 37 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Mixed spaces and tabs

Check failure on line 37 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Expected parentheses around arrow function argument
.catch(err => callback(err, null));

Check failure on line 38 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Mixed spaces and tabs

Check failure on line 38 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected parentheses around arrow function argument

Check failure on line 38 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Mixed spaces and tabs

Check failure on line 38 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected parentheses around arrow function argument

Check failure on line 38 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Mixed spaces and tabs

Check failure on line 38 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Expected parentheses around arrow function argument
}
}, 1);
}

JeedomClient.prototype.getModel = function() {
Expand Down Expand Up @@ -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);

Check failure on line 237 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected { after 'if' condition

Check failure on line 237 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected { after 'if' condition

Check failure on line 237 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Expected { after 'if' condition
else resolve(result);

Check failure on line 238 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected { after 'else'

Check failure on line 238 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected { after 'else'

Check failure on line 238 in lib/jeedom-api.js

View workflow job for this annotation

GitHub Actions / build (21.x)

Expected { after 'else'
});
});
};

JeedomClient.prototype._executeDeviceAction = function(ID, action, param) {
var that = this;
var options = {};
var url = that.url;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit abc540b

Please sign in to comment.