forked from SamGabbay/tesla-siri-homekit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbridgeSetupSession.js
191 lines (158 loc) · 19.5 KB
/
bridgeSetupSession.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
var crypto = require('crypto');
var uuid = require("hap-nodejs").uuid;
var inherits = require('util').inherits;
var EventEmitter = require('events').EventEmitter;
'use strict';
module.exports = {
SetupSession: BridgeSetupSession
}
function BridgeSetupSession(stateChar, controlChar) {
this.validSession = false
this.sessionUUID = uuid.generate(crypto.randomBytes(32));
this.stateChar = stateChar;
this.controlChar = controlChar;
this.transactionID = 0;
this.preferedLanguage = "en-US";
this.lastResponse = null;
// 0 - Waiting for negotiate
// 1 - Waiting for selection
// 2 - List platforms, waiting selection to give session to plugin
// 3 - Forward message to platform
// 4 - Manage accessory config, waiting selection
this.currentStage = 0;
this.currentPluginName;
this.currentPlatformInstance;
this.currentPlatformContext = {};
}
inherits(BridgeSetupSession, EventEmitter);
BridgeSetupSession.prototype.handleWriteRequest = function(request) {
if (request.type === "Negotiate") {
this.transactionID = request.tid + 1;
this.preferedLanguage = request.language;
this.validSession = true
var respDict = {
"tid": this.transactionID,
"type": "Negotiate",
"sid": this.sessionUUID,
"attachment": {
"type": "Interface",
"interface": "list",
"title": "How can I help you?",
"items": [
"Manage Platform",
"Manage Accessories"
]
}
}
this.currentStage = 1;
this.sendResponse(respDict);
} else if (request.type === "Interface") {
this.transactionID = request.tid;
if (this.currentStage === 1) {
if (request.response.selections[0] === 0) {
this.presentManagePlatformMenu();
} else if (request.response.selections[0] === 1) {
this.presentManageAccessoryMenu();
}
} else if (this.currentStage === 2) {
var selectedIndex = request.response.selections[0];
var targetPlatformName = this.listOfPlatforms[selectedIndex];
var targetPlatform = this.configurablePlatformPlugins[targetPlatformName];
this.currentPlatformContext = {};
this.currentPlatformContext.preferedLanguage = this.preferedLanguage;
this.currentPluginName = targetPlatformName;
this.currentPlatformInstance = targetPlatform;
this.currentStage = 3;
this.currentPlatformInstance.configurationRequestHandler(this.currentPlatformContext, null, this.pluginResponseHandler.bind(this));
} else if (this.currentStage === 3) {
this.currentPlatformInstance.configurationRequestHandler(this.currentPlatformContext, request, this.pluginResponseHandler.bind(this));
} else if (this.currentStage === 4) {
this.handleManageAccessory(request);
}
} else if (request.type === "Terminate") {
this.transactionID = request.tid;
this.validSession = false;
if (this.currentStage === 3) {
this.currentPlatformInstance.configurationRequestHandler(this.currentPlatformContext, request, this.pluginResponseHandler.bind(this));
}
}
}
BridgeSetupSession.prototype.pluginResponseHandler = function(response, type, replace, config) {
if (config) {
this.emit('newConfig', type, this.currentPluginName, replace, config);
this.presentMainMenu();
} else if (response) {
this.transactionID += 1;
response.tid = this.transactionID;
response.sid = this.sessionUUID;
this.sendResponse(response);
}
}
BridgeSetupSession.prototype.presentMainMenu = function() {
this.currentStage = 1;
this.transactionID += 1;
var respDict = {
"tid": this.transactionID,
"sid": this.sessionUUID,
"type": "Interface",
"interface": "list",
"title": "How can I help you?",
"items": [
"Manage Platform",
"Manage Accessories"
]
}
this.sendResponse(respDict);
}
BridgeSetupSession.prototype.presentManagePlatformMenu = function() {
var listOfPlatforms = [];
for (var name in this.configurablePlatformPlugins) {
listOfPlatforms.push(name);
}
this.listOfPlatforms = listOfPlatforms;
this.transactionID += 1;
var respDict = {
"tid": this.transactionID,
"type": "Interface",
"sid": this.sessionUUID,
"interface": "list",
"title": "Which platform?",
"items": listOfPlatforms
}
this.currentStage = 2;
this.sendResponse(respDict);
}
BridgeSetupSession.prototype.presentManageAccessoryMenu = function() {
this.emit('requestCurrentConfig', function(config) {
this.currentConfig = config;
}.bind(this));
this.transactionID += 1;
var respDict = {
"tid": this.transactionID,
"type": "Interface",
"sid": this.sessionUUID,
"interface": "instruction",
"title": "Not Implemented",
"detail": "This function is not yet implemented.\nPlease manually edit config.json for now.",
"showNextButton": true,
"heroImage": "iVBORw0KGgoAAAANSUhEUgAAAWgAAAFoCAYAAAB65WHVAAAAAXNSR0IArs4c6QAAKi1JREFUeAHtnX/MbWV157nC9QpIkB8Ff6HvpZIKyLXDqIA3wx9IB0hNm/mjloQJxig1tKON4xTbkBiw1UzMzDRlYmbAP0RmkrHNTJPppAN6UXDi9aozkgopWBXuS3G0EH5J4Qr3Au33K+9uNy/v2WftffaP53n2ZyUre5+zn/08a32etdY5Z/86hx2GQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIFEhgW4E+4VKeBA6X2adI16QnSU+UnlBbVutH6b0d0pdvsdRbhx2UPrPF8oDee1j6yIZW614+JF2XPiB9TopAIAkCFOgkpmE2RmyXp78gPUv6JulO6drG8vVaHiGdUp7V4D+U7peubyx/o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g4PUfyLe9NXVB9qEgBAIrE6BAr4yQDhYQ8DHWs6W+0cPqy8beLM31r5Z8vfV3pXdJ79zQO7R8SIpAYBACFOhBsNLpAgLb9b6LtIv1z0t3Stc2lr7T8QjplOIrK3yn3n7p+sbyXi1dlF2cD0kRCIxGgAI9GmoGWkLAxdlFek16stSXnlnrd/35te+ErO4Q9LK+rpcvurOwfpeh78R7RLrV3YkP6v116QPS56QIBCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAikQ+HvJfXTqIyh0lQAAAABJRU5ErkJggg=="
}
this.currentStage = 4;
this.sendResponse(respDict);
}
BridgeSetupSession.prototype.handleManageAccessory = function(request) {
this.presentMainMenu();
}
BridgeSetupSession.prototype.sendResponse = function(response) {
if (this.validSession) {
var serializedReponse = JSON.stringify(response);
var respData = Buffer(serializedReponse).toString('base64');
this.lastResponse = respData;
setTimeout(function() {
this.controlChar.setValue(respData);
}.bind(this), 100);
}
}
BridgeSetupSession.prototype.handleReadRequest = function(callback) {
callback(null, this.lastResponse);
}