feat(all): send messages as parts
This commit is contained in:
2
dist/devices/gateway/Magnet.js
vendored
2
dist/devices/gateway/Magnet.js
vendored
@@ -21,7 +21,7 @@ class Magnet extends GatewaySubdevice_1.GatewaySubdevice {
|
|||||||
super.handleMessage(msg);
|
super.handleMessage(msg);
|
||||||
if (msg.isReadAck() || msg.isReport()) {
|
if (msg.isReadAck() || msg.isReport()) {
|
||||||
let data = msg.data;
|
let data = msg.data;
|
||||||
// mintime
|
// TODO: mintime
|
||||||
if (this.status !== data.status) {
|
if (this.status !== data.status) {
|
||||||
this.status = data.status;
|
this.status = data.status;
|
||||||
this.emit('values-updated', this.sid);
|
this.emit('values-updated', this.sid);
|
||||||
|
|||||||
22
dist/nodes/gateway-subdevices/All.js
vendored
22
dist/nodes/gateway-subdevices/All.js
vendored
@@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const constants_1 = require("../constants");
|
const constants_1 = require("../constants");
|
||||||
|
const uniqid = require("uniqid");
|
||||||
exports.default = (RED) => {
|
exports.default = (RED) => {
|
||||||
class All {
|
class All {
|
||||||
static getOnlyModelsValue(input) {
|
static getOnlyModelsValue(input) {
|
||||||
@@ -12,28 +13,35 @@ exports.default = (RED) => {
|
|||||||
}
|
}
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
RED.nodes.createNode(this, props);
|
RED.nodes.createNode(this, props);
|
||||||
this.gateway = RED.nodes.getNode(props.gateway);
|
this.gatewayConf = RED.nodes.getNode(props.gateway);
|
||||||
this.onlyModels = All.getOnlyModelsValue(props.onlyModels || []);
|
this.onlyModels = All.getOnlyModelsValue(props.onlyModels || []);
|
||||||
this.excludedSids = props.excludedSids;
|
this.excludedSids = props.excludedSids;
|
||||||
this.setMessageListener();
|
this.setMessageListener();
|
||||||
}
|
}
|
||||||
setMessageListener() {
|
setMessageListener() {
|
||||||
this.on('input', (msg) => {
|
this.on('input', (msg) => {
|
||||||
if (this.gateway) {
|
if (this.gatewayConf) {
|
||||||
// Filter input
|
// Filter input
|
||||||
if (msg.payload && msg.payload.model && msg.payload.sid) {
|
if (msg.payload && msg.payload.model && msg.payload.sid) {
|
||||||
if (!this.isDeviceValid(msg.payload)) {
|
if (!this.isDeviceValid(msg.payload.sid)) {
|
||||||
msg = null;
|
msg = null;
|
||||||
}
|
}
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Object.keys(this.gateway.deviceList || {})
|
let partsId = uniqid();
|
||||||
|
Object.keys(this.gatewayConf.deviceList || {})
|
||||||
.filter((sid) => this.isDeviceValid(sid))
|
.filter((sid) => this.isDeviceValid(sid))
|
||||||
.forEach((sid) => {
|
.forEach((sid, i, subSids) => {
|
||||||
let curMsg = Object.assign({}, msg);
|
let curMsg = Object.assign({}, msg);
|
||||||
|
delete curMsg._msgid;
|
||||||
|
curMsg.parts = {
|
||||||
|
id: partsId,
|
||||||
|
index: i,
|
||||||
|
count: subSids.length,
|
||||||
|
};
|
||||||
curMsg.sid = sid;
|
curMsg.sid = sid;
|
||||||
curMsg.gateway = this.gateway;
|
curMsg.gateway = this.gatewayConf;
|
||||||
this.send(curMsg);
|
this.send(curMsg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -44,7 +52,7 @@ exports.default = (RED) => {
|
|||||||
if ((!this.onlyModels || this.onlyModels.length == 0) && (!this.excludedSids || this.excludedSids.length == 0)) {
|
if ((!this.onlyModels || this.onlyModels.length == 0) && (!this.excludedSids || this.excludedSids.length == 0)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let device = this.gateway.deviceList[sid];
|
let device = this.gatewayConf.deviceList[sid];
|
||||||
// Is excluded
|
// Is excluded
|
||||||
if ((this.excludedSids && this.excludedSids.length != 0) && this.excludedSids.indexOf(sid) >= 0) {
|
if ((this.excludedSids && this.excludedSids.length != 0) && this.excludedSids.indexOf(sid) >= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cryptojs": "^2.5.3",
|
"cryptojs": "^2.5.3",
|
||||||
"miio": "^0.15.4",
|
"miio": "^0.15.4",
|
||||||
|
"uniqid": "^4.1.1",
|
||||||
"yeelight-wifi": "^2.3.0"
|
"yeelight-wifi": "^2.3.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ export class Magnet extends GatewaySubdevice {
|
|||||||
super.handleMessage(msg);
|
super.handleMessage(msg);
|
||||||
if (msg.isReadAck() || msg.isReport()) {
|
if (msg.isReadAck() || msg.isReport()) {
|
||||||
let data = <GatewayMessageReadAckMagnetData> msg.data;
|
let data = <GatewayMessageReadAckMagnetData> msg.data;
|
||||||
// mintime
|
|
||||||
|
// TODO: mintime
|
||||||
if (this.status !== data.status) {
|
if (this.status !== data.status) {
|
||||||
this.status = data.status;
|
this.status = data.status;
|
||||||
this.emit('values-updated', this.sid);
|
this.emit('values-updated', this.sid);
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import {Red, NodeProperties} from "node-red";
|
import {Red, NodeProperties} from "node-red";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
|
import * as uniqid from 'uniqid';
|
||||||
|
|
||||||
export default (RED: Red) => {
|
export default (RED: Red) => {
|
||||||
class All {
|
class All {
|
||||||
protected gateway: any;
|
protected gatewayConf: any;
|
||||||
protected onlyModels: string[];
|
protected onlyModels: string[];
|
||||||
protected excludedSids: string[];
|
protected excludedSids: string[];
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ export default (RED: Red) => {
|
|||||||
|
|
||||||
constructor(props: NodeProperties) {
|
constructor(props: NodeProperties) {
|
||||||
RED.nodes.createNode(<any> this, props);
|
RED.nodes.createNode(<any> this, props);
|
||||||
this.gateway = RED.nodes.getNode((<any> props).gateway);
|
this.gatewayConf = RED.nodes.getNode((<any> props).gateway);
|
||||||
this.onlyModels = All.getOnlyModelsValue((<any> props).onlyModels || []);
|
this.onlyModels = All.getOnlyModelsValue((<any> props).onlyModels || []);
|
||||||
this.excludedSids = (<any> props).excludedSids;
|
this.excludedSids = (<any> props).excludedSids;
|
||||||
|
|
||||||
@@ -26,22 +27,31 @@ export default (RED: Red) => {
|
|||||||
|
|
||||||
protected setMessageListener() {
|
protected setMessageListener() {
|
||||||
(<any> this).on('input', (msg) => {
|
(<any> this).on('input', (msg) => {
|
||||||
if (this.gateway) {
|
if (this.gatewayConf) {
|
||||||
// Filter input
|
// Filter input
|
||||||
if (msg.payload && msg.payload.model && msg.payload.sid) {
|
if (msg.payload && msg.payload.model && msg.payload.sid) {
|
||||||
if (!this.isDeviceValid(msg.payload)) {
|
if (!this.isDeviceValid(msg.payload.sid)) {
|
||||||
msg = null;
|
msg = null;
|
||||||
}
|
}
|
||||||
(<any> this).send(msg);
|
(<any> this).send(msg);
|
||||||
}
|
}
|
||||||
// Prepare for request
|
// Prepare for request
|
||||||
else {
|
else {
|
||||||
Object.keys(this.gateway.deviceList || {})
|
let partsId = uniqid();
|
||||||
|
Object.keys(this.gatewayConf.deviceList || {})
|
||||||
.filter((sid) => this.isDeviceValid(sid))
|
.filter((sid) => this.isDeviceValid(sid))
|
||||||
.forEach((sid) => {
|
.forEach((sid, i, subSids) => {
|
||||||
let curMsg = Object.assign({}, msg);
|
let curMsg = Object.assign({}, msg);
|
||||||
|
delete curMsg._msgid;
|
||||||
|
|
||||||
|
curMsg.parts = {
|
||||||
|
id: partsId,
|
||||||
|
index: i,
|
||||||
|
count: subSids.length,
|
||||||
|
};
|
||||||
curMsg.sid = sid;
|
curMsg.sid = sid;
|
||||||
curMsg.gateway = this.gateway;
|
curMsg.gateway = this.gatewayConf;
|
||||||
|
|
||||||
(<any> this).send(curMsg);
|
(<any> this).send(curMsg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -53,7 +63,8 @@ export default (RED: Red) => {
|
|||||||
if ((!this.onlyModels || this.onlyModels.length == 0) && (!this.excludedSids || this.excludedSids.length == 0)) {
|
if ((!this.onlyModels || this.onlyModels.length == 0) && (!this.excludedSids || this.excludedSids.length == 0)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let device = this.gateway.deviceList[sid];
|
let device = this.gatewayConf.deviceList[sid];
|
||||||
|
|
||||||
// Is excluded
|
// Is excluded
|
||||||
if ((this.excludedSids && this.excludedSids.length != 0) && this.excludedSids.indexOf(sid) >= 0) {
|
if ((this.excludedSids && this.excludedSids.length != 0) && this.excludedSids.indexOf(sid) >= 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user