feat(gateway): add play/stop sounds

This commit is contained in:
Pierre CLEMENT
2018-01-01 21:33:06 +01:00
parent 5732c80039
commit c7076ab5f9
2 changed files with 180 additions and 0 deletions

View File

@@ -241,3 +241,133 @@
<li>Message to connect to a gateway out node.</li>
</ol>
</script>
<!-- The Gateway sound Node -->
<script type="text/javascript">
RED.nodes.registerType('xiaomi-actions gateway_sound', {
category: 'xiaomi actions',
color: '#64C4CD',
defaults: {
gateway: {value:"", type:"xiaomi-configurator"},
name: {value: ""},
mid: {value: ""},
volume: {value: ""}
},
inputs: 1,
outputs: 1,
paletteLabel: "play sound",
icon: "function.png",
label: function () {
return this.name || "play sound";
}
});
</script>
<script type="text/x-red" data-template-name="xiaomi-actions gateway_sound">
<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>
<div class="form-row">
<label for="node-input-mid"><i class="icon-tag"></i> Sound</label>
<select id="node-input-mid">
<option value="0">Police car tone 1</option>
<option value="1">Police car tone 2</option>
<option value="2">Safety incident sound</option>
<option value="3">Missile countdown</option>
<option value="4">Ghost cry</option>
<option value="5">Sniper rifle</option>
<option value="6">Battle sound</option>
<option value="7">Air raid alarm</option>
<option value="8">Barking</option>
<option value="10">Doorbell tone</option>
<option value="11">Door knocking tone</option>
<option value="12">Funny tone</option>
<option value="13">Alarm clock tone</option>
<option value="20">MiMix</option>
<option value="21">Enthusisatic</option>
<option value="22">GuitarClassic</option>
<option value="23">IceWorldPiano</option>
<option value="24">LeisureTime</option>
<option value="25">ChildHood</option>
<option value="26">MorningStreamLet</option>
<option value="27">MusicBox</option>
<option value="28">Orange</option>
<option value="29">Thinker</option>
</select>
</div>
<div class="form-row">
<label for="node-input-volume"><i class="icon-tag"></i> Volume</label>
<input type="range" id="node-input-volume" min="0" max="100">
</div>
</script>
<script type="text/x-red" data-help-name="xiaomi-actions gateway_sound">
<p>Play a sound on the gateway.
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>Inputs</h3>
<dl class="message-properties">
<dt>mid
<span class="property-type">number</span>
</dt>
<dd>Music ID (user define sounds start from <code>1001</code>, <code>1000</code> means stop).</dd>
<dt>volume
<span class="property-type">number</span>
</dt>
<dd>Playing volume, between <code>0</code> and <code>100</code>.</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Message to connect to a gateway out node.</li>
</ol>
</script>
<!-- The Gateway stop sound Node -->
<script type="text/javascript">
RED.nodes.registerType('xiaomi-actions gateway_stop_sound',{
category: 'xiaomi actions',
color: '#64C4CD',
defaults: {
gateway: {value:"", type:"xiaomi-configurator"},
name: {value:""}
},
inputs:1,
outputs:1,
paletteLabel: "stop sound",
icon: "function.png",
label: function() {
return this.name||"stop sound";
}
});
</script>
<script type="text/x-red" data-template-name="xiaomi-actions gateway_stop_sound">
<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 gateway_stop_sound">
<p>
Stop current playing sound on the gateway.
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

@@ -98,4 +98,54 @@ module.exports = function(RED) {
});
}
RED.nodes.registerType("xiaomi-actions gateway_light", XiaomiActionGatewayLight);
function XiaomiActionGatewaySound(config) {
RED.nodes.createNode(this, config);
this.gateway = RED.nodes.getNode(config.gateway);
this.mid = config.mid;
this.volume = config.volume;
var node = this;
node.on('input', function(msg) {
if(node.gateway && node.gateway.sid && node.gateway.key && node.gateway.lastToken) {
msg.payload = {
cmd: "write",
data: {
mid: parseInt(msg.mid || node.mid),
volume: parseInt(msg.volume || node.volume),
sid: node.gateway.sid,
key: miDevicesUtils.getGatewayKey(node.gateway.key, node.gateway.lastToken)
}
};
node.send(msg);
}
});
}
RED.nodes.registerType("xiaomi-actions gateway_sound", XiaomiActionGatewaySound);
function XiaomiActionGatewayStopSound(config) {
RED.nodes.createNode(this, config);
this.gateway = RED.nodes.getNode(config.gateway);
var node = this;
node.on('input', function(msg) {
if(node.gateway && node.gateway.sid && node.gateway.key && node.gateway.lastToken) {
msg.payload = {
cmd: "write",
data: {
mid: 1000,
sid: node.gateway.sid,
key: miDevicesUtils.getGatewayKey(node.gateway.key, node.gateway.lastToken)
}
};
node.send(msg);
}
});
}
RED.nodes.registerType("xiaomi-actions gateway_stop_sound", XiaomiActionGatewayStopSound);
}