-
Notifications
You must be signed in to change notification settings - Fork 1
/
bridged-core.js
39 lines (31 loc) · 1.04 KB
/
bridged-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
38
39
'use strict';
let fs = require('fs');
let path = require('path');
let hapNodejs = require('hap-nodejs');
let uuid = hapNodejs.uuid;
let Bridge = hapNodejs.Bridge;
let Accessory = hapNodejs.Accessory;
let accessoryLoader = hapNodejs.AccessoryLoader;
console.log('HAP-NodeJS starting...');
hapNodejs.init();
// Start by creating our Bridge which will host all loaded Accessories
let bridge = new Bridge('Node Bridge', uuid.generate('Node Bridge'));
// Listen for bridge identification event
bridge.on('identify', (paired, callback) => {
console.log('Node Bridge identify');
callback(); // success
});
// Load up all accessories in the /accessories folder
let dir = path.join(__dirname, 'accessories');
let accessories = accessoryLoader.loadDirectory(dir);
// Add them all to the bridge
accessories.forEach(accessory => {
bridge.addBridgedAccessory(accessory);
});
// Publish the Bridge on the local network.
bridge.publish({
username: 'CC:22:3D:E3:CE:F6',
port: 51826,
pincode: '321-12-531',
category: Accessory.Categories.BRIDGE
});