-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
40 lines (35 loc) · 958 Bytes
/
index.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
/**
* v1
*
* @url https://github.com/SeydX/homebridge-xiamo-alarmswitch
* @author SeydX <[email protected]>
*
**/
'use strict';
const fs = require('fs');
module.exports = function (homebridge) {
if(!isConfig(homebridge.user.configPath(), 'platforms', 'AlarmSwitch')) {
return;
}
let AlarmSwitch = require('./src/platform.js')(homebridge);
homebridge.registerPlatform('homebridge-xiamo-alarmswitch', 'AlarmSwitch', AlarmSwitch, true);
};
function isConfig(configFile, type, name) {
let config = JSON.parse(fs.readFileSync(configFile));
if('accessories' === type) {
let accessories = config.accessories;
for(const i in accessories) {
if(accessories[i]['accessory'] === name) {
return true;
}
}
} else if('platforms' === type) {
let platforms = config.platforms;
for(const i in platforms) {
if(platforms[i]['platform'] === name) {
return true;
}
}
}
return false;
}