From e6a9888ad32acc3bbff7da8bbf41b142985a4d56 Mon Sep 17 00:00:00 2001 From: biddster Date: Sun, 29 Jan 2017 23:42:31 +0000 Subject: [PATCH 1/6] Wait 10 secs before turning off in the test. --- tests/test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test.js b/tests/test.js index b08cf21..b936144 100644 --- a/tests/test.js +++ b/tests/test.js @@ -29,15 +29,18 @@ 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'}); plug.setPowerState(true); + console.log('Turned it on'); setTimeout(function () { plug.setPowerState(false); + console.log('Turned it off'); done(); - }, 1000); + }, 10000); }); }); }); From d2c10c5943d645e3d3feebaf4a96fb17fd34acf8 Mon Sep 17 00:00:00 2001 From: biddster Date: Mon, 30 Jan 2017 00:01:53 +0000 Subject: [PATCH 2/6] Try getInfo. --- tests/test.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/test.js b/tests/test.js index b936144..8a13d8b 100644 --- a/tests/test.js +++ b/tests/test.js @@ -33,14 +33,17 @@ describe('hs100', function () { 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); console.log('Turned it on'); - setTimeout(function () { - plug.setPowerState(false); - console.log('Turned it off'); - done(); - }, 10000); + plug.getInfo().then(function (device) { + console.log(JSON.stringify(device, null, 4); + setTimeout(function () { + plug.setPowerState(false); + console.log('Turned it off'); + done(); + }, 10000); + }); }); }); }); From 3c24ee2716d3bcb89993e80af4fb8cfb081bacf3 Mon Sep 17 00:00:00 2001 From: biddster Date: Mon, 30 Jan 2017 00:02:53 +0000 Subject: [PATCH 3/6] Add missing ) --- tests/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.js b/tests/test.js index 8a13d8b..991ebbe 100644 --- a/tests/test.js +++ b/tests/test.js @@ -37,7 +37,7 @@ describe('hs100', function () { plug.setPowerState(true); console.log('Turned it on'); plug.getInfo().then(function (device) { - console.log(JSON.stringify(device, null, 4); + console.log(JSON.stringify(device, null, 4)); setTimeout(function () { plug.setPowerState(false); console.log('Turned it off'); From ce26374de126e378c639be7da5acfd9aa7c21313 Mon Sep 17 00:00:00 2001 From: biddster Date: Mon, 30 Jan 2017 00:24:41 +0000 Subject: [PATCH 4/6] Test tweaks. --- tests/test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test.js b/tests/test.js index 991ebbe..d3b209c 100644 --- a/tests/test.js +++ b/tests/test.js @@ -41,7 +41,10 @@ describe('hs100', function () { setTimeout(function () { plug.setPowerState(false); console.log('Turned it off'); - done(); + setTimeout(function () { + console.log('Exiting test'); + done(); + }, 10000); }, 10000); }); }); From 13f492f2100d78cd42f81ea1f935ecba8b07af46 Mon Sep 17 00:00:00 2001 From: biddster Date: Mon, 30 Jan 2017 22:23:59 +0000 Subject: [PATCH 5/6] Node red index.js and html. --- icons/hs100.png | Bin 0 -> 308 bytes index.html | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 52 ++++++++++++++++++++++++++++++++++++++++++ package.json | 12 +++++++++- 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 icons/hs100.png create mode 100644 index.html create mode 100644 index.js diff --git a/icons/hs100.png b/icons/hs100.png new file mode 100644 index 0000000000000000000000000000000000000000..a97685a51b1a454a8345e43047a5778c641894d4 GIT binary patch literal 308 zcmeAS@N?(olHy`uVBq!ia0vp^B0wz1!3HFCgzU0`6kC$Fy9wy$!fk$L9 z0|U1(2s1Lwnj--eWH0gbb!C6ZC@02m7}UOE4NyonGbEzKIX^cyHLnE7WngeFN=+1IquSOJkeVRPOfAc+#{ow)DTP2Ga&rGUdQA=qrRZtr6z@tn`}msUPc9+E;T# zat3^nnEPJ+-}lpLcXU=S;+@o!d}!u!KeO7IeL8aDXYv+_-K^NPHPQE^LTKmu`h$J* tr`*myb9y6R14qKEqYD`$7}gxNxWn)z-(9~$yUrNocu!Y9mvv4FO#rwBY9Igr literal 0 HcmV?d00001 diff --git a/index.html b/index.html new file mode 100644 index 0000000..8390474 --- /dev/null +++ b/index.html @@ -0,0 +1,59 @@ + + + + + + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..43003fb --- /dev/null +++ b/index.js @@ -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(); + }); + }); +}; \ No newline at end of file diff --git a/package.json b/package.json index 576ff59..27763ef 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "git ", + "name": "node-red-contrib-hs100", "version": "0.1.0", "description": "", "main": "index.js", @@ -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" + } } } From 37f41c83d9c6153f1cf2491753c6b0b83e7c53ae Mon Sep 17 00:00:00 2001 From: biddster Date: Mon, 30 Jan 2017 22:25:19 +0000 Subject: [PATCH 6/6] Update html. --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 8390474..4b04a8d 100644 --- a/index.html +++ b/index.html @@ -54,6 +54,6 @@ - \ No newline at end of file