-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
71 lines (63 loc) · 2.55 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const boardService = require('./src/services/board.service');
const config = require('./src/config/main');
const lightAccessoryBuilder = require('./src/accessoriesBuilders/LightAccBuilder');
const fanAccessoryBuilder = require('./src/accessoriesBuilders/SwitchAccBuilder');
const motionAccessoryBuilder = require('./src/accessoriesBuilders/MotionSensorAccBuilder');
const thermostatAccBuilder = require('./src/accessoriesBuilders/ThermostatAccBuilder');
const devices = [
{
type: 'fans',
builder: fanAccessoryBuilder,
},
{
type: 'lights',
builder: lightAccessoryBuilder,
},
{
type: 'motionSensors',
builder: motionAccessoryBuilder,
},
{
type: 'thermostats',
builder: thermostatAccBuilder,
},
];
const local = false;
const Arduino = local
? require('./src/node-arduino.mock.js')
: require('node-arduino');
module.exports = function(homebridge) {
const lightStatusBoard = new Arduino.connect(config.lightStatusBoard);
const motionTempStatusBoard = new Arduino.connect(config.thermostatBoard);
boardService.add(lightStatusBoard, config.lightStatusBoard);
boardService.add(motionTempStatusBoard, config.thermostatBoard);
boardService.openAll(() => {});
homebridge.registerPlatform('homebridge-smartHousePlatform', 'SmartHousePlatform', SmartHousePlatform, true);
};
class SmartHousePlatform {
constructor(log, config, api) {
this.accessories = {};
api.on('didFinishLaunching', () => this.didFinishLaunching(config, api));
}
didFinishLaunching(config, api) {
const { Service, Characteristic, uuid } = api.hap;
const apiParams = { Accessory: api.platformAccessory, Characteristic, Service, uuid};
const accessories = {};
devices.forEach((device) => {
config[device.type].forEach((lightConfig) => {
const UUID = device.builder.generateUUID(lightConfig, { uuid });
if (!this.accessories[UUID]) {
const accessory = device.builder.build(lightConfig, apiParams);
this.accessories[UUID] = accessories[UUID] = accessory;
}
else {
this.accessories[UUID] = device.builder.configure(this.accessories[UUID], lightConfig, apiParams);
}
});
});
api.registerPlatformAccessories('homebridge-smartHousePlatform', 'SmartHousePlatform', accessories);
}
configureAccessory(accessory) {
this.accessories[accessory.UUID] = accessory;
}
}