forked from homebridge/HAP-NodeJS
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Core.js
37 lines (29 loc) · 1.34 KB
/
Core.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
var path = require('path');
var storage = require('node-persist');
var uuid = require('./').uuid;
var Accessory = require('./').Accessory;
var accessoryLoader = require('./lib/AccessoryLoader');
console.log("HAP-NodeJS starting...");
// Initialize our storage system
storage.initSync();
// Our Accessories will each have their own HAP server; we will assign ports sequentially
var targetPort = 51826;
// Load up all accessories in the /accessories folder
var dir = path.join(__dirname, "accessories");
var accessories = accessoryLoader.loadDirectory(dir);
// Publish them all separately (as opposed to BridgedCore which publishes them behind a single Bridge accessory)
accessories.forEach(function(accessory) {
// To push Accessories separately, we'll need a few extra properties
if (!accessory.username)
throw new Error("Username not found on accessory '" + accessory.displayName +
"'. Core.js requires all accessories to define a unique 'username' property.");
if (!accessory.pincode)
throw new Error("Pincode not found on accessory '" + accessory.displayName +
"'. Core.js requires all accessories to define a 'pincode' property.");
// publish this Accessory on the local network
accessory.publish({
port: targetPort++,
username: accessory.username,
pincode: accessory.pincode
});
});