2
0

refactor(socket): move on/off to dedicated actions

This commit is contained in:
Pierre CLEMENT
2018-01-03 13:05:01 +01:00
parent a33d616516
commit 8a40a6ad54
11 changed files with 715 additions and 66 deletions

View File

@@ -393,3 +393,87 @@
<li>Message to connect to a gateway out node.</li>
</ol>
</script>
<!-- The plug "on" Node -->
<script type="text/javascript">
RED.nodes.registerType('xiaomi-actions on',{
category: 'xiaomi actions',
color: '#64C4CD',
defaults: {
gateway: {value:"", type:"xiaomi-configurator"},
name: {value:""}
},
inputs:1,
outputs:1,
paletteLabel: "on",
icon: "function.png",
label: function() {
return this.name||"power on";
}
});
</script>
<script type="text/x-red" data-template-name="xiaomi-actions on">
<div class="form-row">
<label for="node-input-gateway"><i class="icon-tag"></i> Gateway</label>
<input type="text" id="node-input-gateway" placeholder="xiaomi gateway">
</div>
<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 on">
<p>
Turn input device to on.
Note: a gateway input node must be present and have receive a message to get gateway tokens and be able to do the action.
</p>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Message to connect to a gateway out node.</li>
</ol>
</script>
<!-- The plug "off" Node -->
<script type="text/javascript">
RED.nodes.registerType('xiaomi-actions off',{
category: 'xiaomi actions',
color: '#64C4CD',
defaults: {
gateway: {value:"", type:"xiaomi-configurator"},
name: {value:""}
},
inputs:1,
outputs:1,
paletteLabel: "off",
icon: "function.png",
label: function() {
return this.name||"power off";
}
});
</script>
<script type="text/x-red" data-template-name="xiaomi-actions off">
<div class="form-row">
<label for="node-input-gateway"><i class="icon-tag"></i> Gateway</label>
<input type="text" id="node-input-gateway" placeholder="xiaomi gateway">
</div>
<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 off">
<p>
Turn input device to off.
Note: a gateway input node must be present and have receive a message to get gateway tokens and be able to do the action.
</p>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Message to connect to a gateway out node.</li>
</ol>
</script>

View File

@@ -97,11 +97,35 @@ module.exports = (RED) => {
RED.nodes.createNode(this, config);
this.gateway = RED.nodes.getNode(config.gateway);
this.on('input', function(msg) {
miDevicesUtils.sendWritePayloadToGateway(this, msg, {
mid: 1000
});
this.on('input', (msg) => {
miDevicesUtils.sendWritePayloadToGateway(this, msg, { mid: 1000 });
});
}
RED.nodes.registerType("xiaomi-actions gateway_stop_sound", XiaomiActionGatewayStopSound);
/*********************************************
Turn device on
*********************************************/
function XiaomiActionPowerOn(config) {
RED.nodes.createNode(this, config);
this.gateway = RED.nodes.getNode(config.gateway);
this.on('input', (msg) => {
miDevicesUtils.sendWritePayloadToGateway(this, msg, { status: "on", sid: msg.sid});
});
}
RED.nodes.registerType("xiaomi-actions on", XiaomiActionPowerOn);
/*********************************************
Turn device off
*********************************************/
function XiaomiActionPowerOff(config) {
RED.nodes.createNode(this, config);
this.gateway = RED.nodes.getNode(config.gateway);
this.on('input', (msg) => {
miDevicesUtils.sendWritePayloadToGateway(this, msg, { status: "off", sid: msg.sid});
});
}
RED.nodes.registerType("xiaomi-actions off", XiaomiActionPowerOff);
}