forked from homebridge/HAP-NodeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore.js
140 lines (124 loc) · 3.73 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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
var storage = require('node-persist');
var accessory_Factor = new require("./Accessory.js");
var accessoryController_Factor = new require("./AccessoryController.js");
var service_Factor = new require("./Service.js");
var characteristic_Factor = new require("./Characteristic.js");
console.log("HAP-NodeJS starting...");
storage.initSync();
var accessoryController = new accessoryController_Factor.AccessoryController();
var infoService = generateAccessoryInfoService("Test Accessory 1","Rev 1","A1S2NASF88EW","Oltica");
var lightService = generateLightService();
accessoryController.addService(infoService);
accessoryController.addService(lightService);
var accessory = new accessory_Factor.Accessory("Test Accessory 1", "1A:2B:3C:4D:5E:FF", storage, parseInt(51822), "031-45-154", accessoryController);
accessory.publishAccessory();
function generateLightService() {
var lightService = new service_Factor.Service("00000043-0000-1000-8000-0026BB765291");
var nameOptions = {
type: "00000023-0000-1000-8000-0026BB765291",
perms: [
"pr"
],
format: "string",
initialValue: "Light 1",
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255,
}
var nameChar = new characteristic_Factor.Characteristic(nameOptions);
lightService.addCharacteristic(nameChar);
var onOptions = {
type: "00000025-0000-1000-8000-0026BB765291",
perms: [
"pw",
"pr",
"ev"
],
format: "bool",
initialValue: false,
supportEvents: false,
supportBonjour: false,
manfDescription: "Turn On the Light",
designedMaxLength: 1,
}
var lightSwitchChar = new characteristic_Factor.Characteristic(onOptions, function(value) {
console.log("Light Status Change:",value);
});
lightService.addCharacteristic(lightSwitchChar);
return lightService;
}
function generateAccessoryInfoService(name, model, sn, manufacturer) {
var infoService = new service_Factor.Service("0000003E-0000-1000-8000-0026BB765291");
var nameOptions = {
type: "00000023-0000-1000-8000-0026BB765291",
perms: [
"pr"
],
format: "string",
initialValue: name,
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255,
}
var nameChar = new characteristic_Factor.Characteristic(nameOptions);
infoService.addCharacteristic(nameChar);
var manufacturerOptions = {
type: "00000020-0000-1000-8000-0026BB765291",
perms: [
"pr"
],
format: "string",
initialValue: manufacturer,
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255,
}
var manufacturerChar = new characteristic_Factor.Characteristic(manufacturerOptions);
infoService.addCharacteristic(manufacturerChar);
var modelOptions = {
type: "00000021-0000-1000-8000-0026BB765291",
perms: [
"pr"
],
format: "string",
initialValue: model,
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255,
}
var modelChar = new characteristic_Factor.Characteristic(modelOptions);
infoService.addCharacteristic(modelChar);
var snOptions = {
type: "00000030-0000-1000-8000-0026BB765291",
perms: [
"pr"
],
format: "string",
initialValue: sn,
supportEvents: false,
supportBonjour: false,
manfDescription: "Bla",
designedMaxLength: 255,
}
var snChar = new characteristic_Factor.Characteristic(snOptions);
infoService.addCharacteristic(snChar);
var identifyOptions = {
type: "00000014-0000-1000-8000-0026BB765291",
perms: [
"pw"
],
format: "bool",
initialValue: false,
supportEvents: false,
supportBonjour: false,
manfDescription: "Identify Accessory",
designedMaxLength: 1,
}
var identifyChar = new characteristic_Factor.Characteristic(identifyOptions);
infoService.addCharacteristic(identifyChar);
return infoService;
}