-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomekit-pairing-data.js
More file actions
28 lines (26 loc) · 935 Bytes
/
homekit-pairing-data.js
File metadata and controls
28 lines (26 loc) · 935 Bytes
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
module.exports = function(RED) {
function PairingDataNode(n) {
const { JsonDB, Config } = require('node-json-db');
RED.nodes.createNode(this,n);
this.name = n.name;
this.DBName = n.DBName;
var userDir = RED.settings.userDir;
const db = new JsonDB(new Config(`${userDir}/HomeKitPairingData/${this.DBName}`,true,true,'/'));
this.SaveData = async function(DeviceID, PairingData) {
await db.push(`/${DeviceID}`,PairingData);
};
this.GetData = async function(DeviceID){
try{
let data = await db.getData(`/${DeviceID}`);
return data;
}
catch(e){
return false;
}
}
this.RemoveData = async function(DeviceID){
await db.delete(`/${DeviceID}`);
}
}
RED.nodes.registerType("homekit-pairing-data",PairingDataNode);
}