Skip to content

Commit

Permalink
Merged release/0.1.0 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
biddster committed Jan 30, 2017
2 parents af7d18e + 37f41c8 commit ff2727d
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 6 deletions.
Binary file added icons/hs100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!--
The MIT License (MIT)
Copyright (c) 2016 @biddster
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<script type="text/javascript">
RED.nodes.registerType('hs100', {
category: 'output',
color: '#f37a33',
defaults: {
name: {value: ''},
host: {value: ''}
},
inputs: 1,
outputs: 0,
icon: 'hs100.png',
label: function () {
return this.name || 'hs100';
},
paletteLabel: 'hs100',
align: 'right'
});
</script>

<script type="text/x-red" data-template-name="hs100">

<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i>Node Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-host"><i class="icon-tag"></i>Host Address</label>
<input type="text" id="node-input-host" placeholder="">
</div>

</script>

<script type="text/x-red" data-help-name="hs100">

</script>
52 changes: 52 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
The MIT License (MIT)
Copyright (c) 2017 @biddster
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

module.exports = function (RED) {
'use strict';

var Hs100Api = require('fx-hs100-api');

RED.nodes.registerType('hs100', function (config) {

RED.nodes.createNode(this, config);
var node = this;

var client = new Hs100Api.Client();
var plug = client.getPlug({host: config.host});

node.on('input', function (msg) {
var state = msg.payload === 'on';
plug.setPowerState(state);
node.status({
fill: 'green',
shape: state ? 'dot' : 'circle',
text: state ? 'on' : 'off'
});
});

node.on('close', function () {
client.socket.close();
});
});
};
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "git ",
"name": "node-red-contrib-hs100",
"version": "0.1.0",
"description": "",
"main": "index.js",
Expand All @@ -17,7 +17,17 @@
},
"author": "@biddster",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/biddster/node-red-contrib-hs100.git"
},

"dependencies": {
"fx-hs100-api": "^0.3.0"
},
"node-red": {
"nodes": {
"hs100": "index.js"
}
}
}
19 changes: 14 additions & 5 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,24 @@ var Hs100Api = require('fx-hs100-api');


describe('hs100', function () {
this.timeout(60000);
describe('test', function () {
it('should turn a known socket on and off', function (done) {
var client = new Hs100Api.Client();
var plug = client.getPlug({host: '10.0.1.2'});
var plug = client.getPlug({host: '192.168.74.82'});
plug.setPowerState(true);
setTimeout(function () {
plug.setPowerState(false);
done();
}, 1000);
console.log('Turned it on');
plug.getInfo().then(function (device) {
console.log(JSON.stringify(device, null, 4));
setTimeout(function () {
plug.setPowerState(false);
console.log('Turned it off');
setTimeout(function () {
console.log('Exiting test');
done();
}, 10000);
}, 10000);
});
});
});
});

0 comments on commit ff2727d

Please sign in to comment.