This repository has been archived by the owner on Jun 25, 2020. It is now read-only.
forked from homebridge/HAP-NodeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BridgedAccessoryController.js
53 lines (51 loc) · 1.73 KB
/
BridgedAccessoryController.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
BridgedAccessoryController.prototype = {
addAccessory: function addAccessory(accessory) {
var that = this;
accessory.bridgeController = that;
accessory.accessoryID = that.accessoryID;
that.accessories.push(accessory);
that.accessoryID += 1;
},
jsonPresentation: function jsonPresentation() {
var accessoryObjects = [];
for (var i = 0; i < this.accessories.length; i++) {
var accessory = this.accessories[i];
accessoryObjects.push(accessory.accessoryJsonPresentation());
};
var dict = {
accessories: accessoryObjects
}
return JSON.stringify(dict);
},
jsonForCharacteristicUpdate: function jsonForCharacteristicUpdate(aid, iid, callback) {
var accessory = this.accessories[aid - 1];
accessory.jsonForCharacteristicUpdate(aid,iid, function(json){
callback(json);
});
},
processCharacteristicsValueWrite: function processCharacteristicsValueWrite(updates, peer) {
var updates_objects = JSON.parse(updates.toString());
var update_characteristics = updates_objects["characteristics"];
for (var i = 0; i < update_characteristics.length; i++) {
var update_char = update_characteristics[i];
var update_char_aid = update_char["aid"];
var accessory = this.accessories[update_char_aid - 1];
accessory.processSingleCharacteristicsValueWrite(update_char, peer);
}
},
broadcastEvent: function broadcastEvent(data, subscribedPeers, peer) {
if (this.tcpServer !== undefined) {
this.tcpServer.broadcastEvent(data, subscribedPeers, peer);
}
}
}
function BridgedAccessoryController() {
if (!(this instanceof BridgedAccessoryController)) {
return new BridgedAccessoryController();
}
this.accessoryID = 1;
this.accessories = [];
}
module.exports = {
BridgedAccessoryController: BridgedAccessoryController
};