forked from nfarina/homebridge-legacy-plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
40 lines (32 loc) · 1.33 KB
/
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
var path = require('path');
var api = require('./api')
var fs = require('fs');
module.exports = function(homebridge) {
// make the homebridge API object available to accessories and platforms that weren't
// designed with it in mind
api.homebridge = homebridge;
// load up all legacy accessories
var accessoriesDir = path.join(__dirname, "accessories");
fs.readdirSync(accessoriesDir).forEach(function(file) {
if (file.indexOf(".js") > 0) {
var name = file.replace(".js","");
homebridge.registerAccessory("homebridge-legacy-plugins", name, function(logger, config) {
console.log("Loading legacy accessory " + name);
var accessoryModule = require(path.join(accessoriesDir, file));
return new accessoryModule.accessory(logger, config);
});
}
});
// load up all legacy platforms
var platformsDir = path.join(__dirname, "platforms");
fs.readdirSync(platformsDir).forEach(function(file) {
if (file.indexOf(".js") > 0) {
var name = file.replace(".js","");
homebridge.registerPlatform("homebridge-legacy-plugins", name, function(logger, config) {
console.log("Loading legacy platform " + name);
var platformModule = require(path.join(platformsDir, file));
return new platformModule.platform(logger, config);
});
}
});
}