-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
421 lines (400 loc) · 14.5 KB
/
index.html
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Homebridge Hubitat Configuration Tool</title>
<style>
body { background-color: DimGray ; }
* { font-family:"Lucida Console"; font-size:12px; padding:0px;margin:0px;}
p { line-height:18px; }
div { width:95%; margin-left:auto; margin-right:auto;}
#content { padding:5px; background:#282923; border-radius:5px;
overflow-y: scroll; border:1px solid #CCC;
margin-top:10px; height: 500px; font-family: "Lucida Console";
}
</style>
</head>
<body>
<br/>
<div style="background-color:red">
<font color=yellow>
Note: This tool will always create a new random "username" and "pin" in the bridge section for homebridge. Do <b>NOT</b> change these values in your config.json if you have an already running homebridge instance. You will destroy your HomeKit configuration if you do so.
</font>
</div>
<br/><br/>
<div id="config">
<font color=White>
<input type="checkbox" id="hoobs"/> I need this for HOOBS? <br/><br/>
</font>
<div id="localip">
<label>IP Address of your computer that runs homebridge:</label><input type="text" id="homebridgeIP"><br/><br/>
</div>
<font color=lawngreen>
<input type="checkbox" id="makerAPI"> Add MakerAPI Config? <br/>
<div id="makerconfig">
<label>MakerAPI URL:</label>
<input type="text" id="makerAPIURL" size="80"><br/>
<div>
Note: Just copy the first example URL in MakerAPI in here to auto-fill your configuration<br>
<img src="maker.PNG" width="600"/>
</div>
 <input type="checkbox" id="hsmMaker"/> HSM Enabled? <br/>
 <input type="checkbox" id="modesMaker"/> Modes Enabled? <br/>
 <input type="checkbox" id="attribute_filterMaker"/> Add Attribute Filter example<br/>
 <input type="checkbox" id="capability_filterMaker"/> Add Capability Filter example<br/>
</div>
</font>
<font color=orange>
<input type="checkbox" id="hubconnect"> Add HubConnect Config? <br/>
<div id="hubconnectconfig">
 <label>HubConnect Key:</label><input type="text" id="hubConnectKey" size="80"><br/>
<div>
Note: Enter the Connection Key your that was provided in the HUbConnect Server Instance<br>
<img src="hubconnect.PNG" width="600"/>
</div>
 <input type="checkbox" id="hsmHubConnect"/> HSM Enabled? <br/>
 <input type="checkbox" id="modesHubConnect"/> Modes Enabled? <br/>
 <input type="checkbox" id="attribute_filterHubConnect"/> Add Attribute Filter example<br/>
 <input type="checkbox" id="capability_filterHubConnect"/> Add Capability Filter example<br/>
