feat(actions): add click and double click actions
This commit is contained in:
@@ -1,19 +1,3 @@
|
||||
<!--
|
||||
Copyright JS Foundation and other contributors, http://js.foundation
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
<!-- The Read Node -->
|
||||
<script type="text/x-red" data-template-name="xiaomi-actions read">
|
||||
<div class="form-row">
|
||||
@@ -56,6 +40,7 @@
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<!-- The get ids Node -->
|
||||
<script type="text/x-red" data-template-name="xiaomi-actions get_id_list">
|
||||
<div class="form-row">
|
||||
@@ -89,3 +74,104 @@
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<!-- The Single click Node -->
|
||||
<script type="text/x-red" data-template-name="xiaomi-actions click">
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="xiaomi-actions click">
|
||||
<p>
|
||||
Virtual single click for switch.
|
||||
Note: a gateway input node must be present to get gateway tokens.
|
||||
</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>sid
|
||||
<span class="property-type">string</span>
|
||||
</dt>
|
||||
<dd>Device <code>sid</code> to ask the report.</dd>
|
||||
<dt>gateway
|
||||
<span class="property-type">xiaomi-configurator</span>
|
||||
</dt>
|
||||
<dd>Device <code>sid</code> to ask the report.</dd>
|
||||
</dl>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<p class="node-ports">
|
||||
Message to connect to a gateway out node.
|
||||
</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-actions click',{
|
||||
category: 'xiaomi actions',
|
||||
color: '#64C4CD',
|
||||
defaults: {
|
||||
name: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
paletteLabel: "click",
|
||||
icon: "function.png",
|
||||
label: function() {
|
||||
return this.name||"click";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<!-- The Double click Node -->
|
||||
<script type="text/x-red" data-template-name="xiaomi-actions double_click">
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="xiaomi-actions double_click">
|
||||
<p>
|
||||
Virtual double click for switch.
|
||||
Note: a gateway input node must be present to get gateway tokens.
|
||||
</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>sid
|
||||
<span class="property-type">string</span>
|
||||
</dt>
|
||||
<dd>Device <code>sid</code> to ask the report.</dd>
|
||||
<dt>gateway
|
||||
<span class="property-type">xiaomi-configurator</span>
|
||||
</dt>
|
||||
<dd>Device <code>sid</code> to ask the report.</dd>
|
||||
</dl>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<p class="node-ports">
|
||||
Message to connect to a gateway out node.
|
||||
</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-actions double_click',{
|
||||
category: 'xiaomi actions',
|
||||
color: '#64C4CD',
|
||||
defaults: {
|
||||
name: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
paletteLabel: "double click",
|
||||
icon: "function.png",
|
||||
label: function() {
|
||||
return this.name||"double click";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var miDevicesUtils = require('../utils');
|
||||
|
||||
function XiaomiActionRead(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
@@ -9,7 +10,7 @@ module.exports = function(RED) {
|
||||
if(msg.sid) {
|
||||
msg.payload = {
|
||||
cmd: "read",
|
||||
sid: msg.payload
|
||||
sid: msg.sid
|
||||
};
|
||||
node.send(msg);
|
||||
}
|
||||
@@ -30,4 +31,46 @@ module.exports = function(RED) {
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-actions get_id_list", XiaomiActionGetIdList);
|
||||
|
||||
|
||||
function XiaomiActionSingleClick(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
var node = this;
|
||||
|
||||
node.on('input', function(msg) {
|
||||
if(msg.gateway && msg.sid && msg.gateway.key && msg.gateway.lastToken) {
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: {
|
||||
status: "click",
|
||||
sid: msg.sid,
|
||||
key: miDevicesUtils.getGatewayKey(msg.gateway.key, msg.gateway.lastToken)
|
||||
}
|
||||
};
|
||||
node.send(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-actions click", XiaomiActionSingleClick);
|
||||
|
||||
|
||||
function XiaomiActionDoubleClick(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
var node = this;
|
||||
|
||||
node.on('input', function(msg) {
|
||||
if(msg.gateway && msg.sid && msg.gateway.key && msg.gateway.lastToken) {
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: {
|
||||
status: "double_click",
|
||||
sid: msg.sid,
|
||||
key: miDevicesUtils.getGatewayKey(msg.gateway.key, msg.gateway.lastToken)
|
||||
}
|
||||
};
|
||||
node.send(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-actions double_click", XiaomiActionDoubleClick);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user