doc(main): update documentation and flows
This commit is contained in:
43
dist/nodes/yeelight/YeelightConfigurator.js
vendored
Normal file
43
dist/nodes/yeelight/YeelightConfigurator.js
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const constants_1 = require("../constants");
|
||||
const YeelightServer_1 = require("../../devices/yeelight/YeelightServer");
|
||||
exports.default = (RED) => {
|
||||
class YeelightConfigurator {
|
||||
constructor(props) {
|
||||
RED.nodes.createNode(this, props);
|
||||
let { sid } = props;
|
||||
this.sid = parseInt(sid);
|
||||
if (this.sid) {
|
||||
this.setBulb();
|
||||
}
|
||||
let server = YeelightServer_1.YeelightServer.getInstance();
|
||||
server.on('yeelight-online', (sid) => {
|
||||
if (sid === this.sid) {
|
||||
this.setBulb();
|
||||
this.emit('bulb-online');
|
||||
}
|
||||
});
|
||||
server.on('yeelight-offline', (sid) => {
|
||||
if (sid === this.sid) {
|
||||
this._bulb = null;
|
||||
this.emit('bulb-offline');
|
||||
}
|
||||
});
|
||||
}
|
||||
setBulb() {
|
||||
this._bulb = YeelightServer_1.YeelightServer.getInstance().getBulb(this.sid);
|
||||
}
|
||||
get bulb() {
|
||||
return this._bulb;
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType(`${constants_1.Constants.NODES_PREFIX}-yeelight configurator`, YeelightConfigurator, {
|
||||
settings: {
|
||||
miDevicesYeelightConfiguratorDiscoveredBulbs: {
|
||||
value: YeelightServer_1.YeelightServer.getInstance().bulbs,
|
||||
exportable: true
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
64
dist/nodes/yeelight/YeelightOut.js
vendored
Normal file
64
dist/nodes/yeelight/YeelightOut.js
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const constants_1 = require("../constants");
|
||||
exports.default = (RED) => {
|
||||
class YeelightOut {
|
||||
constructor(props) {
|
||||
RED.nodes.createNode(this, props);
|
||||
this.yeelightConf = RED.nodes.getNode(props.yeelight);
|
||||
this.status({ fill: "red", shape: "ring", text: "offline" });
|
||||
if (this.yeelightConf.bulb) {
|
||||
this.yeelightOnline();
|
||||
}
|
||||
this.yeelightConf.on('bulb-online', () => this.yeelightOnline());
|
||||
this.yeelightConf.on('bulb-offline', () => this.yeelightOffline());
|
||||
this.setListener();
|
||||
}
|
||||
yeelightOnline() {
|
||||
this.status({ fill: "blue", shape: "dot", text: "online" });
|
||||
}
|
||||
yeelightOffline() {
|
||||
this.status({ fill: "red", shape: "ring", text: "offline" });
|
||||
}
|
||||
setListener() {
|
||||
this.on("input", (msg) => {
|
||||
let bulb = this.yeelightConf.bulb;
|
||||
if (msg.hasOwnProperty("payload") && bulb) {
|
||||
switch (msg.payload.action) {
|
||||
case 'turn_on':
|
||||
bulb.turnOn();
|
||||
break;
|
||||
case 'turn_off':
|
||||
bulb.turnOff();
|
||||
break;
|
||||
case 'toggle':
|
||||
bulb.toggle();
|
||||
break;
|
||||
case 'setLight':
|
||||
if (msg.payload.color !== undefined) {
|
||||
let rgb = msg.payload.color.blue | (msg.payload.color.green << 8) | (msg.payload.color.red << 16);
|
||||
let hex = '#' + (0x1000000 + rgb).toString(16).slice(1);
|
||||
bulb.setRGB(hex);
|
||||
}
|
||||
(msg.payload.brightness !== undefined) && bulb.setBrightness(Math.max(1, msg.payload.brightness));
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
/*(<any> this).on('input', (msg) => {
|
||||
if (this.yeelightConf.bulb) {
|
||||
|
||||
|
||||
if(msg.payload.color !== undefined) {
|
||||
// TODO: revoir la couleur
|
||||
this.yeelightConf.bulb.setRGB(msg.payload.color);
|
||||
}
|
||||
if(msg.payload.brightness !== undefined) {
|
||||
this.yeelightConf.bulb.setBrightness(msg.payload.brightness);
|
||||
}
|
||||
}
|
||||
});*/
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType(`${constants_1.Constants.NODES_PREFIX}-yeelight out`, YeelightOut);
|
||||
};
|
||||
BIN
dist/nodes/yeelight/icons/mi-yeelight.png
vendored
Normal file
BIN
dist/nodes/yeelight/icons/mi-yeelight.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
160
dist/nodes/yeelight/index.html
vendored
Normal file
160
dist/nodes/yeelight/index.html
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mi-devices-yeelight configurator', {
|
||||
category: 'config',
|
||||
defaults: {
|
||||
name: {value: ""},
|
||||
sid: {value: ""}
|
||||
},
|
||||
label: function () {
|
||||
return this.name || "yeelight conf";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
var foundBulbs = RED.settings.miDevicesYeelightConfiguratorDiscoveredBulbs;
|
||||
Object.keys(foundBulbs).forEach(function(sid) {
|
||||
var bulb = foundBulbs[sid];
|
||||
$('#discovered-bulbs').append('<option value="' + bulb.sid + '">' + (bulb.name || bulb.sid) + ' - ' + bulb.model + ' - ' + bulb.ip + '</option>');
|
||||
});
|
||||
$('#discovered-bulbs').on('change', function() {
|
||||
var sid = $('#discovered-bulbs').val();
|
||||
var bulb = foundBulbs[sid];
|
||||
$("#node-config-input-name").val(bulb && bulb.name);
|
||||
$("#node-config-input-sid").val(bulb && bulb.sid);
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mi-devices-yeelight configurator">
|
||||
<div class="form-row">
|
||||
<label for="discovered-bulbs"><i class="fa fa-search"></i> Found bulbs</label>
|
||||
<select id="discovered-bulbs">
|
||||
<option>- Select -</option>
|
||||
</select>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-config-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-sid"><i class="fa fa-barcode"></i> SID</label>
|
||||
<input type="text" id="node-config-input-sid" placeholder="sid">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mi-devices-yeelight configurator">
|
||||
<p>Xiaomi Yeelight configuration node.</p>
|
||||
<h3>Details</h3>
|
||||
<p>This configuration node is used by the Yeelight nodes. Here you can add
|
||||
devices with their device-id (SID), type and a description.</p>
|
||||
<p>At the moment the following devices are supported:
|
||||
<lu>
|
||||
<li>Humidity & Temperature sensor [sensor ht/]</li>
|
||||
<li>Body motion sensor [motion]</li>
|
||||
<li>Magnet contact sensor [contact]</li>
|
||||
<li>Wall socket plug (zigbee) [plug]</li>
|
||||
<li>Push button [switch]</li>
|
||||
</lu>
|
||||
</p>
|
||||
<p>To be able to receive messages from the Xiaomi gateway, you need to set the gateway
|
||||
in developer mode. Once in developer mode, the gateway sends JSON messages over the network as
|
||||
UDP packages. On the internet their are a lot of guides on how to put the gateway in developer mode.</p>
|
||||
<p>If you want to use the wall sockets, you need to set the key from the gateway. The key can be
|
||||
retrieved via the Xiaomi Home App when in developer mode. Enter the key here and it is used
|
||||
together with the token from the gateway's heartbeat message to recalculate the key to switch
|
||||
the plug. If you do not specify a key, the plug-node can not be used.</p>
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('mi-devices-yeelight out', {
|
||||
category: 'xiaomi in out',
|
||||
color: '#087F8A',
|
||||
defaults: {
|
||||
name: {value: ""},
|
||||
yeelight: {value:"", type:"mi-devices-yeelight configurator"}
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 0,
|
||||
paletteLabel: "yeelight out",
|
||||
icon: "mi-yeelight.png",
|
||||
align: "right",
|
||||
label: function () {
|
||||
return this.name || "yeelight out";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
function changeGateway() {
|
||||
var configNodeID = $('#node-input-gateway').val();
|
||||
if (configNodeID) {
|
||||
var configNode = RED.nodes.node(configNodeID);
|
||||
if(configNode) {
|
||||
if(!this.name) {
|
||||
$("#node-input-name").val(configNode.name);
|
||||
}
|
||||
$('#node-input-ip').val(configNode.ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$("#node-input-gateway").change(function () {
|
||||
changeGateway();
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="mi-devices-yeelight out">
|
||||
<div class="form-row">
|
||||
<label for="node-input-yeelight"><i class="fa fa-wrench"></i> Yeelight</label>
|
||||
<input type="text" id="node-input-yeelight" placeholder="yeelight">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mi-devices-yeelight out">
|
||||
<p>The Xiaomi Yeelight node</p>
|
||||
|
||||
<h3>Inputs</h3>
|
||||
<dl class="message-properties">
|
||||
<dt>payload
|
||||
<span class="property-type">object</span>
|
||||
</dt>
|
||||
<dd>
|
||||
When the message contains a <code>sid</code> field, the node will filter the input and output only if the <code>sid</code> is the device's sid.<br>
|
||||
<hr>
|
||||
If the message doesn't contain a <code>sid</code> field, the node will be used to inject <code>sid</code> and <code>gateway</code> fields in the incoming <code>msg</code>.<br>
|
||||
<hr>
|
||||
Input Gateway node produces message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code>.
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h3>Outputs</h3>
|
||||
<ol class="node-ports">
|
||||
<dl class="message-properties">
|
||||
<dt>payload <span class="property-type">object</span></dt>
|
||||
<dd>Data from gateway when used as a filter (see below).</dd>
|
||||
<dt>sid <span class="property-type">string</span></dt>
|
||||
<dd>Device SID.</dd>
|
||||
<dt>gateway <span class="property-type">object</span></dt>
|
||||
<dd>The <code>xiaomi-configurator</code> object where the device is registred.</dd>
|
||||
</dl>
|
||||
</ol>
|
||||
|
||||
<h4>Details</h4>
|
||||
<p>The incoming message is processed if the input <code>sid</code> matches the configured value for this device.</p>
|
||||
<p>Sample message:</p>
|
||||
<p><pre>{
|
||||
cmd: "report"
|
||||
model: "switch"
|
||||
sid: "158d000128b124"
|
||||
short_id: 56773
|
||||
data: {
|
||||
status: "click",
|
||||
batteryLevel: 23
|
||||
}
|
||||
}</pre></p>
|
||||
|
||||
</script>
|
||||
9
dist/nodes/yeelight/index.js
vendored
Normal file
9
dist/nodes/yeelight/index.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
const YeelightServer_1 = require("../../devices/yeelight/YeelightServer");
|
||||
const YeelightConfigurator_1 = require("./YeelightConfigurator");
|
||||
const YeelightOut_1 = require("./YeelightOut");
|
||||
module.exports = (RED) => {
|
||||
YeelightServer_1.YeelightServer.getInstance().discover();
|
||||
YeelightConfigurator_1.default(RED);
|
||||
YeelightOut_1.default(RED);
|
||||
};
|
||||
Reference in New Issue
Block a user