Skip to content

Commit

Permalink
Added help for every node & bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadjimina committed Nov 21, 2018
1 parent f8a8a8b commit 0f63a21
Show file tree
Hide file tree
Showing 14 changed files with 664 additions and 120 deletions.
174 changes: 88 additions & 86 deletions README.md

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-mystrom",
"version": "1.0.0",
"version": "1.0.3",
"description": "myStrom nodes to controll all myStrom devices within Node-RED",
"author": "Hadjimina",
"homepage": "https://github.com/myStrom/node-red-contrib-mystrom",
Expand All @@ -15,9 +15,19 @@
"bugs": {
"url": "https://github.com/myStrom/node-red-contrib-mystrom/issues"
},
"dependencies": {
},
"keywords": ["node-red","node-red-contrib", "contrib", "mystrom", "iot","bulb", "switch", "strip","swisscom", "api"],
"dependencies": {},
"keywords": [
"node-red",
"node-red-contrib",
"contrib",
"mystrom",
"iot",
"bulb",
"switch",
"strip",
"swisscom",
"api"
],
"node-red": {
"nodes": {
"myStrom Bulb": "src/myStromBulb.js",
Expand Down
85 changes: 84 additions & 1 deletion src/myStromBulb.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,88 @@
</script>

<script type="text/x-red" data-help-name="myStrom Bulb">
<p>A node to control myStrom Bulbs</p>
<h4><a id="myStrom_Bulb_1"></a>myStrom Bulb</h4>
<p><img src="misc/preview-bulb.png" alt=""></p>
<p>Change the state of the bulb, change the colour and set the speed (ramp) of the transition</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th style="text-align:left">Valid requests</th>
<th style="text-align:left">Type</th>
<th style="text-align:left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>on</code></td>
<td style="text-align:left">string</td>
<td style="text-align:left">Turns the bulb on</td>
</tr>
<tr>
<td style="text-align:left"><code>off</code></td>
<td style="text-align:left">string</td>
<td style="text-align:left">Turns the bulb off</td>
</tr>
<tr>
<td style="text-align:left"><code>toggle</code></td>
<td style="text-align:left">string</td>
<td style="text-align:left">toggles the bulb</td>
</tr>
<tr>
<td style="text-align:left"><code>report</code></td>
<td style="text-align:left">string</td>
<td style="text-align:left">Get diagnostic information</td>
</tr>
<tr>
<td style="text-align:left"><code>color</code></td>
<td style="text-align:left">string</td>
<td style="text-align:left"><em>Needs additional data array</em>. See below for specification</td>
</tr>
</tbody>
</table>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th style="text-align:left">Valid data</th>
<th style="text-align:left">Type</th>
<th style="text-align:left">Need for request</th>
<th style="text-align:left">Format</th>
<th style="text-align:left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>color</code></td>
<td style="text-align:left">string</td>
<td style="text-align:left"><code>color</code></td>
<td style="text-align:left">Must be in RGBW format and start with a ‘#’</td>
<td style="text-align:left">Specifies the color which the bulb should be set to. Only used if the request is set to color.</td>
</tr>
<tr>
<td style="text-align:left"><code>ramp</code></td>
<td style="text-align:left">int</td>
<td style="text-align:left"><code>color</code></td>
<td style="text-align:left">Must be a positive number.</td>
<td style="text-align:left">Specify the transition time in miliseconds.</td>
</tr>
</tbody>
</table>
<h5><a id="Examples_20"></a>Examples:</h5>
<p>To turn the bulb on:</p>
<pre><code>{ &quot;ip&quot;: &quot;192.168.1.00&quot;,
&quot;mac&quot;: &quot;00:00:00:00:00:00&quot;
&quot;request&quot;: &quot;on&quot;
}
</code></pre>
<p>To turn the bulb red with a slow transition:</p>
<pre><code>{ &quot;ip&quot;: &quot;192.168.1.00&quot;,
&quot;mac&quot;: &quot;00:00:00:00:00:00&quot;
&quot;request&quot;: &quot;color&quot;,
&quot;data&quot;: {
&quot;color&quot;: &quot;#ff000000&quot;,
&quot;ramp&quot;: &quot;1000&quot;
}
}
</code></pre>
<p>The api documentatino of the bulb can be found <a href="https://mystrom.ch/wp-content/uploads/REST_API_WRB-2.txt" title="myStrom Bulb">here.</a></p>
</script>
28 changes: 24 additions & 4 deletions src/myStromBulb.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ module.exports = function(RED) {
var taskJSON = msg["payload"]


this.status({ fill: "blue", shape: "ring", text: "Using json" });
this.status({
fill: "blue",
shape: "ring",
text: "Using json"
});

if (!requests.isValid(taskJSON, this.DEVICE_TYPE)) {
taskJSON = { "ip": this.device.host, "mac": this.device.mac, "request": config.request, "data": { "color": config.color, "ramp": config.ramp } }
taskJSON = {
"ip": this.device.host,
"mac": this.device.mac,
"request": config.request,
"data": {
"color": config.color,
"ramp": config.ramp
}
}

this.status({ fill: "yellow", shape: "ring", text: "Using property" });
this.status({
fill: "yellow",
shape: "ring",
text: "Using property"
});


if (!requests.isValid(taskJSON, this.DEVICE_TYPE)) {
Expand All @@ -39,9 +55,13 @@ module.exports = function(RED) {
node.error("An error occured while sending")
}

node.send({ payload: str });
node.send({
payload: str
});
}



//CLOSE
this.on('close', function() {});
}
Expand Down
112 changes: 110 additions & 2 deletions src/myStromButton.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,114 @@ <h4> Long Click</h4>
</script>


<script type="text/x-red " data-help-name="myStrom Button ">
<p>A node to control myStrom Button</p>
<script type="text/x-red " data-help-name="myStrom Button">
<h4><a id="myStrom_Button_1"></a>myStrom Button</h4>
<p><img src="misc/preview-button.png" alt=""></p>
<p>Set the address to which the button should send a request for each button click or use the button click as input into node-RED.</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th style="text-align:left">Valid requests</th>
<th style="text-align:left">Type</th>
<th style="text-align:left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>set</code></td>
<td style="text-align:left">string</td>
<td style="text-align:left">Set the addresses the button should send requests to</td>
</tr>
<tr>
<td style="text-align:left"><code>report</code></td>
<td style="text-align:left">string</td>
<td style="text-align:left">Gets info from the button. (Button has to be in configuration mode)</td>
</tr>
</tbody>
</table>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th style="text-align:left">Valid data</th>
<th style="text-align:left">Type</th>
<th style="text-align:left">For request</th>
<th style="text-align:left">Format</th>
<th style="text-align:left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>single</code></td>
<td style="text-align:left">array</td>
<td style="text-align:left"><code>set</code> (optional)</td>
<td style="text-align:left">See Valid action below</td>
<td style="text-align:left">Specifies the url and data the button should send the request to.</td>
</tr>
<tr>
<td style="text-align:left"><code>double</code></td>
<td style="text-align:left">array</td>
<td style="text-align:left"><code>set</code> (optional)</td>
<td style="text-align:left">See Valid action below</td>
<td style="text-align:left">Specifies the url and data the button should send the request to.</td>
</tr>
<tr>
<td style="text-align:left"><code>long</code></td>
<td style="text-align:left">array</td>
<td style="text-align:left"><code>set</code> (optional)</td>
<td style="text-align:left">See Valid action below</td>
<td style="text-align:left">Specifies the url and data the button should send the request to.</td>
</tr>
</tbody>
</table>
<p>Not all of these parameters have to be specified all the time. You can have 1 or all of them. It does not matter.</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th style="text-align:left">Valid action</th>
<th style="text-align:left">Type</th>
<th style="text-align:left">Needed for data</th>
<th style="text-align:left">Format</th>
<th style="text-align:left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>url</code></td>
<td style="text-align:left">string</td>
<td style="text-align:left"><code>single</code>,<code>double</code>,<code>long</code>,<code>touch</code></td>
<td style="text-align:left">&lt;ip address&gt; or &lt; ip address &gt;:&lt; port &gt;</td>
<td style="text-align:left">Specifies the url and port to which the request should be sent</td>
</tr>
<tr>
<td style="text-align:left"><code>url-data</code></td>
<td style="text-align:left">string</td>
<td style="text-align:left"><code>single</code>,<code>double</code>,<code>long</code>,<code>touch</code> (optional)</td>
<td style="text-align:left">key1=value1&amp;key2=value2&amp;…</td>
<td style="text-align:left">Specifies the data that should be sent to the address</td>
</tr>
</tbody>
</table>
<h5><a id="Examples_25"></a>Examples:</h5>
<p>Set single click to wire output, send get request to <a href="http:https://google.com">google.com</a> with double click and send post request to 192.168.1.2 on port 9000 with data foo1=bar1&amp;foo2=bar2 on long click:</p>
<pre><code>{
&quot;ip&quot;: &quot;192.168.1.122&quot;,
&quot;mac&quot;: &quot;5C:CF:7F:CB:A9:AA&quot;,
&quot;request&quot;: &quot;set&quot;,
&quot;data&quot;: {
&quot;single&quot;: {
&quot;url&quot;: &quot;wire&quot;,
&quot;url-data&quot;: &quot;&quot;
},
&quot;double&quot;: {
&quot;url&quot;: &quot;wire&quot;,
&quot;url-data&quot;: &quot;&quot;
},
&quot;long&quot;: {
&quot;url&quot;: &quot;192.168.1.2:9000&quot;,
&quot;url-data&quot;: &quot;foo1=bar1&amp;foo2=bar2&quot;
}
}
}
</code></pre>
<p>The api documentatino of the Button+ can be found <a href="https://mystrom.ch/wp-content/uploads/REST_API_WBP-4.txt" title="myStrom Button strip">here.</a></p>
</script>
39 changes: 34 additions & 5 deletions src/myStromButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,49 @@ module.exports = function(RED) {
require('../utils/helpers').setupNodeMacPairs(node)
var taskJSON = msg["payload"]

this.status({ fill: "blue", shape: "ring", text: "Using json" });
this.status({
fill: "blue",
shape: "ring",
text: "Using json"
});

if (!requests.isValid(taskJSON, this.DEVICE_TYPE)) {

taskJSON = {
'ip': this.device.host,
'mac': this.device.mac,
'request': config.request,
'data': { 'single': { 'url': config.singleURL, 'url-data': config.singleData }, 'double': { 'url': config.doubleURL, 'url-data': config.doubleData }, 'long': { 'url': config.longURL, 'url-data': config.longData }, 'touch': { 'url': config.touchURL, 'url-data': config.touchData } }
'data': {
'single': {
'url': config.singleURL,
'url-data': config.singleData
},
'double': {
'url': config.doubleURL,
'url-data': config.doubleData
},
'long': {
'url': config.longURL,
'url-data': config.longData
},
'touch': {
'url': config.touchURL,
'url-data': config.touchData
}
}
}
this.status({ fill: "yellow", shape: "ring", text: "Using property" });
this.status({
fill: "yellow",
shape: "ring",
text: "Using property"
});

if (!requests.isValid(taskJSON, this.DEVICE_TYPE)) {
node.error("Conversion from property to json failed")
}
}

console.log(taskJSON);

helpers.setupWiredListFromJSON(taskJSON, node)
helpers.setupNodeMacPairs(node)
requests.doAsync(back, this.DEVICE_TYPE, taskJSON, node)
Expand All @@ -48,7 +73,9 @@ module.exports = function(RED) {
if (str["success"] == "false") {
node.error("An error occured while sending")
}
node.send({ payload: str });
node.send({
payload: str
});
}

//CLOSE
Expand All @@ -59,8 +86,10 @@ module.exports = function(RED) {


RED.httpAdmin.post("/buttons", function(req, res) {

var request = require('../utils/requests')
req = req.body

var DEVICE_TYPE = 'button'
res.json(request.handleRequest(req, DEVICE_TYPE))
});
Expand Down
Loading

0 comments on commit 0f63a21

Please sign in to comment.