homebridge-cmd4 6.1.2 → 6.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1359 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Note:
4
+ // Must read https://docs.github.com/en/rest/reference/markdown#render-an-arbitrary-markdown-document
5
+ // https://gist.github.com
6
+ //
7
+ // Good Learning sites:
8
+ // https://www.w3schools.com/jquery/jquery_get_started.asp
9
+ // https://www.w3schools.com/howto/howto_css_sidebar_icons.asp
10
+ //
11
+ // Node.js Manuals & Documentation
12
+ // https://nodejs.org/docs/v0.4.0/api/all.html
13
+
14
+ // * Cmd4 Body Layout *
15
+ // ====================
16
+ //
17
+ // =====================================
18
+ // | class="header fixed-top"
19
+ // | __________________________________
20
+ // | | class="container-fluid"
21
+ // | | _______________________________
22
+ // | | | class="site-logo"
23
+ // | | |_______________________________
24
+ // | | | Search - tba
25
+ // | | |_______________________________
26
+ // | |__________________________________
27
+ // |
28
+ // |=====================================
29
+ // | class="content"
30
+ // | _________________________________
31
+ // | | class="sidenav"
32
+ // | | - device links
33
+ // | | - characteristic links
34
+ // | | - cmd4Directive links
35
+ // | | .
36
+ // | | .
37
+ // | | .
38
+ // | |_________________________________
39
+ // | | class="main"
40
+ // | | - class="section" - device pages
41
+ // | | - class="section" - characteristic pages
42
+ // | | - class="section" - directive pages
43
+ // | | .
44
+ // | | .
45
+ // | | .
46
+ // | |_________________________________
47
+ // |=====================================
48
+ // | Javascript
49
+ // =====================================
50
+
51
+
52
+
53
+ // * HTML Layout *
54
+ // ===============
55
+ // _______________________________________
56
+ // | Margin |
57
+ // | _________________________________ |
58
+ // | | Border | |
59
+ // | | ___________________________ | |
60
+ // | | | Padding | | |
61
+ // | | | _____________________ | | |
62
+ // | | | | | | | |
63
+ // | | | | Content | | | |
64
+ // | | | |_____________________| | | |
65
+ // | | | | | |
66
+ // | | |___________________________| | |
67
+ // | | | |
68
+ // | |_________________________________| |
69
+ // | |
70
+ // |_______________________________________|
71
+
72
+
73
+
74
+ const which = require('which');
75
+ const path = require( "path" );
76
+
77
+ const settings = require( "../cmd4Settings" );
78
+
79
+ // Get the real path of homebridge instead of a dev dependancy,
80
+ // which caused issues if you forget to update dependancies but
81
+ // upgrade homebridge.
82
+ const homebridgePath = which.sync( 'homebridge', { nothrow: true } )
83
+
84
+ let apiPath;
85
+ let HomebridgeAPI;
86
+ if ( homebridgePath )
87
+ {
88
+ let dirname = path.dirname( homebridgePath );
89
+
90
+ console.log( "Found homebridge in path %s", dirname );
91
+ apiPath = `${ dirname }/../lib/node_modules/homebridge/lib/api`;
92
+ HomebridgeAPI = require( apiPath ).HomebridgeAPI;
93
+
94
+ if ( ! HomebridgeAPI )
95
+ {
96
+ console.log( "homebridgeAPI not available !!!" );
97
+ process.exit( 10 );
98
+ }
99
+
100
+ } else
101
+ {
102
+ console.log( "homebridge not found !!!" );
103
+ process.exit( 10 );
104
+ }
105
+ console.log( "Found api in %s", apiPath );
106
+
107
+
108
+
109
+ // Cmd4 Constants and Settings
110
+ const constants = require( "../cmd4Constants" );
111
+ //const settings = require( "../cmd4Settings" );
112
+
113
+ // For changing validValue Constants to Values and back again
114
+ var { transposeValueToValidConstant } = require( "../utils/transposeCMD4Props" );
115
+
116
+ // Required to initialize CMD4 Accessory & Device lookup tables.
117
+ let _api = new HomebridgeAPI( ); // object we feed to Plugins
118
+
119
+
120
+ // These would be the uninitialized values.
121
+ let ACC_DATA = require('../lib/CMD4_ACC_TYPE_ENUM');
122
+ let DEVICE_DATA = require('../lib/CMD4_DEVICE_TYPE_ENUM');
123
+
124
+ // Init the library for all to use
125
+ let CMD4_ACC_TYPE_ENUM = ACC_DATA.init( _api.hap.Characteristic );
126
+ let CMD4_DEVICE_TYPE_ENUM = DEVICE_DATA.init( CMD4_ACC_TYPE_ENUM, _api.hap.Service, _api.hap.Characteristic, _api.hap.Categories );
127
+ let Characteristic = _api.hap.Characteristic;
128
+
129
+ // File System utilities
130
+ let fs = require( "fs" );
131
+
132
+ let CMD4_DOC_FILE_PATH = "./docs/";
133
+ let AUTO_GENERATED_SUB_PATH = "autoGenerated/";
134
+ let CMD4_ACC_DOC_FILE = "CMD4_AccessoryDescriptions.html";
135
+
136
+ // Scripts we embed
137
+ let CMD4_SCRIPTS = [
138
+ { "file": "ExampleJavaScript_template.js",
139
+ "filePath": "./Extras/Cmd4Scripts/Examples/",
140
+ "link": "JS Template",
141
+ "description": "Example Cmd4 JavaScript Template"
142
+ },
143
+ { "file": "ExampleShellScript_template.sh",
144
+ "filePath": "./Extras/Cmd4Scripts/Examples/",
145
+ "link": "Bash Template",
146
+ "description": "Example Cmd4 Shell Script Template"
147
+ }
148
+ ];
149
+
150
+ // The fid of the document.
151
+ var fid;
152
+
153
+ var divLevel=0;
154
+ const INDENT = 3;
155
+
156
+ // Since v6.2 the Accessory characteristics are not sorted. This
157
+ // is because peoples saved status per characteristic is done by index.
158
+ // changing this would mean the values would be mixed up.
159
+ function sortACCByType( )
160
+ {
161
+ var keys = [];
162
+ var sorted_obj = { properties: [] };
163
+
164
+ for ( let accTypeEnumIndex = 0 ; accTypeEnumIndex < CMD4_ACC_TYPE_ENUM.EOL; accTypeEnumIndex++ )
165
+ {
166
+ keys.push( CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type )
167
+ }
168
+
169
+ // sort the keys ( types )
170
+ keys.sort();
171
+
172
+ // create new array based on Sorted Keys
173
+ keys.forEach( ( key ) =>
174
+ {
175
+ accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.indexOfEnum( key );
176
+ sorted_obj.properties.push( CMD4_ACC_TYPE_ENUM.properties[accTypeEnumIndex]);
177
+ });
178
+
179
+ sorted_obj.indexOfEnum = CMD4_ACC_TYPE_ENUM.indexOfEnum;
180
+ sorted_obj.EOL = CMD4_ACC_TYPE_ENUM.EOL;
181
+ return sorted_obj;
182
+ }
183
+
184
+ // Since v6.2 the Device names are not sorted. This
185
+ // is because I'm lazy to change any documentation referencing an index
186
+ function sortDevByDeviceName( )
187
+ {
188
+ var keys = [];
189
+ var sorted_obj = { properties: [] };
190
+
191
+ for ( let devTypeEnumIndex = 0 ; devTypeEnumIndex < CMD4_DEVICE_TYPE_ENUM.EOL; devTypeEnumIndex++ )
192
+ {
193
+ keys.push( CMD4_DEVICE_TYPE_ENUM.properties[ devTypeEnumIndex ].deviceName )
194
+ }
195
+
196
+ // sort the keys ( deviceName )
197
+ keys.sort();
198
+
199
+ // create new array based on Sorted Keys
200
+ keys.forEach( ( key ) =>
201
+ {
202
+ devTypeEnumIndex = CMD4_DEVICE_TYPE_ENUM.indexOfEnum( key );
203
+ sorted_obj.properties.push( CMD4_DEVICE_TYPE_ENUM.properties[ devTypeEnumIndex ] );
204
+ });
205
+
206
+ sorted_obj.indexOfEnum = CMD4_DEVICE_TYPE_ENUM.indexOfEnum;
207
+ sorted_obj.EOL = CMD4_DEVICE_TYPE_ENUM.EOL;
208
+ return sorted_obj;
209
+ }
210
+
211
+ let CMD4_Sorted_ACC = sortACCByType( );
212
+ let CMD4_Sorted_DEV = sortDevByDeviceName( );
213
+
214
+
215
+ function createHTMLCmd4AccDocument( )
216
+ {
217
+ let file = CMD4_DOC_FILE_PATH +
218
+ AUTO_GENERATED_SUB_PATH +
219
+ CMD4_ACC_DOC_FILE;
220
+
221
+ // Open the document for writing
222
+ fid = fs.createWriteStream( file,
223
+ { flags: "w" // Open for write
224
+ });
225
+
226
+ fid.on("error", ( ) =>
227
+ {
228
+ console.log(`error fs.creatingWriteStream: ${ file }` );
229
+ process.exit( 666 );
230
+ });
231
+
232
+ startHTML_AndHead( );
233
+
234
+ addSytlesAndLeftSideNav_WithinHead ( );
235
+ endHead( );
236
+
237
+ addBody( );
238
+
239
+ wfs( `</HTML>\n` );
240
+
241
+ fid.close( );
242
+
243
+ }
244
+
245
+ function startHTML_AndHead ()
246
+ {
247
+ wfs(
248
+ `<!DOCTYPE HTML>
249
+ <HTML LANG="en">
250
+ <HEAD>
251
+ <META CHARSET="utf-8">
252
+ <META NAME="viewport" CONTENT="width=device-width, initial-scale=1">
253
+ <!-- Needed for unicode fa-caret-down -->
254
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
255
+ <META NAME="robots" CONTENT="index,follow">
256
+ <META NAME="Description" CONTENT="CMD4 Characteristics.">
257
+ <META PROPERTY="og:url" CONTENT="https://github.com/ztalbot2000/homebridge-cmd4/docs/${ AUTO_GENERATED_SUB_PATH }${ CMD4_ACC_DOC_FILE }">
258
+
259
+ <TITLE>CMD4 Devices</TITLE>\n` );
260
+
261
+ }
262
+
263
+ function addSytlesAndLeftSideNav_WithinHead( )
264
+ {
265
+ wfs(
266
+ `<META NAME="viewport" CONTENT="width=device-width, initial-scale=1">
267
+ <STYLE>
268
+
269
+ /* Fallback styling */
270
+ BODY {
271
+ font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;
272
+ font-size: 1rem;
273
+ font-weight: 400;
274
+ line-height: 1.5;
275
+ color: #252930; /* blackish */
276
+ text-align: left;
277
+ background-color: white;
278
+ }
279
+
280
+ /* Common styling used inline */
281
+ .fixed-bottom, .fixed-top {
282
+ POSITION: fixed;
283
+ LEFT: 0;
284
+ z-index: 1030;
285
+ background-color: white;
286
+ }
287
+ .fixed-top {
288
+ TOP: 0;
289
+ }
290
+ .position-relative {
291
+ position: relative;
292
+ }
293
+ .float-left {
294
+ float: left;
295
+ }
296
+ .flex {
297
+ display: flex;
298
+ }
299
+ .align-items-center {
300
+ align-items: center;
301
+ }
302
+
303
+
304
+ .header {
305
+ /* The header div goes all across the top */
306
+ WIDTH: 100%;
307
+ box-shadow: 0 1px 4px 0 rgba(0,0,0,.1);
308
+ }
309
+
310
+ /* This houses the Logo */
311
+ .container-fluid {
312
+ width: 100%;
313
+ padding-right:15px;
314
+ padding-left:15px;
315
+ margin-right:auto;
316
+ margin-left:auto;
317
+ }
318
+
319
+
320
+ .site-logo {
321
+ box-shadow: 0 1px 4px 0 rgba(0,0,0,.1);
322
+ BACKGROUND: white;
323
+ display: inline-block;
324
+ }
325
+ .site-text {
326
+ BACKGROUND: white;
327
+ position: relative;
328
+ display: inline-block;
329
+ transform: translate( 0, 25% );
330
+ }
331
+
332
+ .nav-link:before {
333
+ background-color: #fbf5ff;
334
+ content: " ";
335
+ display: inline-block;
336
+ height: inherit;
337
+ left: 0;
338
+ margin-top: -.5rem;
339
+ position: absolute;
340
+ width: 3px;
341
+ height: 100%;
342
+ border-radius: 1rem;
343
+ }
344
+
345
+ /* Fixed sidenav */
346
+ .sidenav
347
+ {
348
+ WIDTH: 130px;
349
+ POSITION: fixed;
350
+ Z-INDEX: 1;
351
+ MARGIN-LEFT: 10px;
352
+ /* Must be below Logo */
353
+ MARGIN-TOP: 50px;
354
+ BACKGROUND: #eee;
355
+ OVERFLOW-X: hidden;
356
+ OVERFLOW-Y: auto;
357
+ max-height: calc( 100vh - 9rem);
358
+ }
359
+
360
+ /* Style the sidenav links and the dropdown button */
361
+ .sidenav a, .dropdown-btn, .accordion {
362
+ PADDING: 6px 8px 6px 16px; /* Top, Right, Bottom,Left */
363
+ TEXT-DECORATION: none;
364
+ FONT: 10.5px Poppins;
365
+ COLOR: #4b5465; /* Blueish Gray */
366
+ DISPLAY: block;
367
+ -webkit-text-stroke: #4b546;
368
+ TEXT-ALIGN: left;
369
+ CURSOR: pointer;
370
+ OUTLINE: none;
371
+ BACKGROUND: none;
372
+ /* Border around button */
373
+ BORDER: none;
374
+ }
375
+
376
+ /* On mouse-over */
377
+ .sidenav a:hover, .dropdown-btn: hover, .accordion: hover
378
+ {
379
+ COLOR: #064579; /* darker blue */
380
+ }
381
+
382
+ .accordion
383
+ {
384
+ transition: 0.4s;
385
+ }
386
+
387
+ /* accordion type divs */
388
+ .panel {
389
+ padding: 0 0px;
390
+ display: none;
391
+ background-color: white;
392
+ overflow: hidden;
393
+ }
394
+
395
+ .main {
396
+ MARGIN-LEFT: 148px; /* Same width as the sidebar + left position in px */
397
+ PADDING: 55px 10px; /* Top, Right, Bottom, Left */
398
+ }
399
+
400
+ /* Div within main, holding page information */
401
+ /* This is also used to hide all the sections at startup */
402
+ .section {
403
+ display: none; /* initially hidden */
404
+ }
405
+
406
+ /* Common paragraph sytling */
407
+ h1 {
408
+ FONT-SIZE: 2.5rem;
409
+ padding-top: 4rem;
410
+ }
411
+ h2 {
412
+ FONT-SIZE: 1.5rem;
413
+ }
414
+ h1, h2, h3, h4, h5 {
415
+ COLOR: #252930;
416
+ FONT-WEIGHT: 600;
417
+ }
418
+ h1, h2, h3, h4, h5, note, p {
419
+ FONT-FAMILY: Poppins,sans-serif;
420
+ MARGIN-TOP: 0;
421
+ MARGIN-BOTTOM: .5rem;
422
+ font-weight: 500;
423
+ line-height: 1.2;
424
+ }
425
+ note {
426
+ FONT-STYLE: italic;
427
+ FONT-SIZE: 1rem;
428
+ COLOR: #5d6778; /* blue-ish gray */
429
+ PADDING: 2rem;
430
+ }
431
+
432
+
433
+ /* Table styling */
434
+ table {
435
+ display: table;
436
+ border-collapse: collapse;
437
+ -webkit-border-horizontal-spacing: 2px;
438
+ -webkit-border-vertical-spacing: 2px;
439
+ width: 100%;
440
+ margin-bottom: 1rem;
441
+ }
442
+ th {
443
+ FONT-WEIGHT: bold;
444
+ border: 1px solid #e7e9ed;
445
+ text-align: center;
446
+ }
447
+ td {
448
+ padding: .75rem;
449
+ vertical-align: top;
450
+ border-top: 1px solid #e7e9ed;
451
+ FONT-WEIGHT: normal;
452
+ }
453
+ tr:nth-child(even) { background-color: #f2f2f2 } /* off white */
454
+
455
+ block-warning a {
456
+ color: #d09c13; /* Orange-ish */
457
+ }
458
+
459
+ /* Add an active class to the active dropdown button */
460
+ .active, .accordion: hover {
461
+
462
+ /* The background color of the active buttons */
463
+ background-color: #ccc; /* light gray */
464
+
465
+ /* The width of item is the width of the div */
466
+ /* Otherwise buttons appear half blocked */
467
+ width: 100%;
468
+ }
469
+
470
+ /* Optional: Style the caret down icon */
471
+ .fa-caret-down {
472
+ float: right;
473
+ }
474
+
475
+ /* Apply box-sizing to everything */
476
+ * {
477
+ box-sizing: border-box;
478
+ }
479
+
480
+ /* Some media queries for responsiveness */
481
+ @media screen and (max-height: 450px) {
482
+ .sidenav {PADDING-TOP: 15px;}
483
+ .sidenav a {FONT-SIZE: 12px;} /* height of items in accordion dropdown */
484
+ }
485
+ </STYLE>\n` );
486
+
487
+ }
488
+ function endHead( )
489
+ {
490
+ wfs( `</HEAD>\n` );
491
+ }
492
+
493
+ function addBody ()
494
+ {
495
+ wfs( `<BODY>\n` );
496
+
497
+ addFixedHeader_WithinBody();
498
+
499
+ addContentDiv_WithinBody( );
500
+
501
+ addAccordionScript_WithinEndOfBody();
502
+
503
+ addDropDownScript_WithinEndOfBody();
504
+
505
+ addToggleVisibilityScript_WithinEndOfBody( );
506
+
507
+ wfs( `</BODY>\n` );
508
+ }
509
+
510
+ function addFluidHeader_WithinFixedHeader()
511
+ {
512
+ wf( "+", `<div class="container-fluid position-relative">\n` );
513
+
514
+ addLogoDiv_WithinFluidHeader( );
515
+
516
+ endDiv( "container-fluid" );
517
+ }
518
+ function addFixedHeader_WithinBody()
519
+ {
520
+ wf( "+", `<HEADER class="header fixed-top">\n` );
521
+
522
+ addFluidHeader_WithinFixedHeader();
523
+
524
+ wf( "-", `</HEADER>\n` );
525
+ }
526
+
527
+
528
+ function addContentDiv_WithinBody( )
529
+ {
530
+ wf( "+", `<div class="content">\n` );
531
+
532
+ addSideNav_WithinContentDiv( )
533
+
534
+ addIntroductionPage_WithinContentDiv( )
535
+
536
+ addMain_withinContentDiv( );
537
+
538
+ endDiv( "content" );
539
+
540
+ }
541
+ function addMain_withinContentDiv( )
542
+ {
543
+ wf( "+", `<div class="main">\n` );
544
+
545
+ addDevicePages_WithinMain( )
546
+
547
+ addCharacteristicPages_WithinMain( );
548
+
549
+ addCmd4DirectivePages_WithinMain( );
550
+
551
+ addCmd4AccessoryDirectivePages_WithinMain( );
552
+
553
+ addCustomCharacteristicPages_withinMain( );
554
+
555
+ addScriptTemplatePages_WithinMain( );
556
+
557
+ endDiv( "main" );
558
+ }
559
+
560
+
561
+ function addLogoDiv_WithinFluidHeader( )
562
+ {
563
+ wf( "+", `<div class="site-logo">\n` );
564
+
565
+ wfs( `<img class="float-left" src="assets/images/Cmd4_icon.svg" width="40px" alt="logo">\n` );
566
+
567
+ wf( "+", `<div class="site-text">\n` );
568
+ wfs(`Cmd4\n`);
569
+ endDiv( "site-text" );
570
+
571
+ endDiv( "site-logo" );
572
+ }
573
+
574
+ // For this to work, it must be at the end of the Body
575
+ function addAccordionScript_WithinEndOfBody( )
576
+ {
577
+ wf( "+", `<script>\n` );
578
+ wfs(
579
+ `var acc = document.getElementsByClassName("accordion");
580
+ var i;
581
+
582
+ for (i = 0; i < acc.length; i++) {
583
+ acc[i].addEventListener("click", function() {
584
+ this.classList.toggle("active");
585
+ var panel = this.nextElementSibling;
586
+ if (panel.style.display === "block") {
587
+ panel.style.display = "none";
588
+ } else {
589
+ panel.style.display = "block";
590
+ }
591
+ });
592
+ }
593
+ ` );
594
+ wf( "-", `</script>\n` );
595
+ }
596
+
597
+ // For this to work, it must be at the end of the Body
598
+ function addToggleVisibilityScript_WithinEndOfBody( )
599
+ {
600
+ wf( "+", `<script type="text/javascript">\n` );
601
+ wfs(
602
+ `
603
+ function toggleVisibility( id )
604
+ {
605
+ var e = document.getElementById( id );
606
+ /* Hide the last one off */
607
+ if ( window.lastToggledE !== undefined )
608
+ {
609
+ window.lastToggledE.style.display = "none";
610
+ }
611
+
612
+ /* Show the new one on */
613
+ if ( e.style.display = "none" )
614
+ {
615
+ e.style.display = "block";
616
+ }
617
+
618
+ /* Set the last one to this one */
619
+ window.lastToggledE = e;
620
+ }
621
+ ` );
622
+ wf( "-", `</script>\n` );
623
+ }
624
+
625
+ // For this to work, it must be at the end of the Body
626
+ function addDropDownScript_WithinEndOfBody( )
627
+ {
628
+ wf( "+", `<script>\n` );
629
+ wfs( `
630
+ // Loop through all dropdown buttons to toggle between hiding and
631
+ // showing its dropdown content - This allows the user to have
632
+ // multiple dropdowns without any conflict
633
+
634
+ var dropdown = document.getElementsByClassName("dropdown-btn");
635
+
636
+ for (let i = 0; i < dropdown.length; i++)
637
+ {
638
+ dropdown[i].addEventListener("click", function()
639
+ {
640
+ this.classList.toggle("active");
641
+ var dropdownContent = this.nextElementSibling;
642
+ if (dropdownContent.style.display === "block")
643
+ {
644
+ dropdownContent.style.display = "none";
645
+ } else {
646
+ dropdownContent.style.display = "block";
647
+ }
648
+ });
649
+ }\n` );
650
+
651
+ wf( "-", `</script>\n` );
652
+
653
+ }
654
+
655
+ function addSideNav_WithinContentDiv( )
656
+ {
657
+ wf( "+", `<div class="sidenav">\n` );
658
+
659
+ addSideNavIntroductionLinks_WithinSideNav ();
660
+
661
+ addSideNavDevicesLinks_WithinSideNav( );
662
+
663
+ addSideNavCharacteristicsLinks_WithinSideNav( );
664
+
665
+ addSideNavCmd4DirectivesLinks_WithinSideNav( );
666
+
667
+ addSideNavCmd4AccessoryDirectivesLinks_WithinSideNav( );
668
+
669
+ addSideNavCustomCharacteristicsLinks_WithinSideNav( );
670
+
671
+ addSideNavScriptTemplateLinks_WithinSideNav( );
672
+
673
+ wfs( `<a href=https://github.com/ztalbot2000/homebridge-cmd4/blob/master/docs/Developers.md>Developers Guide</a>\n` );
674
+
675
+ wfs( `<a href=https://github.com/ztalbot2000/homebridge-cmd4/blob/master/docs/AdvancedTroubleShooting.md>Advanced TroubleShooting</a>\n` );
676
+
677
+ endDiv( "sidenav" );
678
+ }
679
+ function addSideNavDevicesLinks_WithinSideNav( )
680
+ {
681
+
682
+ // Accordion button for Devices
683
+ wf( "+", `<button class="accordion">Devices\n` );
684
+ wfs( `<i class="fa fa-caret-down"></i>\n` );
685
+ wf( "-", `</button>\n` );
686
+
687
+
688
+ wf( "+", `<div class="panel">\n` );
689
+
690
+ for ( let index=0; index < CMD4_DEVICE_TYPE_ENUM.EOL; index ++)
691
+ {
692
+ // We just need the index to look sorted
693
+ let deviceName = CMD4_Sorted_DEV.properties[ index ].deviceName;
694
+
695
+ wfs( `<a href="#${ deviceName }" onclick="toggleVisibility( '${ deviceName }');">${ deviceName }</a>\n` );
696
+ }
697
+
698
+ endDiv( "panel" );
699
+ }
700
+ function addSideNavIntroductionLinks_WithinSideNav ()
701
+ {
702
+ }
703
+
704
+ function addSideNavCharacteristicsLinks_WithinSideNav( )
705
+ {
706
+ // Accordion button for Characteristics
707
+ wf( "+", `<button class="accordion">Characteristics\n` );
708
+ wfs( `<i class="fa fa-caret-down"></i>\n` );
709
+ wf( "-", `</button>\n` );
710
+
711
+
712
+ wf( "+", `<div class="panel">\n` );
713
+ // We just need the index to look sorted
714
+ for ( let index=0; index < CMD4_ACC_TYPE_ENUM.EOL; index ++)
715
+ {
716
+ // Lower case characteristic
717
+ let characteristic = CMD4_Sorted_ACC.properties[ index ].sche;
718
+
719
+ wfs( `<a href="#${ characteristic }" onclick="toggleVisibility( '${ characteristic }');">${ characteristic }</a>\n` );
720
+ }
721
+ endDiv( "panel" );
722
+
723
+ }
724
+ function addSideNavCmd4DirectivesLinks_WithinSideNav( )
725
+ {
726
+ // Accordion button for Directives
727
+ wf( "+", `<button class="accordion">Directives\n` );
728
+ wfs( `<i class="fa fa-caret-down"></i>\n` );
729
+ wf( "-", `</button>\n` );
730
+
731
+ wf( "+", `<div class="panel">\n` );
732
+ wfs( `<a href="#${ constants.DEBUG }_D" onclick="toggleVisibility( 'Directives');">${ constants.DEBUG }</a>\n` );
733
+ wfs( `<a href="#${ constants.OUTPUTCONSTANTS }_D" onclick="toggleVisibility( 'Directives');">${ constants.OUTPUTCONSTANTS }</a>\n` );
734
+ wfs( `<a href="#${ constants.STATUSMSG }_D" onclick="toggleVisibility( 'Directives');">${ constants.STATUSMSG }</a>\n` );
735
+ wfs( `<a href="#${ constants.INTERVAL }_D" onclick="toggleVisibility( 'Directives');">${ constants.INTERVAL }</a>\n` );
736
+ wfs( `<a href="#${ constants.TIMEOUT }_D" onclick="toggleVisibility( 'Directives');">${ constants.TIMEOUT }</a>\n` );
737
+ wfs( `<a href="#${ constants.QUEUETYPES }_D" onclick="toggleVisibility( 'Directives');">${ constants.QUEUETYPES }</a>\n` );
738
+ wfs( `<a href="#${ constants.DEFINITIONS }_D" onclick="toggleVisibility( 'Directives');">${ constants.DEFINITIONS }</a>\n` );
739
+ endDiv( "panel" );
740
+
741
+ }
742
+
743
+ function addSideNavCmd4AccessoryDirectivesLinks_WithinSideNav( )
744
+ {
745
+ // Accordion button for Characteristics
746
+ wf( "+", `<button class="accordion">Accessory Directives\n` );
747
+ wfs( `<i class="fa fa-caret-down"></i>\n` );
748
+ wf( "-", `</button>\n` );
749
+
750
+
751
+ wf( "+", `<div class="panel">\n` );
752
+ wfs( `<a href="#${ constants.SUBTYPE }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.SUBTYPE }</a>\n` );
753
+ wfs( `<a href="#${ constants.FAKEGATO }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.FAKEGATO }</a>\n` );
754
+ wfs( `<a href="#${ constants.PUBLISHEXTERNALLY }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.PUBLISHEXTERNALLY }</a>\n` );
755
+ wfs( `<a href="#${ constants.STATE_CMD_PREFIX }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.STATE_CMD_PREFIX }</a>\n` );
756
+ wfs( `<a href="#${ constants.STATE_CMD_SUFFIX }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.STATE_CMD_SUFFIX }</a>\n` );
757
+ wfs( `<a href="#${ constants.STATE_CMD }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.STATE_CMD }</a>\n` );
758
+ wfs( `<a href="#${ constants.POLLING }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.POLLING }</a>\n` );
759
+ wfs( `<a href="#${ constants.INTERVAL }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.INTERVAL }</a>\n` );
760
+ wfs( `<a href="#${ constants.TIMEOUT }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.TIMEOUT }</a>\n` );
761
+ wfs( `<a href="#${ constants.QUEUETYPES }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.QUEUETYPES }</a>\n` );
762
+ wfs( `<a href="#${ constants.QUEUE }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.QUEUE }</a>\n` );
763
+ wfs( `<a href="#${ constants.STATECHANGERESPONSETIME }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.STATECHANGERESPONSETIME }</a>\n` );
764
+ wfs( `<a href="#${ constants.LINKEDTYPES }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.LINKEDTYPES }</a>\n` );
765
+ wfs( `<a href="#${ constants.OUTPUTCONSTANTS }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.OUTPUTCONSTANTS }</a>\n` );
766
+ wfs( `<a href="#${ constants.STATUSMSG }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.STATUSMSG }</a>\n` );
767
+ endDiv( "panel" );
768
+
769
+ }
770
+
771
+ function addSideNavCustomCharacteristicsLinks_WithinSideNav( )
772
+ {
773
+ // Accordion button for Characteristics
774
+ wf( "+", `<button class="accordion">Custom Characteristics\n` );
775
+ wfs( `<i class="fa fa-caret-down"></i>\n` );
776
+ wf( "-", `</button>\n` );
777
+
778
+ wf( "+", `<div class="panel">\n` );
779
+ wfs( `<a href="#CUSTOM_CHARACTERISTICS" onclick="toggleVisibility( 'CustomCharacteristics');">Custom Characteristics</a>\n` );
780
+ endDiv( "panel" );
781
+ }
782
+
783
+ function addSideNavScriptTemplateLinks_WithinSideNav( )
784
+ {
785
+ // Accordion button for ScriptTemplates
786
+ wf( "+", `<button class="accordion">Script Templates\n` );
787
+ wfs( `<i class="fa fa-caret-down"></i>\n` );
788
+ wf( "-", `</button>\n` );
789
+
790
+ wf( "+", `<div class="panel">\n` );
791
+
792
+ CMD4_SCRIPTS.forEach( ( script ) =>
793
+ {
794
+ //wfs( `<a href="#${ script.link }">${ script.link }</a>\n` );
795
+ wfs( `<a href="#${ script.link }" onclick="toggleVisibility( '${ script.link }');">${ script.link }</a>\n` );
796
+ });
797
+
798
+ endDiv( "panel" );
799
+
800
+ }
801
+
802
+ function addIntroductionPage_WithinContentDiv( )
803
+ {
804
+ wf( "+", `<div class="main">\n` );
805
+ wfs( `<h2>CMD4 Portal</h2>\n` );
806
+ wfs( `<p>This auto generated document replaces much of the hard coded definitions and is the portal to everything that is Cmd4.</p>\n` );
807
+ wfs( `<p>Enjoy</p>\n` );
808
+ wfs( `<p>&nbsp;&nbsp;&nbsp;John Talbot</p>\n` );
809
+
810
+ endDiv( "main" );
811
+ }
812
+
813
+ function addDevicePages_WithinMain( )
814
+ {
815
+ //wfs( `<h2>CMD4 Device Properties</h2>\n` );
816
+ //wfs( `<p>This auto generated document replaces the hard coded, impossible to maintain definitions in what was the State.js script and other locations.</p>\n` );
817
+
818
+ for ( let index=0; index < CMD4_DEVICE_TYPE_ENUM.EOL; index ++)
819
+ {
820
+ let deviceName = CMD4_DEVICE_TYPE_ENUM.properties[ index ].deviceName;
821
+
822
+ addSingleDeviceContent( index, deviceName );
823
+ }
824
+
825
+ }
826
+
827
+ function addSingleDeviceContent(device_type_enum, deviceName )
828
+ {
829
+ let definition = CMD4_DEVICE_TYPE_ENUM.properties[ device_type_enum ];
830
+ let requiredCharacteristics = definition.requiredCharacteristics;
831
+ let optionalCharacteristics = definition.optionalCharacteristics;
832
+ let defaultPollingCharacteristics = definition.defaultPollingCharacteristics;
833
+ let commaNeeded = true;
834
+
835
+ // Start deviceName Div
836
+ // The <div id> is used to show/hide the section.
837
+ // The <class> is used for css formatting, including initial hide.
838
+ // The <a name> is used to jump here when nav item clicked.
839
+ wf( "+", `<div id="${ deviceName }" class="section">\n` );
840
+ wfs( `<a name="${ deviceName }"></a>\n` );
841
+ wfs( `<header><h1>${ deviceName }</h1></header>\n` );
842
+ wfs( `<p>UUID:${ definition.UUID }</p>\n` );
843
+
844
+ // Required Characteristics
845
+ wfs( `<H3>Required Characteristics</H3>\n` );
846
+ if ( requiredCharacteristics && requiredCharacteristics.length > 0 )
847
+ {
848
+ wf( "+", `<table>\n` );
849
+ wfs( `<TD> </TD><TD> Default Value </TD><TD> Constant </TD>\n` );
850
+
851
+ requiredCharacteristics.forEach( ( characteristic ) =>
852
+ {
853
+ // Look up the characteristic index given, to its string value
854
+ let characteristicString = CMD4_ACC_TYPE_ENUM.properties[ characteristic.type ].sche;
855
+ let defaultValue = characteristic.defaultValue;
856
+
857
+ let transposed = transposeValueToValidConstant( CMD4_ACC_TYPE_ENUM.properties, characteristic.type, defaultValue );
858
+
859
+ if ( transposed == defaultValue )
860
+ transposed = "n/a";
861
+
862
+ wfs( `<tr><TD><UL><LI><a href="#${ characteristicString }">${ characteristicString }</a></UL></TD><TD> ${ defaultValue } </TD><TD> ${ transposed } </TD>\n` );
863
+ });
864
+ wf( "-", `</Table>\n` );
865
+ }
866
+
867
+
868
+ // Optional Characteristics
869
+ wfs( `<H3>Optional Characteristics</H3>\n` );
870
+ if ( optionalCharacteristics && optionalCharacteristics.length > 0 )
871
+ {
872
+ wf( "+", `<UL>\n` );
873
+ optionalCharacteristics.forEach( ( characteristic ) =>
874
+ {
875
+ let characteristicString = CMD4_ACC_TYPE_ENUM.properties[ characteristic ].sche;
876
+ wfs( `<LI><a href="#${ characteristicString }">${ characteristicString }</a>\n` );
877
+ });
878
+ wf( "-", `</UL>\n` );
879
+ }
880
+
881
+ // Default Polling Characteristics
882
+ if ( defaultPollingCharacteristics && defaultPollingCharacteristics.length > 0 )
883
+ {
884
+ wfs( `<H3>Default Polling Characteristics</H3>\n` );
885
+ wfs( `<note> Default polling characteristics are characteristics that would automatically be polled if Accessory Polling is configured ( polling:true ) instead of characteristic polling where each characteristic is set individually.\n` );
886
+ wf( "+", `<UL>\n` );
887
+
888
+ defaultPollingCharacteristics.forEach( ( characteristic ) =>
889
+ {
890
+ let characteristicString = CMD4_ACC_TYPE_ENUM.properties[ characteristic ].sche;
891
+ wfs( `<LI><a href="#${ characteristicString }">${ characteristicString }</a>\n` );
892
+ });
893
+
894
+ wf( "-", `</UL>\n` );
895
+ }
896
+ wfs( `<H3>Example config.json entry</H3>\n` );
897
+ commaNeeded = true;
898
+
899
+ // This is pre-formatted text
900
+ wfs( `<pre>\n` );
901
+
902
+ // The stuff in the brace will be indented
903
+ wf( "+", `{\n` );
904
+ wfs( `${ constants.TYPE }: ${ definition.deviceName },\n` );
905
+ let nameCharacteristicString = CMD4_ACC_TYPE_ENUM.properties[ CMD4_ACC_TYPE_ENUM.Name ].sche;
906
+ wfs( `${ nameCharacteristicString }: "MY_${ definition.deviceName }",\n` );
907
+ wfs( `${ constants.DISPLAYNAME }: "MY_${ definition.deviceName }"` );
908
+ if ( requiredCharacteristics && requiredCharacteristics.length > 0 )
909
+ {
910
+ requiredCharacteristics.forEach( ( characteristic ) =>
911
+ {
912
+ let requiredDefinition = CMD4_ACC_TYPE_ENUM.properties[ characteristic.type ];
913
+ if ( commaNeeded )
914
+ w( `,\n` );
915
+
916
+ // Look up the characteristic index given, to its string value
917
+ let characteristicString = requiredDefinition.sche;
918
+ let defaultValue = characteristic.defaultValue;
919
+ wfs( `${ characteristicString }: "${ defaultValue}"` );
920
+ });
921
+ }
922
+
923
+ if ( optionalCharacteristics && optionalCharacteristics.length > 0 )
924
+ {
925
+ optionalCharacteristics.forEach( ( characteristic ) =>
926
+ {
927
+ let optionalDefinition = CMD4_ACC_TYPE_ENUM.properties[ characteristic ];
928
+ let characteristicString = optionalDefinition.sche;
929
+
930
+ if ( optionalDefinition.type == CMD4_ACC_TYPE_ENUM.Name )
931
+ return;
932
+
933
+ // Do not show TLV8 characteristics
934
+ let format = optionalDefinition.props.format;
935
+ switch( format )
936
+ {
937
+ case Characteristic.Formats.TLV8:
938
+ return;
939
+ case Characteristic.Formats.INT:
940
+ if ( commaNeeded ) w( `,\n` );
941
+ wfs( `${ characteristicString }: < INT >` );
942
+ break;
943
+ case Characteristic.Formats.UINT8:
944
+ if ( commaNeeded ) w( `,\n` );
945
+ wfs( `${ characteristicString }: < UINT8 >` );
946
+ break;
947
+ case Characteristic.Formats.UINT16:
948
+ if ( commaNeeded ) w( `,\n` );
949
+ wfs( `${ characteristicString }: < UINT16 >` );
950
+ break;
951
+ case Characteristic.Formats.UINT32:
952
+ if ( commaNeeded ) w( `,\n` );
953
+ wfs( `${ characteristicString }: < UINT32 >` );
954
+ break;
955
+ case Characteristic.Formats.UINT64:
956
+ if ( commaNeeded ) w( `,\n` );
957
+ wfs( `${ characteristicString }: < UINT64 >` );
958
+ break;
959
+ case Characteristic.Formats.STRING:
960
+ if ( commaNeeded ) w( `,\n` );
961
+ wfs( `${ characteristicString }: "< STRING> "` );
962
+ break;
963
+ case Characteristic.Formats.BOOL:
964
+ if ( commaNeeded ) w( `,\n` );
965
+ wfs( `${ characteristicString }: < BOOLEAN >` );
966
+ break;
967
+ case Characteristic.Formats.ARRAY:
968
+ if ( commaNeeded ) w( `,\n` );
969
+ wfs( `${ characteristicString }: < ARRAY >` );
970
+ break;
971
+ case Characteristic.Formats.DATA:
972
+ if ( commaNeeded ) w( `,\n` );
973
+ wfs( `${ characteristicString }: < DATA >` );
974
+ break;
975
+ case Characteristic.Formats.DICTIONARY:
976
+ if ( commaNeeded ) w( `,\n` );
977
+ wfs( `${ characteristicString }: < DICTIONARY >` );
978
+ break;
979
+ default:
980
+ if ( commaNeeded ) w( `,\n` );
981
+ wfs( `Unknown format ${ format }` );
982
+ }
983
+ });
984
+ }
985
+
986
+ if ( commaNeeded ) w( `,\n` );
987
+ wfs( `<a href="#${ constants.STATE_CMD }">${ constants.STATE_CMD }</a>: < "STRING" >,\n` );
988
+ wfs( `<a href="#${ constants.POLLING }">${ constants.POLLING }</a>: < POLLING>\n` );
989
+ // The last carriage return before the close brace
990
+ w( `\n` );
991
+
992
+ // End of the indented stuff in the brace
993
+ wf( "-", `}\n` );
994
+
995
+ // End of pre-formatted text
996
+ wfs( `</pre>\n` );
997
+
998
+ wfs( `See additional <a href="#CMD4 Accessory Directives">CMD4 Accessory Directives</a>\n` );
999
+
1000
+ endDiv( deviceName );
1001
+ }
1002
+
1003
+ function addCharacteristicPages_WithinMain( )
1004
+ {
1005
+ //
1006
+ // Add the characteristic content within the HTML body
1007
+ //
1008
+ for ( let index=0; index < CMD4_ACC_TYPE_ENUM.EOL; index ++)
1009
+ {
1010
+ let characteristic = CMD4_ACC_TYPE_ENUM.properties[ index ].sche;
1011
+
1012
+ addSingleCharacteristicContent( index, characteristic );
1013
+
1014
+ }
1015
+ }
1016
+
1017
+ function addSingleCharacteristicContent( acc_type_enum, characteristic )
1018
+ {
1019
+ let definition = CMD4_ACC_TYPE_ENUM.properties[ acc_type_enum ];
1020
+ let props = CMD4_ACC_TYPE_ENUM.properties[ acc_type_enum ].props;
1021
+
1022
+ // Start characteristic div
1023
+ // The <div id> is used to show/hide the section.
1024
+ // The <class> is used for css formatting, including initial hide.
1025
+ // The <a name> is used to jump here when nav item clicked.
1026
+ wf( "+", `<div id="${ characteristic }" class="section" >\n` );
1027
+ wfs( `<a name="${ characteristic }"></a>\n` );
1028
+ wfs( `<header><h1>${ characteristic }</h1></header>\n` );
1029
+ wfs( `<h3>Properties</h3>\n` );
1030
+ wf( "+",
1031
+ `<table>\n` );
1032
+ wfs( `<tr><TD> Type: </TD><TD> ${ characteristic }</TD></tr>\n` );
1033
+
1034
+ if ( definition.UUID )
1035
+ wfs( `<tr><TD> UUID: </TD><TD> ${ definition.UUID }</TD></tr>\n` );
1036
+
1037
+ if ( props.format )
1038
+ wfs( `<tr><TD> Format: </TD><TD> ${ props.format }</TD></tr>\n` );
1039
+
1040
+ if ( props.unit )
1041
+ wfs( `<tr><TD> Unit: </TD><TD> ${ props.unit }</TD></tr>\n` );
1042
+
1043
+ if ( props.minValue )
1044
+ wfs( `<tr><TD> Min Value: </TD><TD> ${ props.minValue }</TD></tr>\n` );
1045
+
1046
+ if ( props.maxValue )
1047
+ wfs( `<tr><TD> Max Value: </TD><TD> ${ props.maxValue }</TD></tr>\n` );
1048
+
1049
+ if ( props.minStep )
1050
+ wfs( `<tr><TD> Min Step: </TD><TD> ${ props.minStep }</TD></tr>\n` );
1051
+
1052
+ if ( props.perms )
1053
+ {
1054
+ let output = "";
1055
+ let comma = "";
1056
+ props.perms.forEach( ( perm ) =>
1057
+ {
1058
+ switch( perm )
1059
+ {
1060
+ case "pr":
1061
+ output = output + comma + "Paired Read";
1062
+ break;
1063
+ case "pw":
1064
+ output = output + comma + "Paired Write";
1065
+ break;
1066
+ case "ev":
1067
+ output = output + comma + "Events";
1068
+ break;
1069
+ case "tw":
1070
+ output = output + comma + "Timed Write";
1071
+ break;
1072
+ case "wr":
1073
+ output = output + comma + "Write Response";
1074
+ break;
1075
+ default:
1076
+ console.log( "Unknown perm: %s", perm );
1077
+ process.exit(333);
1078
+ }
1079
+ comma = ", ";
1080
+ });
1081
+ wfs( `<tr><TD> Perms: </TD><TD> ${ output }</TD></tr>\n` );
1082
+
1083
+ }
1084
+ wf( "-", `</table>\n` );
1085
+
1086
+ // Constants definition Table
1087
+ let defs = Object.keys( definition.validValues );
1088
+ if ( defs.length > 0 )
1089
+ {
1090
+ wfs( `<h3>Constants</h3>\n` );
1091
+ wf( "+", `<table>\n` );
1092
+ wfs( `<TD> Value </TD><TD> String </TD>\n` );
1093
+
1094
+ defs.forEach( ( def ) =>
1095
+ {
1096
+ wfs( `<tr><TD> ${ definition.validValues[ def ] } </TD><TD> "${ def }" </TD></tr>\n` );
1097
+ });
1098
+
1099
+ wf( "-", `</table>\n` );
1100
+ }
1101
+
1102
+ // Verify Chsracteristic Notes
1103
+ let verify = definition.verifyCharacteristic;
1104
+ if ( verify )
1105
+ {
1106
+ wfs( `<h4>Note:</h4>\n` );
1107
+ wfs( `<note>Setting this characteristic will automstically trigger a "Get" of the characteristic: <a href="#${ verify.name }">${ verify.name }</a></note>\n` );
1108
+
1109
+ }
1110
+
1111
+ endDiv( characteristic ); // Closing DIV of Characteristic
1112
+
1113
+ }
1114
+
1115
+ function addCmd4DirectivePages_WithinMain( )
1116
+ {
1117
+ // Start Directives div
1118
+ // The <div id> is used to show/hide the section.
1119
+ // The <class> is used for css formatting, including initial hide.
1120
+ // The <a name> is used to jump here when nav item clicked.
1121
+ wf( "+", `<div id="Directives" class="section">\n` );
1122
+
1123
+ wfs( `<h2>CMD4 Directives</h2>\n` );
1124
+ wfs( `<p>These directives appear within the "Cmd4" plugin header and reflect how Cmd4 will behave overall.</p>\n` );
1125
+
1126
+
1127
+ wf( "+", `<TABLE WIDTH="100%">\n` );
1128
+ wfs( `<TR ALIGN="left"><TH>Cmd4Directive<TH>Type<TH PADDING="50px">Default<TH>Description</TR>\n` );
1129
+
1130
+ // debug - CMD4 Directives
1131
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.DEBUG }_D">${ constants.DEBUG }</a><TD> < Bool > <TD> false <TD> Output Debug messages. Can also be accomplished with setenv DEBUG=${ settings.PLATFORM_NAME}</TR>\n` );
1132
+
1133
+ // outputConstants - CMD4 Directives
1134
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.OUTPUTCONSTANTS }_D">${ constants.OUTPUTCONSTANTS }</a><TD> < Bool > <TD> false <TD> If Cmd4 will send Strings like "TRUE" or "FALSE" instead of 0 | 1 for all Accessories</TR>\n` );
1135
+
1136
+ // statusMsg - CMD4 Directives - See cmd4Constants as why we do this
1137
+ let defaultStatusMsg = constants.DEFAULT_STATUSMSG;
1138
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.STATUSMSG }_D"> ${ constants.STATUSMSG }</a><TD> < Bool > <TD> ${ defaultStatusMsg } <TD> Cmd4 will log a Set Status Message for all Accessories.</TR>\n` );
1139
+
1140
+ // Interval - CMD4 Directives
1141
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.INTERVAL }_D"> ${ constants.INTERVAL }</a><TD> ${ constants.INTERVAL } <TD> ${ constants.DEFAULT_INTERVAL * .001 } < seconds > <TD> How long before killing the state command of all polled characteristics. See <a href="#${ constants.INTERVAL }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.INTERVAL }</a> in Accessory Directives for full description as it can also be set per accessory or per characteristic.</TR>\n` );
1142
+
1143
+ // Timeout - CMD4 Directives
1144
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.TIMEOUT }_D"> ${ constants.TIMEOUT }</a><TD> ${ constants.TIMEOUT } <TD> ${ constants.DEFAULT_TIMEOUT } < msec > <TD> How long before killing the state command of all polled characteristics. See <a href="#${ constants.TIMEOUT }" onclick="toggleVisibility( 'AccessoryDirectives');">${ constants.TIMEOUT }</a> in Accessory Directives for full description as it can also be set per accessory or per characteristic.</TR>\n` );
1145
+
1146
+ // QueueTypes - CMD4 Directives
1147
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.QUEUETYPES }_D"> ${ constants.QUEUETYPES }</a><TD> < Array of < ${ constants.QUEUE }: < "name" >, ${ constants.QUEUETYPE }: < ${ constants.QUEUETYPE_SEQUENTIAL } | ${ constants.QUEUETYPE_WORM } > <TD> none <TD> Pre-defines Queue types. This Directive can also be per queue as noted by its presence as an accessory directive.</TR>\n` );
1148
+
1149
+ // Definitions - Custom Characteristics - CMD4 Directives
1150
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.DEFINITIONS }_D"> ${ constants.DEFINITIONS }</a><TD> < Array > <TD> <TD> An Array of new Characteristic Objects. See <a href="#CUSTOM_CHARACTERISTICS" onclick="toggleVisibility( 'CustomCharacteristics');">Custom Characteristics, around line 339</a> for more information</TR>\n` );
1151
+
1152
+ wf( "-", `</TABLE>\n` );
1153
+ endDiv( "main" );
1154
+
1155
+ }
1156
+
1157
+ function addCmd4AccessoryDirectivePages_WithinMain( )
1158
+ {
1159
+ // Start AccessoryDirectives div
1160
+ // The <div id> is used to show/hide the section.
1161
+ // The <class> is used for css formatting, including initial hide.
1162
+ // The <a name> is used to jump here when nav item clicked.
1163
+ wf( "+", `<div id="AccessoryDirectives" class="section">\n` );
1164
+
1165
+ wfs( `<h2><a name="CMD4 Accessory Directives">CMD4 Accessory Directives</a></h2>\n` );
1166
+ wfs( `<p>These directives appear within the characteristic section of the Cmd4 Accessory</p>\n` );
1167
+
1168
+ wf( "+", `<TABLE WIDTH="100%" border: 1px solid black >\n` );
1169
+ wfs( `<TR cols="4" ALIGN="left"><TH>Cmd4Directive<TH>Type<TH PADDING="50px">Default<TH>Description</TR>\n` );
1170
+
1171
+ // subType
1172
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.SUBTYPE }">${ constants.SUBTYPE }</a><TD> < unique string > <TD> accessory.name <TD> Used to distinguish accessories that have same Type and Name.</TR>\n` );
1173
+
1174
+ // outputConstants - AccessoryDirectives
1175
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.OUTPUTCONSTANTS }">${ constants.OUTPUTCONSTANTS }</a><TD> < Bool > <TD> false <TD> If Cmd4 will send Strings like "TRUE" or "FALSE" instead of 0 | 1 </TR>\n` );
1176
+
1177
+ // statusMsg - AccessoryDirectives
1178
+ let defaultStatusMsg = constants.DEFAULT_STATUSMSG;
1179
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.STATUSMSG }">${ constants.STATUSMSG }</a><TD> < Bool > <TD> ${ defaultStatusMsg } <TD>Cmd4 will log a Set Status Message</TR>\n` );
1180
+
1181
+ // publishExternally - AccessoryDirectives
1182
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.PUBLISHEXTERNALLY }">${ constants.PUBLISHEXTERNALLY }</a><TD> < Bool > <TD> false <TD> Tell Homebridge to publish the device as its own bridge. </TR>\n` );
1183
+
1184
+ // stateChangeResponseTime - AccessoryDirectives
1185
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.STATECHANGERESPONSETIME }">${ constants.STATECHANGERESPONSETIME }</a><TD> < seconds > <TD> 60 <TD> How long to wait between a Set and Get command.</TR>\n` );
1186
+
1187
+ // interval - AccessoryDirectives
1188
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.INTERVAL }">${ constants.INTERVAL }</a><TD> < seconds > <TD> ${ constants.DEFAULT_INTERVAL * .001 } < seconds > <TD> How long between polls of all polled characteristics.</TR>\n` );
1189
+
1190
+ // timeout - AccessoryDirectives
1191
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.TIMEOUT }">${ constants.TIMEOUT }</a><TD> < msec > <TD> ${ constants.DEFAULT_TIMEOUT } < msec > <TD> How long before killing the state command of all polled characteristics.</TR>\n` );
1192
+
1193
+ // polling - AccessoryDirectives
1194
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.POLLING }">${ constants.POLLING }</a><TD> < Bool > <TD> false <TD> If the characteristics should be polled for state change.</TR>\n` );
1195
+
1196
+ wfs( `<TR><TD><TD COLSPAN=3> or [{"characteristic" < characteristic >, [ "interval": < sec >, "timeout": < msec > ] }] The timeout and interval override any higher directive.</TR>\n` );
1197
+
1198
+ // QueueTypes - AccessoryDirectives
1199
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.QUEUETYPES }"> ${ constants.QUEUETYPES }</a><TD> none <TD> < Array of < ${ constants.QUEUE }: < "name" >, ${ constants.QUEUETYPE }: < ${ constants.QUEUETYPE_SEQUENTIAL } | ${ constants.QUEUETYPE_WORM } <TD> none <TD> Pre-defines the Queue types.</TR>\n` );
1200
+
1201
+ // Queue - AccessoryDirectives
1202
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.QUEUE }"> ${ constants.QUEUE }</a><TD> ${ constants.QUEUE } <TD> < String > <TD> Defines which Queue polled characteristics will be placed.</TR>\n` );
1203
+
1204
+ // state_cmd - AccessoryDirectives
1205
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.STATE_CMD }">${ constants.STATE_CMD }</a><TD> < ${ constants.STATE_CMD } > <TD> See Description <TD> The command used to Get/Set Device characteristic State.</TR>\n` );
1206
+ wfs( `<TR><TD COLSPAN="4">The ${ constants.STATE_CMD } represents the path to your script. Cmd4 appends the Get/Set shown.<BR>\n` );
1207
+ wfs( `${ constants.STATE_CMD } Get < DisplayName > < characteristic ><BR>\n` );
1208
+ wfs( `${ constants.STATE_CMD } Set < DisplayName > < characteristic > < value ></TD></TR>\n` );
1209
+
1210
+ // state_cmd_prefix - AccessoryDirectives
1211
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.STATE_CMD_PREFIX }">${ constants.STATE_CMD_PREFIX }</a><TD> < String > <TD> <TD> A String prepended to the < ${ constants.STATE_CMD } >.</TR>\n` );
1212
+
1213
+ // state_cmd_suffix - AccessoryDirectives
1214
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.STATE_CMD_SUFFIX }">${ constants.STATE_CMD_SUFFIX }</a><TD> < String > <TD> <TD> A String appended to the < ${ constants.STATE_CMD } >.</TR>\n` );
1215
+
1216
+ // props - AccessoryDirectives
1217
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.PROPS }">${ constants.PROPS }</a><TD> < Bool > <TD> false <TD> A way to override Hap Characteristiic Properties<BR>\n` );
1218
+ wfs( ` Only used to set min/max temperatures, for instance:</TR>\n` );
1219
+ wfs( `<TR ALIGN="Left"><TD><TD COLSPAN=3>"${ constants.PROPS }" : { "currentTemperature": { "maxValue":100, "minValue": -100, "minStep": 0.1}}</TR>\n` );
1220
+
1221
+ // category - AccessoryDirectives
1222
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.CATEGORY }">${ constants.CATEGORY }</a><TD> < CATEGORY > <TD> <TD> See <a href="https://developers.homebridge.io/#/categories">Homebridge Categories</a> for a complete list of possible categories. </TR>\n` );
1223
+
1224
+ // fakegato - AccessoryDirectives
1225
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.FAKEGATO }">${ constants.FAKEGATO }</a><TD> < JSON > <TD> <TD> See the section, <a href="https://github.com/ztalbot2000/homebridge-cmd4/README.md#fakegatotag"> "Adding in Fakegato history"</a> below.</TR>\n` );
1226
+
1227
+ // linkedTypes - AccessoryDirectives
1228
+ wfs( `<TR ALIGN="left"><TD><a name="${ constants.LINKEDTYPES }">${ constants.LINKEDTYPES }</a><TD> < JSON > <TD> <TD> Other Cmd4 Accessories like Input Source for HDMI inputs. </TR>\n` );
1229
+
1230
+
1231
+ wf( "-", `</TABLE>\n` );
1232
+ endDiv( "main" );
1233
+
1234
+ }
1235
+
1236
+ function addCustomCharacteristicPages_withinMain( )
1237
+ {
1238
+ wf( "+", `<div id="CustomCharacteristics" class="section">\n` );
1239
+
1240
+ wfs( `<h2><a name="CUSTOMCHARACTERISTICS">Custom Characteristics</a></h2>\n` );
1241
+ wfs( `<p>These directives appear within the Cmd4 Platform section</p><BR>\n` );
1242
+ wfs( `<p>IMPORTANT - It is unlikely that adding custom characteristics will be supported by any GUI or SIRI<BR>\n` );
1243
+ wfs( `<BR><BR>\n` );
1244
+ wfs( `<p>Custom characteristics in Cmd4 do not stray far from how Homebridge uses them from HAP-NodeJS. To create a custom characteristic an object entry is programmatically added to <a href="https://github.com/ztalbot2000/homebridge-cmd4/blob/master/lib/CMD4_ACC_TYPE_ENUM.js">lib/CMD4_ACC_TYPE_ENUM.js</a> via an entry you define in your config.json. The best way to show how to define a custom characteristic is through an example</p>.\n` );
1245
+ wf( "+", `<pre>\n` );
1246
+ wfs( `{\n` );
1247
+ wfs( ` "platform": "Cmd4",\n` );
1248
+ wfs( ` "outputConstants": false,\n` );
1249
+ wfs( ` "statusMsg": true,\n` );
1250
+ wfs( ` "Definitions": [\n` );
1251
+ wfs( ` { "type": "PointX",\n` );
1252
+ wfs( ` "description": "An X Coordinate",\n` );
1253
+ wfs( ` "props": { "format": "uint32",\n` );
1254
+ wfs( ` "minValue": 0,\n` );
1255
+ wfs( ` "minStep": 1,\n` );
1256
+ wfs( ` "perms": [ "ev", "pr", "pw" ]\n` );
1257
+ wfs( ` }\n` );
1258
+ wfs( ` }\n` );
1259
+ wfs( ` ],\n` );
1260
+ wfs( ` "accessories": [\n` );
1261
+ wfs( ` { "type": "Switch",\n` );
1262
+ wfs( ` "name": "PS_4",\n` );
1263
+ wfs( ` "PointX": 3267,\n` );
1264
+ wfs( ` "on": false,\n` );
1265
+ wfs( ` "polling": [ { "characteristic": "on", "interval": 50 },\n` );
1266
+ wfs( ` { "characteristic": "pointX", "interval": 5 }\n` );
1267
+ wfs( ` ],\n` );
1268
+ wfs( ` "state_cmd": "node .homebridge/Cmd4Scripts/AnyDevice.js"\n` );
1269
+ wfs( ` }\n` );
1270
+ wfs( ` ]\n` );
1271
+ wfs( `}\n` );
1272
+ wf( "-", `</pre>\n` );
1273
+ wfs( `<BR><BR>\n` );
1274
+ wfs( `<p>The definitions for "props" can be found at: <a href="https://github.com/homebridge/HAP-NodeJS/blob/master/src/lib/Characteristic.ts">HAP Characteristics - line 259</a></p>\n` );
1275
+
1276
+
1277
+
1278
+ endDiv( "CustomCharacteristics" );
1279
+ }
1280
+
1281
+ function addScriptTemplatePages_WithinMain( )
1282
+ {
1283
+ CMD4_SCRIPTS.forEach( ( script ) =>
1284
+ {
1285
+ addScriptPage_WithinMain( script );
1286
+ });
1287
+ }
1288
+
1289
+ function addScriptPage_WithinMain( script )
1290
+ {
1291
+ // Start script.link div
1292
+ // The <div id> is used to show/hide the section.
1293
+ // The <class> is used for css formatting, including initial hide.
1294
+ // The <a name> is used to jump here when nav item clicked.
1295
+ wf( "+", `<div id="${ script.link }" class="section">\n` );
1296
+
1297
+ wfs( `<h2><a name="${ script.link }">${ script.description }</a></h2>\n` );
1298
+ // Create the full path to the file.
1299
+ let file = script.filePath + script.file;
1300
+
1301
+ wfs( `<p> This script is auto generated from: <a href=https://github.com/ztalbot2000/homebridge-cmd4/blob/master/${ file }>${ file } </a></p>\n` );
1302
+ wf( "+", `<pre>\n` );
1303
+
1304
+
1305
+ let readStream = fs.readFileSync( file, {encoding: 'utf8'} );
1306
+ w( readStream );
1307
+
1308
+ wf( "-", `</pre>\n` );
1309
+
1310
+ endDiv( "main" );
1311
+ }
1312
+
1313
+ function endDiv( comment )
1314
+ {
1315
+ let div = "</DIV>";
1316
+ if ( comment )
1317
+ div = div + ` <!-- ${comment} -->`;
1318
+
1319
+ div = div + "\n";
1320
+
1321
+ wf( "-" , div );
1322
+ }
1323
+
1324
+
1325
+ // Write to fid the given text, increasing or decreasing divLevel.
1326
+ function wf( level, text )
1327
+ {
1328
+ // Subtract now
1329
+ if ( level == "-" )
1330
+ divLevel--;
1331
+
1332
+ fid.write( " ".repeat( divLevel * INDENT ).concat( text ) );
1333
+
1334
+ // Add later
1335
+ if (level == "+" )
1336
+ divLevel++;
1337
+ }
1338
+
1339
+ // Convenience function for wfs. writing to same level.
1340
+ function wfs( text )
1341
+ {
1342
+ wf( "nc", text );
1343
+ }
1344
+ // Convenience function to write to fid, no formatting, as is.
1345
+ function w( text )
1346
+ {
1347
+ fid.write( text );
1348
+ }
1349
+
1350
+ createHTMLCmd4AccDocument( );
1351
+
1352
+ if ( divLevel == 0)
1353
+ {
1354
+ console.log( "Yahoo ! All lined up. " );
1355
+ return 0;
1356
+ } else {
1357
+ console.log( "Booo ... alignment failed: %s", ['','+'][Number(divLevel > 0)] + divLevel );
1358
+ }
1359
+ return divLevel;