Skip to content

Commit

Permalink
First checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
hardillb committed Nov 5, 2016
0 parents commit 31d9734
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/*
Empty file added LICENSE
Empty file.
Empty file added README.md
Empty file.
79 changes: 79 additions & 0 deletions alexa.html
@@ -0,0 +1,79 @@
<script type="text/x-red" data-template-name="alexa-home-conf">
<div class="form-row">
<label for="node-input-username"><i class="icon-tag"></i> Username</label>
<input type="text" id="node-input-username">
</div>
<div class="form-row">
<label for="node-input-password"><i class="icon-tag"></i> Password</label>
<input type="password" id="node-input-password">
</div>
</script>

<script type="text/x-red" data-help-name="alexa-home-conf">
<p><a target="_blank" href="https://alexa-node-red.eu-gb.mybluemix.net/">here</a></p>
</script>

<script type="text/javascript">
RED.nodes.registerType('alexa-home-conf',{
category: 'config',
defaults: {
name: {}
},
color: 'gray',
label: function() {
return this.name;
},
oneditsave: function(){
var node = this;
var username = $('#node-input-username').val();
var password = $('#node-input-password').val();
this.name = username;
var account = {
id: node.id,
user: username,
pass: password
}
$.post('alexa-home/new-account',account);
}
});
</script>

<script type="text/x-red" data-template-name="alexa-home">
<div class="form-row">
<label for="node-input-conf"><i class="icon-tag"></i> Accout</label>
<input type="text" id="node-input-conf">
</div>
<div class="form-row">
<label for="node-input-device"><i class="icon-tag"></i> Device</label>
<select id="node-input-device">

</select>
</div>
</script>

<script type="text/x-red" data-help-name="alexa-home">
<p><a target="_blank" href="https://alexa-node-red.eu-gb.mybluemix.net/">here</a></p>
</script>

<script type="text/javascript">
RED.nodes.registerType('alexa-home',{
category: 'input',
defaults: {
conf: {value: "", type:"alexa-home-conf"},
device: {value: "" },
name: {}
},
outputs: 1,
inputs: 0,
color: 'gray',
label: function() {
return this.name || "Alexa Home";
},
oneditprepare: function(){
var node = this;
if (node.conf) {
console.log($('#node-input-conf').val());
}
}
});
</script>
81 changes: 81 additions & 0 deletions alexa.js
@@ -0,0 +1,81 @@
/**
* Copyright 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

module.export = function(RED) {
"use strict";
var request = require('request');
var mqtt = require('mqtt');
var bodyParser = require('body-parser');

var devices = {};

function conf(n) {
RED.nodes.createNode(this,n);
this.username = this.credentials.username;
this.password = this.credentials.password;

var node = this;

this.on('close',function(){
delete devices[username];
});
}

RED.registerType("alexa-home-conf",conf,{
credentials: {
username: {type: "text"},
password: {type: "password"}
}
});

function alexaHome(n) {
RED.nodes.createNode(this,n);
this.conf = RED.nodes.getNode(n.conf);
this.device = n.device;

var node = this;

}

RED.registerType("alexa-home",alexaHome);

RED.httpAdmin.use('/alexa-home/new-account',bodyParser.json());

RED.httpAdmin.post('/alexa-home/new-account',function(req,res){
console.log(req.body);
// request.get({
// url: 'https://alexa-node-red.eu-gb.mybluemix.net/api/v1/devices',
// auth: {
// username: node.username,
// password: node.password
// }
// }, function(err, res, body){
// if (!err) {
// devs = JSON.parse(body);
// console.log(devs);
// devices[node.username] = devs;
// }
// });
});

RED.httpAdmin.get('/alexa-home/devices/:id',function(req,res){
if (devices[req.params.id]) {
res.send(devices[req.params.id]);
} else {
res.status(404).send();
}
});
};
25 changes: 25 additions & 0 deletions package.json
@@ -0,0 +1,25 @@
{
"name": "node-red-contrib-alexa-home-skill",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"node-red",
"alexa",
"echo"
],
"node-red": {
"nodes": {
"alexa": "alexa.js"
}
},
"author": "hardillb@gmail.com",
"license": "Apache-2.0",
"dependencies": {
"mqtt": "^2.0.1",
"request": "^2.78.0"
}
}

0 comments on commit 31d9734

Please sign in to comment.