Skip to content

Commit

Permalink
Added output and fixed position parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkow committed Dec 21, 2017
1 parent 77180b4 commit 27dc65b
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions tahoma.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ module.exports = function(RED) {
break;
case "customPosition":
commandName = "setClosure";
parameters = [String(msg.payload.position)];
parameters = [msg.payload.position];
statusProgressText = "Going to "+ msg.payload.position +"%...";
statusDoneText = "Set to "+ msg.payload.position +"%";
expectedState = {open: true, position: msg.payload.position};
}



var command = {};
command.name = commandName;
if(parameters.length > 0) {
Expand Down Expand Up @@ -79,7 +81,19 @@ module.exports = function(RED) {

tahomalink.continueWhenFinished(node.device, expectedState)
.then(function() {
node.status({fill: 'green', shape: 'dot', text: statusDoneText});
node.status({
fill: 'green',
shape: 'dot',
text: statusDoneText
});

if(!('payload' in msg)) {
msg.payload = {};
}

// TODO: Find a better way to handle "my" position.
msg.payload.output = expectedState ? expectedState : {open: true};

node.send(msg);
});
});
Expand Down Expand Up @@ -111,21 +125,4 @@ module.exports = function(RED) {
});
return;
});

RED.httpAdmin.get('/tahomasomfy/updateState/:node', function(req, res, next){
var configNode = RED.nodes.getNode(req.params.boxid);

tahomalink.login(configNode.username, configNode.password)
.then(function() {
tahomalink.getDeviceState(req.params.deviceid)
.then(function(body) {
if(typeof body === "string") {
body = JSON.parse(body);
}

res.json(body);
});
});
return;
});
};

0 comments on commit 27dc65b

Please sign in to comment.