-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_attribute.js
35 lines (30 loc) · 1.2 KB
/
read_attribute.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
const {cap} = require('./utils')
module.exports = function(RED) {
function MatterReadAttr(config) {
RED.nodes.createNode(this, config);
var node = this;
node.controller = RED.nodes.getNode(config.controller);
node._id = BigInt(config.device.split('-')[0])
node._ep = config.device.split('-')[1] || 1
node.cluster = Number(config.cluster)
node.attr = cap(config.attr)
this.on('input', function(msg) {
node.controller.commissioningController.connectNode(node._id).then((conn) => {
const ep = conn.getDeviceById(Number(node._ep))
const clc = ep.getClusterClientById(Number(node.cluster))
try {
let command = eval(`clc.get${node.attr}Attribute`)
command()
.then((attr_resp) => {
msg.payload = attr_resp
node.send(msg)
})
.catch((e) => node.error(e))
} catch (error) {
node.error(error)
}
})
})
}
RED.nodes.registerType("matterreadattr",MatterReadAttr);
}