feat(devices): handle yeelight basic support
Delete gateway in action config. Close #4, #8 and #9
This commit is contained in:
BIN
node-red-contrib-xiaomi-actions/icons/mi-toggle.png
Normal file
BIN
node-red-contrib-xiaomi-actions/icons/mi-toggle.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
@@ -86,10 +86,7 @@
|
||||
</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 and have receive a message to get gateway tokens and be able to do the action.
|
||||
</p>
|
||||
<p>Virtual single click for switch.</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
@@ -136,10 +133,7 @@
|
||||
</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 and have receive a message to get gateway tokens and be able to do the action.
|
||||
</p>
|
||||
<p>Virtual double click for switch.</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
@@ -183,7 +177,6 @@
|
||||
category: 'xiaomi actions',
|
||||
color: '#64C4CD',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"xiaomi-configurator"},
|
||||
name: {value: ""},
|
||||
brightness: {value: 100},
|
||||
hexRgbColor: {value: "#ffffff"},
|
||||
@@ -211,10 +204,6 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="xiaomi-actions gateway_light">
|
||||
<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">
|
||||
@@ -230,9 +219,7 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="xiaomi-actions gateway_light">
|
||||
<p>Change the light of 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>
|
||||
<p>Change the light of the gateway.</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
@@ -271,7 +258,6 @@
|
||||
category: 'xiaomi actions',
|
||||
color: '#64C4CD',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"xiaomi-configurator"},
|
||||
name: {value: ""},
|
||||
mid: {value: ""},
|
||||
volume: {value: ""}
|
||||
@@ -287,10 +273,6 @@
|
||||
</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">
|
||||
@@ -330,9 +312,7 @@
|
||||
</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>
|
||||
<p>Play a sound on the gateway.</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
@@ -359,7 +339,6 @@
|
||||
category: 'xiaomi actions',
|
||||
color: '#64C4CD',
|
||||
defaults: {
|
||||
gateway: {value:"", type:"xiaomi-configurator"},
|
||||
name: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
@@ -372,10 +351,6 @@
|
||||
});
|
||||
</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">
|
||||
@@ -385,7 +360,6 @@
|
||||
<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>
|
||||
@@ -395,13 +369,12 @@
|
||||
</script>
|
||||
|
||||
|
||||
<!-- The plug "on" Node -->
|
||||
<!-- The "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,
|
||||
@@ -414,10 +387,6 @@
|
||||
});
|
||||
</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">
|
||||
@@ -427,23 +396,21 @@
|
||||
<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>
|
||||
<li>Message to connect to a gateway/yeelight out node.</li>
|
||||
</ol>
|
||||
</script>
|
||||
|
||||
|
||||
<!-- The plug "off" Node -->
|
||||
<!-- The "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,
|
||||
@@ -456,10 +423,6 @@
|
||||
});
|
||||
</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">
|
||||
@@ -469,11 +432,44 @@
|
||||
<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>
|
||||
<li>Message to connect to a gateway/yeelight out node.</li>
|
||||
</ol>
|
||||
</script>
|
||||
|
||||
|
||||
<!-- The "toggle" Node -->
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xiaomi-actions toggle',{
|
||||
category: 'xiaomi actions',
|
||||
color: '#64C4CD',
|
||||
defaults: {
|
||||
name: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
paletteLabel: "toggle",
|
||||
icon: "mi-toggle.png",
|
||||
label: function() {
|
||||
return this.name||"toggle power";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script type="text/x-red" data-template-name="xiaomi-actions toggle">
|
||||
<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 toggle">
|
||||
<p>Toggle device.</p>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<ol class="node-ports">
|
||||
<li>Message to connect to a gateway/yeelight out node.</li>
|
||||
</ol>
|
||||
</script>
|
||||
|
||||
@@ -36,8 +36,11 @@ module.exports = (RED) => {
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
this.gateway = msg.gateway;
|
||||
miDevicesUtils.sendWritePayloadToGateway(this, msg, {status: "click", sid: msg.sid});
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: { status: "click", sid: msg.sid }
|
||||
};
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-actions click", XiaomiActionSingleClick);
|
||||
@@ -49,7 +52,11 @@ module.exports = (RED) => {
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
miDevicesUtils.sendWritePayloadToGateway(this, msg, {status: "double_click", sid: msg.sid});
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: { status: "double_click", sid: msg.sid }
|
||||
};
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-actions double_click", XiaomiActionDoubleClick);
|
||||
@@ -59,15 +66,26 @@ module.exports = (RED) => {
|
||||
*********************************************/
|
||||
function XiaomiActionGatewayLight(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
this.gateway = RED.nodes.getNode(config.gateway);
|
||||
this.color = RED.nodes.getNode(config.color);
|
||||
this.brightness = RED.nodes.getNode(config.brightness);
|
||||
this.color = config.color;
|
||||
this.brightness = config.brightness;
|
||||
|
||||
this.on('input', (msg) => {
|
||||
let color = msg.color || this.color;
|
||||
let brightness = msg.brightness || this.brightness;
|
||||
let rgb = miDevicesUtils.computeColorValue(brightness, color.red, color.green, color.blue);
|
||||
miDevicesUtils.sendWritePayloadToGateway(this, msg, {rgb: rgb});
|
||||
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("xiaomi-actions gateway_light", XiaomiActionGatewayLight);
|
||||
@@ -77,15 +95,19 @@ module.exports = (RED) => {
|
||||
*********************************************/
|
||||
function XiaomiActionGatewaySound(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
this.gateway = RED.nodes.getNode(config.gateway);
|
||||
this.mid = config.mid;
|
||||
this.volume = config.volume;
|
||||
|
||||
this.on('input', (msg) => {
|
||||
miDevicesUtils.sendWritePayloadToGateway(this, msg, {
|
||||
mid: parseInt(msg.mid || this.mid),
|
||||
volume: parseInt(msg.volume || this.volume)
|
||||
});
|
||||
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("xiaomi-actions gateway_sound", XiaomiActionGatewaySound);
|
||||
@@ -95,10 +117,13 @@ module.exports = (RED) => {
|
||||
*********************************************/
|
||||
function XiaomiActionGatewayStopSound(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
this.gateway = RED.nodes.getNode(config.gateway);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
miDevicesUtils.sendWritePayloadToGateway(this, msg, { mid: 1000 });
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: { mid: 1000, sid: msg.sid }
|
||||
};
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-actions gateway_stop_sound", XiaomiActionGatewayStopSound);
|
||||
@@ -108,16 +133,18 @@ module.exports = (RED) => {
|
||||
*********************************************/
|
||||
function XiaomiActionPowerOn(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
this.gateway = RED.nodes.getNode(config.gateway);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
if(msg.sid){
|
||||
miDevicesUtils.sendWritePayloadToGateway(this, msg, { status: "on", sid: msg.sid});
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: { status: "on", sid: msg.sid }
|
||||
};
|
||||
}
|
||||
else {
|
||||
msg.payload = "off";
|
||||
this.send(msg);
|
||||
msg.payload = "on";
|
||||
}
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-actions on", XiaomiActionPowerOn);
|
||||
@@ -127,17 +154,32 @@ module.exports = (RED) => {
|
||||
*********************************************/
|
||||
function XiaomiActionPowerOff(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
this.gateway = RED.nodes.getNode(config.gateway);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
if(msg.sid){
|
||||
miDevicesUtils.sendWritePayloadToGateway(this, msg, { status: "off", sid: msg.sid});
|
||||
msg.payload = {
|
||||
cmd: "write",
|
||||
data: { status: "off", sid: msg.sid }
|
||||
};
|
||||
}
|
||||
else {
|
||||
msg.payload = "off";
|
||||
this.send(msg);
|
||||
}
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-actions off", XiaomiActionPowerOff);
|
||||
|
||||
/*********************************************
|
||||
Toggle device
|
||||
*********************************************/
|
||||
function XiaomiActionToggle(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
this.on('input', (msg) => {
|
||||
msg.payload = "toggle";
|
||||
this.send(msg);
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("xiaomi-actions toggle", XiaomiActionToggle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user