Skip to content

Commit

Permalink
Added support for out of range responses
Browse files Browse the repository at this point in the history
  • Loading branch information
hardillb committed Nov 19, 2016
1 parent 25af436 commit 83c265c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 10 additions & 2 deletions alexa.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,17 @@

<script type="text/x-red" data-help-name="alexa-home">
<p>This node sends a response to Alexa to acknoledge if the command
succeeded or not.</p>
succeeded or not. Responses must be sent with in 5 seconds of
receiving the request other wise a timeout message will be returned
to the Alexa sevice.</p>
<p>The message must come from the Alexa Home input node and takes a
payload of true/false</p>
payload of true/false for on/off requests. For percentage or
temperature requests the payload can also be an object with
the min and max accepted values for the accepted range. e.g.</p>
<pre>{
min: 10.0,
max: 30.0
}</pre>
</script>

<script type="text/javascript">
Expand Down
16 changes: 13 additions & 3 deletions alexa.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,16 @@ module.exports = function(RED) {
done();
};

this.acknoledge = function(messageId, device, success) {
this.acknoledge = function(messageId, device, success, range) {
var response = {
messageId: messageId,
success: success
};

if (!success && range) {
response.range = range;
}

var topic = 'response/' + node.username + '/' + device;
if (node.client && node.client.connected) {
node.client.publish(topic, JSON.stringify(response));
Expand Down Expand Up @@ -233,10 +237,16 @@ module.exports = function(RED) {
node.on('input',function(msg){
if (msg._messageId && msg._applianceId && msg._confId) {
var conf = RED.nodes.getNode(msg._confId);
if (msg.payload) {
if (typeof msg.payload == boolean && msg.payload) {
conf.acknoledge(msg._messageId, msg._applianceId, true);
} else {
conf.acknoledge(msg._messageId, msg._applianceId, false);
if (typeof msg.payload === 'boolean') {
conf.acknoledge(msg._messageId, msg._applianceId, false);
} else if (typeof msg.payload === 'object') {
if (message.payload.hasOwnProperty(min)) {
cong.acknoledge(msg._messageId, msg._applianceId, false, message.payload);
}
}
}
}

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-alexa-home-skill",
"version": "0.1.7",
"version": "0.1.8",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 83c265c

Please sign in to comment.