Skip to content

Commit

Permalink
Merge bb7f1df into 511b5ce
Browse files Browse the repository at this point in the history
  • Loading branch information
ottoszika authored Dec 13, 2019
2 parents 511b5ce + bb7f1df commit 36b15a2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils/ewelink-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ module.exports = {
this.login(RED, node, config).then(connection => {
// Once logged in we can listen to inputs
node.on('input', (msg) => {
method = method || msg.payload.method;
params = (typeof params === 'function' ? params(msg) : params) || msg.payload.params || [];
// Get method name and build params
const evaluatedMethod = method || msg.payload.method;
const evaluatedParams = (typeof params === 'function' ? params(msg) : params) || msg.payload.params || [];

// First parameter should be always the device ID
params.unshift(deviceId);
evaluatedParams.unshift(deviceId);

// Call dynamically the method
connection[method].apply(connection, params).then(result => {
connection[evaluatedMethod].apply(connection, evaluatedParams).then(result => {
node.send({ payload: result });
}).catch(error => node.error(error));
})
Expand Down

0 comments on commit 36b15a2

Please sign in to comment.