-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller.js
59 lines (52 loc) · 2.21 KB
/
controller.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const { Environment, Logger, singleton, StorageService, Time } = require( "@matter/main");
const { BasicInformationCluster, DescriptorCluster, GeneralCommissioning, OnOff } = require( "@matter/main/clusters");
const { ClusterClientObj, ControllerCommissioningFlowOptions } = require("@matter/main/protocol")
const { ManualPairingCodeCodec, QrPairingCodeCodec, NodeId } = require("@matter/main/types")
//Some parts of the controller are still in the legacy packages
var { CommissioningController, NodeCommissioningOptions } = require("@project-chip/matter.js")
var { NodeStates } = require("@project-chip/matter.js/device")
const environment = Environment.default;
module.exports = function(RED) {
function MatterController(config) {
RED.nodes.createNode(this, config);
var node = this;
node.started = false
node.networkInterface = config.networkInterface
node.storageLocation = config.storageLocation
switch (config.logLevel) {
case "FATAL":
Logger.defaultLogLevel = 5;
break;
case "ERROR":
Logger.defaultLogLevel = 4;
break;
case "WARN":
Logger.defaultLogLevel = 3;
break;
case "INFO":
Logger.defaultLogLevel = 1;
break;1
case "DEBUG":
Logger.defaultLogLevel = 0;
break;
}
Environment.default.vars.set('mdns.networkInterface', node.networkInterface);
let ss = environment.get(StorageService);
if (node.storageLocation){
ss.location = node.storageLocation;
environment.set(StorageService, ss)
node.log(`Using Custom Storage Location: ${ss.location}`)
} else {
node.log(`Using Default Storage Location: ${ss.location}`)
}
node.commissioningController = new CommissioningController({
environment: {
environment,
id: node.id
},
autoConnect: false,
})
node.commissioningController.start().then(() => {node.started = true})
}
RED.nodes.registerType("mattercontroller",MatterController);
}