feat(gateway): addset light and play sounds
This commit is contained in:
@@ -1,133 +1,5 @@
|
||||
const miDevicesUtils = require('../src/utils');
|
||||
|
||||
module.exports = (RED) => {
|
||||
/*********************************************
|
||||
Read data from Gateway
|
||||
*********************************************/
|
||||
function XiaomiActionRead(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
if(msg.sid) {
|
||||
msg.payload = { cmd: "read", sid: msg.sid };
|
||||
this.send(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mi-devices-actions read", XiaomiActionRead);
|
||||
|
||||
/*********************************************
|
||||
Get registred ids of devices on gateway
|
||||
*********************************************/
|
||||
function XiaomiActionGetIdList(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
msg.payload = { cmd: "get_id_list" };
|
||||
node.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mi-devices-actions get_id_list", XiaomiActionGetIdList);
|
||||
|
||||
/*********************************************
|
||||
Virtual single click on a button
|
||||
*********************************************/
|
||||
function XiaomiActionSingleClick(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: { status: "click", sid: msg.sid }
|
||||
};
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mi-devices-actions click", XiaomiActionSingleClick);
|
||||
|
||||
/*********************************************
|
||||
Virtual Double click on a button
|
||||
*********************************************/
|
||||
function XiaomiActionDoubleClick(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: { status: "double_click", sid: msg.sid }
|
||||
};
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mi-devices-actions double_click", XiaomiActionDoubleClick);
|
||||
|
||||
/*********************************************
|
||||
Set the gateway light
|
||||
*********************************************/
|
||||
function XiaomiActionGatewayLight(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
this.color = config.color;
|
||||
this.brightness = config.brightness;
|
||||
|
||||
this.on('input', (msg) => {
|
||||
let color = msg.color || this.color;
|
||||
let brightness = msg.brightness || this.brightness;
|
||||
if(msg.sid) {
|
||||
let rgb = miDevicesUtils.computeColorValue(color.red, color.green, color.blue, brightness);
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: { rgb: rgb, sid: msg.sid }
|
||||
};
|
||||
}
|
||||
else {
|
||||
msg.payload = {
|
||||
color: miDevicesUtils.computeColorValue(color.red, color.green, color.blue),
|
||||
brightness: brightness
|
||||
};
|
||||
}
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mi-devices-actions gateway_light", XiaomiActionGatewayLight);
|
||||
|
||||
/*********************************************
|
||||
Play a sound on the gateway
|
||||
*********************************************/
|
||||
function XiaomiActionGatewaySound(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
this.mid = config.mid;
|
||||
this.volume = config.volume;
|
||||
|
||||
this.on('input', (msg) => {
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: {
|
||||
mid: parseInt(msg.mid || this.mid),
|
||||
volume: parseInt(msg.volume || this.volume),
|
||||
sid: msg.sid
|
||||
}
|
||||
};
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mi-devices-actions gateway_sound", XiaomiActionGatewaySound);
|
||||
|
||||
/*********************************************
|
||||
Stop playing a sound on the gateway
|
||||
*********************************************/
|
||||
function XiaomiActionGatewayStopSound(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: { mid: 1000, sid: msg.sid }
|
||||
};
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mi-devices-actions gateway_stop_sound", XiaomiActionGatewayStopSound);
|
||||
|
||||
/*********************************************
|
||||
Turn device on
|
||||
*********************************************/
|
||||
|
||||
Reference in New Issue
Block a user