-
Notifications
You must be signed in to change notification settings - Fork 2
/
mijia-filter.js
33 lines (25 loc) · 1.08 KB
/
mijia-filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module.exports = function (RED) {
"use strict";
const { Parser, EventTypes, SERVICE_DATA_UUID } = require("./parser");
function MijiaFilterNode(config) {
RED.nodes.createNode(this, config);
let node = this;
node.on('input', function (msg, send, done) {
send = send || function(){ node.send.apply(node, arguments)}
const { advertisement: { serviceData } = {}, address } = msg.payload || {};
const miServiceData = serviceData && serviceData.find(data => data.uuid.toLowerCase() === SERVICE_DATA_UUID);
if (miServiceData) {
try {
let data = new Parser(miServiceData.data).parse().event;
let msg = { payload: { data: data, address: address}};
send(msg);
} catch (e) {
}
}
if (done) {
done();
}
});
}
RED.nodes.registerType("Mijia BLE Filter", MijiaFilterNode);
}