-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (49 loc) · 1.59 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
class Accessory {
static register(homebridge) {
homebridge.registerAccessory(this.pluginName, this.accessoryName, this.accessory(homebridge).bind(this));
}
static get pluginName() {
throw new Error("Accessory static getter 'pluginName' not implemented.");
}
static get accessoryName() {
throw new Error("Accessory static getter 'accessoryName' not implemented.");
}
static accessory(homebridge) {
const constructor = this;
return function (log, config, api) {
return new constructor(homebridge, log, config, api);
}
}
getInformationService() {
const { Service, Characteristic } = this;
var informationService = new Service.AccessoryInformation();
informationService
.setCharacteristic(Characteristic.Name, this.name)
.setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
.setCharacteristic(Characteristic.Model, this.model)
.setCharacteristic(Characteristic.SerialNumber, this.serialNumber);
return informationService;
}
get manufacturer() {
throw new Error("Accessory getter 'manufacturer' not implemented.");
}
get model() {
throw new Error("Accessory getter 'model' not implemented.");
}
get serialNumber() {
throw new Error("Accessory getter 'serialNumber' not implemented.");
}
getServices() {
const { service } = this;
const { accessoryName } = this.constructor;
if (!service) {
throw new Error(`Service not found for ${accessoryName} Accessory.`);
}
return [service, this.getInformationService()];
}
constructor() {
}
}
module.exports = {
Accessory,
};