</div>
</font>
<font color=blue>
<input type="checkbox" id="anotherConfig"> Add placeholder for another homebridge plugin? <br/>
</font>
<div>
<br/><button id="copyClipboard">Copy to clipboard</button>
</div>
</div>
<div id="content"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
function parseURL(url) {
var parser = document.createElement('a'),
searchObject = {},
queries, split, i;
// Let the browser do the work
parser.href = url;
// Convert query string to object
queries = parser.search.replace(/^\?/, '').split('&');
for( i = 0; i < queries.length; i++ ) {
split = queries[i].split('=');
searchObject[split[0]] = split[1];
}
return {
protocol: parser.protocol,
host: parser.host,
hostname: parser.hostname,
port: parser.port,
pathname: parser.pathname,
search: parser.search,
searchObject: searchObject,
hash: parser.hash
};
}
function makeusername() {
var result = '';
var characters = 'ABCDEF0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < 12; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
result = result.replace(/(.{2})/g, "$1:");
result = result.slice(0, -1);
return result;
}
function makepin() {
var result = '';
var characters = '123456789';
var charactersLength = characters.length;
for ( var i = 0; i < 3; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
result +='-';
for ( var i = 0; i < 2; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
result +='-';
for ( var i = 0; i < 3; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
</script>
<script>
$(function () {
"use strict";
// for better performance - to avoid searching in DOM
var content = $('#content');
var hsmMaker = $('#hsmMaker');
var modesMaker = $('#modesMaker');
var attribute_filterMaker = $('#attribute_filterMaker');
var capability_filterMaker = $('#capability_filterMaker');
var makerAPI = $('#makerAPI');
var makerconfig = $('#makerconfig');
var homebridgeIP = $('#homebridgeIP');
var hubconnect = $('#hubconnect');
var hubconnectconfig = $('#hubconnectconfig');
var hsmHubConnect = $('#hsmHubConnect');
var modesHubConnect = $('#modesHubConnect');
var attribute_filterHubConnect = $('#attribute_filterHubConnect');
var capability_filterHubConnect = $('#capability_filterHubConnect');
var hubConnectKey = $('#hubConnectKey');
var makerAPIURL = $('#makerAPIURL');
var anotherConfig = $('#anotherConfig');
var hoobs = $('#hoobs');
var localip = $('#localip');
var userName = makeusername();
var pin = makepin();
makerconfig.hide();
hubconnectconfig.hide();
function tab() {
return " ";
//return " ";
}
function addLine(line) {
content.append(line+ '<br/>');
}
function buildMain() {
content.html('<pre>');
addLineMain('{');
addLineMain(tab() + '"bridge": {');
addLineMain(tab() + tab() + '"name": "Homebridge",');
addLineMain(tab() + tab() + '"username": "' + userName + '",');
addLineMain(tab() + tab() + '"port": 51936,');
addLineMain(tab() + tab() + '"pin": "' + pin + '"');
addLineMain(tab() + '},');
addLineMain(tab() + '"mdns": {');
addLineMain(tab() + tab() + '"interface": "' + homebridgeIP.val() + '"');
addLineMain(tab() + '},');
addLineMain(tab() + '"platforms": [');
}
function addLineMain(line) {
addLine('<font color=white>' + line);
}
function addLineMaker(line) {
addLine('<font color=lawngreen>' + line);
}
function addLineHubConnect(line) {
addLine('<font color=orange>' + line);
}
function addLineAnotherPlugin(line) {
addLine('<font color=blue>' + line);
}
function buildMakerAPI() {
var parsedURL = parseURL(makerAPIURL.val());
var pathname = parsedURL.pathname.split('/');
var access_token = '"<font color="red">access_token</font>"';
var app_url = '"<font color="red">app_url</font>"';
if ((parsedURL.searchObject.access_token) && (makerAPIURL.val().length > 0))
access_token = '"' + parsedURL.searchObject.access_token + '"';
if ((pathname.length > 4) && (makerAPIURL.val().length > 0)) {
app_url = '"' + parsedURL.protocol;
app_url += '//';
app_url += parsedURL.hostname;
for (var i = 0; i < 4; i++) {
if (pathname[i].length > 0)
app_url += '/' + pathname[i];
}
app_url += '"';
}
addLineMaker(tab() + tab() + '{');
addLineMaker(tab() + tab() + tab() + '"platform": "Hubitat-MakerAPI",');
addLineMaker(tab() + tab() + tab() + '"name": "Hubitat MakerAPI",');
addLineMaker(tab() + tab() + tab() + '"app_url": ' + app_url + ',');
addLineMaker(tab() + tab() + tab() + '"access_token": ' + access_token + ',');
addLineMaker(tab() + tab() + tab() + '"local_ip": "' + homebridgeIP.val() + '",');
addLineMaker(tab() + tab() + tab() + '"local_port": 20010,');
addLineMaker(tab() + tab() + tab() + '"mode_switches": ' + (modesMaker.is(':checked') ? "true" : "false") + ',');
addLineMaker(tab() + tab() + tab() + '"hsm": ' + (hsmMaker.is(':checked') ? "true" : "false") + ',');
if (attribute_filterMaker.is(':checked')) {
addLineMaker(tab() + tab() + tab() + '"excluded_attributes" : {');
addLineMaker(tab() + tab() + tab() + tab() + '"123" : [ "switch", "power" ],');
addLineMaker(tab() + tab() + tab() + tab() + '"321" : [ "humidity" ]');
addLineMaker(tab() + tab() + tab() + '},');
}
if (capability_filterMaker.is(':checked')) {
addLineMaker(tab() + tab() + tab() + '"excluded_capabilities": {');
addLineMaker(tab() + tab() + tab() + tab() + '"12" : [ "thermostat" ]');
addLineMaker(tab() + tab() + tab() + '},');
}
addLineMaker(tab() + tab() + tab() + '"debug": false,');
addLineMaker(tab() + tab() + tab() + '"logFile": {');
addLineMaker(tab() + tab() + tab() + tab() + '"enabled": true,');
addLineMaker(tab() + tab() + tab() + tab() + '"path": "",');
addLineMaker(tab() + tab() + tab() + tab() + '"file": "",');
addLineMaker(tab() + tab() + tab() + tab() + '"compress": true,');
addLineMaker(tab() + tab() + tab() + tab() + '"keep": 5,');
addLineMaker(tab() + tab() + tab() + tab() + '"size": "10m"');
addLineMaker(tab() + tab() + tab() + '}');
}
function buildHubConnect() {
var hubConnectKeyValue = '"<font color="red">hubConnectKey</font>"';
if (hubConnectKey.val().length > 0)
hubConnectKeyValue = '"' + hubConnectKey.val() + '"';
addLineHubConnect(tab() + tab() + '{');
addLineHubConnect(tab() + tab() + tab() + '"platform": "Hubitat-HubConnect",');
addLineMaker(tab() + tab() + tab() + '"name": "Hubitat HubConnect",');
addLineHubConnect(tab() + tab() + tab() + '"hubconnect_key": ' + hubConnectKeyValue + ',');
addLineHubConnect(tab() + tab() + tab() + '"local_ip": "' + homebridgeIP.val() + '",');
addLineHubConnect(tab() + tab() + tab() + '"local_port": 20009,');
addLineHubConnect(tab() + tab() + tab() + '"mode_switches": ' + (modesHubConnect.is(':checked') ? "true" : "false") + ',');
addLineHubConnect(tab() + tab() + tab() + '"hsm": ' + (hsmHubConnect.is(':checked') ? "true" : "false") + ',');
if (attribute_filterHubConnect.is(':checked')) {
addLineHubConnect(tab() + tab() + tab() + '"excluded_attributes" : {');
addLineHubConnect(tab() + tab() + tab() + tab() + '"123" : [ "switch", "power" ],');
addLineHubConnect(tab() + tab() + tab() + tab() + '"321" : [ "humidity" ]');
addLineHubConnect(tab() + tab() + tab() + '},');
}
if (capability_filterHubConnect.is(':checked')) {
addLineHubConnect(tab() + tab() + tab() + '"excluded_capabilities": {');
addLineHubConnect(tab() + tab() + tab() + tab() + '"12" : [ "thermostat" ]');
addLineHubConnect(tab() + tab() + tab() + '},');
}
addLineHubConnect(tab() + tab() + tab() + '"debug": false,');
addLineHubConnect(tab() + tab() + tab() + '"logFile": {');
addLineHubConnect(tab() + tab() + tab() + tab() + '"enabled": true,');
addLineHubConnect(tab() + tab() + tab() + tab() + '"path": "",');
addLineHubConnect(tab() + tab() + tab() + tab() + '"file": "",');
addLineHubConnect(tab() + tab() + tab() + tab() + '"compress": true,');
addLineHubConnect(tab() + tab() + tab() + tab() + '"keep": 5,');
addLineHubConnect(tab() + tab() + tab() + tab() + '"size": "10m"');
addLineHubConnect(tab() + tab() + tab() + '}');
}
function buildAnotherPlugin() {
addLineAnotherPlugin(tab() + tab() + '{');
addLineAnotherPlugin(tab() + tab() + tab() + '"description": "Add the parameters for the other plugin here"');
addLineAnotherPlugin(tab() + tab() + '}');
}
function ValidateIPaddress(ipaddress)
{
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) {
return true;
}
return false;
}
function buildConfig() {
var homebridgeIPStr = '';
if (homebridgeIP.val())
homebridgeIPStr = homebridgeIP.val();
if ((ValidateIPaddress(homebridgeIPStr) == false) && hoobs.is(':checked') == false ) {
$('#copyClipboard').hide();
content.html('<pre><font color=red>Please enter a valid IP address for the computer that runs homebridge</font>');
} else {
$('#copyClipboard').show();
if (hoobs.is(':checked') == true) {
content.html('<pre>');
}
else {
buildMain();
}
if (makerAPI.is(':checked')) {
buildMakerAPI();
if ((hubconnect.is(':checked')) || (anotherConfig.is(':checked')))
addLineMaker(tab() + tab() + '}</font><font color=white>,')
else
addLineMaker(tab() + tab() + '}</font>')
}
if (hubconnect.is(':checked')) {
buildHubConnect();
if (anotherConfig.is(':checked'))
addLineHubConnect(tab() + tab() + '}</font><font color=white>,')
else
addLineHubConnect(tab() + tab() + '}</font>')
}
if (anotherConfig.is(':checked')) {
buildAnotherPlugin();
}
if (hoobs.is(':checked') == true) {
addLineMain('</pre>');
}
else
{
addLineMain(tab() + ']');
addLineMain('}</pre>');
}
}
}
$('#hsmMaker').change(function() {
buildConfig()
});
$('#modesMaker').change(function() {
buildConfig()
});
$('#attribute_filterMaker').change(function() {
buildConfig()
});
$('#capability_filterMaker').change(function() {
buildConfig()
});
$('#hsmHubConnect').change(function() {
buildConfig()
});
$('#modesHubConnect').change(function() {
buildConfig()
});
$('#attribute_filterHubConnect').change(function() {
buildConfig()
});
$('#capability_filterHubConnect').change(function() {
buildConfig()
});
$('#makerAPI').change(function() {
if (makerAPI.is(':checked'))
makerconfig.show();
else
makerconfig.hide();
buildConfig()
});
$('#homebridgeIP').keyup(function() {
buildConfig()
});
$('#hubConnectKey').keyup(function() {
buildConfig()
});
$('#makerAPIURL').keyup(function() {
buildConfig()
});
$("#makerAPIURL").bind("input propertychange", function(e){
buildConfig();
});
$('#hoobs').change(function() {
if (hoobs.is(':checked'))
localip.hide();
else
localip.show();
buildConfig()
});
$('#hubconnect').change(function() {
if (hubconnect.is(':checked'))
hubconnectconfig.show();
else
hubconnectconfig.hide();
buildConfig()
});
$("#hubConnectKey").bind("input propertychange", function(e){
buildConfig();
});
$("#homebridgeIP").bind("input propertychange", function(e){
buildConfig();
});
$("#anotherConfig").change(function() {
buildConfig();
});
$(document).ready(function () {
buildConfig();
});
$('#copyClipboard').click(function(){
var $temp = $("<div>");
$("body").append($temp);
$temp.attr("contenteditable", true)
.html($('#content').html()).select()
.on("focus", function() { document.execCommand('selectAll',false,null); })
.focus();
document.execCommand("copy");
$temp.remove();
});
});
</script>
</body>
</html>