2
0

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
@@ -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);
}