Skip to content

Commit

Permalink
Merged release/0.3.0 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
biddster committed Feb 12, 2017
2 parents 25f0df2 + 8ac7be6 commit 0625841
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ Alternatively, use the Palette Manager in Node-RED.

Drag this node on to a worksheet and double click it. Enter the IP address of the plug on your network. Save and deploy.

To turn the HS100 on, send a message a message with the topic or payload set to `on`.

To turn the HS100 off, send a message a message with the topic or payload set to `off`.
# Actuation

## Turn on

To turn the HS100 on, send a message to this node's input with the topic or payload set to `on`.

## Turn off

To turn the HS100 off, send a message to this node's input with the topic or payload set to `off`.

## Obtain power consumption data

To obtain the power consumption, send a message to this node's input with the topic or payload set to `consumption`.
The consumption data will be sent via this node's output in `msg.payload`.
17 changes: 14 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
host: {value: ''}
},
inputs: 1,
outputs: 0,
outputs: 1,
icon: 'hs100.png',
label: function () {
return this.name || 'hs100';
Expand Down Expand Up @@ -67,8 +67,19 @@ <h1>Configuration</h1>

<p>Drag this node on to a worksheet and double click it. Enter the IP address of the plug on your network. Save and deploy.</p>

<p>To turn the HS100 on, send a message a message with the topic or payload set to <code>on</code>.</p>
<h1>Actuation</h1>

<p>To turn the HS100 off, send a message a message with the topic or payload set to <code>off</code>.</p>
<h2>Turn on</h2>

<p>To turn the HS100 on, send a message to this node's input with the topic or payload set to <code>on</code>.</p>

<h2>Turn off</h2>

<p>To turn the HS100 off, send a message to this node's input with the topic or payload set to <code>off</code>.</p>

<h2>Obtain power consumption data</h2>

<p>To obtain the power consumption, send a message to this node's input with the topic or payload set to `consumption`. The consumption data will
be sent via this node's output in <code>msg.payload</code>.</p>

</script>
38 changes: 31 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,41 @@ module.exports = function (RED) {
var plug = client.getPlug({host: config.host});

node.on('input', function (msg) {
var state = (msg.payload === 'on' || msg.topic === 'on');
plug.setPowerState(state);
node.status({
fill: 'green',
shape: state ? 'dot' : 'circle',
text: state ? 'on' : 'off'
});
if (msg.payload === 'consumption' || msg.topic === 'consumption') {
plug.getConsumption().then(function (data) {
node.send({payload: data});
}).catch(errorHandler);
} else if (msg.payload === 'on' || msg.topic === 'on') {
setPowerState(true);
} else if (msg.payload === 'off' || msg.topic === 'off') {
setPowerState(false);
} else {
errorHandler(new Error('Actuation must be one of [on, off, consumption]'));
}
});

node.on('close', function () {
client.socket.close();
});

function setPowerState(on) {
node.status({
fill: 'orange',
shape: on ? 'dot' : 'circle',
text: 'Turning ' + ( on ? 'on' : 'off')
});
plug.setPowerState(on).then(function () {
node.status({
fill: 'green',
shape: on ? 'dot' : 'circle',
text: on ? 'on' : 'off'
});
}).catch(errorHandler);
}

function errorHandler(err) {
node.error(err);
node.status({fill: 'red', shape: 'dot', text: err.message});
}
});
};
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-hs100",
"version": "0.2.1",
"version": "0.3.0",
"description": "",
"main": "index.js",
"keywords": ["node-red", "tp-link", "tplink", "hs100"],
Expand Down

0 comments on commit 0625841

Please sign in to comment.