-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathrfxcom.spec.js
More file actions
4732 lines (4675 loc) · 234 KB
/
rfxcom.spec.js
File metadata and controls
4732 lines (4675 loc) · 234 KB
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* global require: false, describe: false, module */
const rfxcom = require('../lib'),
FakeSerialPort = require('./helper'),
matchers = require('./matchers'),
protocols = rfxcom.protocols;
describe("RfxCom", function() {
beforeEach(function() {
jasmine.addMatchers({
toHaveSent: matchers.toHaveSent
});
});
describe("RfxCom class", function() {
describe("constructor", function() {
it("should be initialised correctly when created", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
expect(device.portEventHandlersInstalled).toEqual(false);
expect(device.initialiseWaitTime).toBe(6000);
expect(device._seqnbr).toBe(0);
expect(device.connected).toEqual(false);
expect(device.initialising).toEqual(false);
expect(device.receiving).toEqual(false);
expect(device.startReceiverRequired).toEqual(true);
expect(device.transmitters).toEqual({});
expect(device.readyCallback).toBe(null);
done();
});
});
describe("data event handler", function() {
it("should emit a receive event when it receives a message", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("receive", function() {
done();
});
device.open();
device.parser.emit("data", [0x01]);
});
it("should emit a status event when it receives message type 0x01", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("status", function() {
done();
});
device.open();
device.parser.emit("data", [0x0D, 0x01, 0x00, 0x01, 0x02, 0x53, 0x30, 0x00, 0x02, 0x21, 0x01, 0x00, 0x00, 0x00]);
});
it("should emit a response event when it receives message type 0x02", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("response", function () {
done();
});
device.open();
device.parser.emit("data", [0x04, 0x02, 0x01, 0x00, 0x00]);
});
it("should emit a lighting1 event when it receives message type 0x10", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("lighting1", function (evt, packetType) {
expect(packetType).toBe(0x10);
expect(this.packetNames[packetType]).toEqual("lighting1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["X10 lighting"]);
done();
});
device.open();
device.parser.emit("data", [0x07, 0x10, 0x00, 0x00, 0x41, 0x03, 0x00, 0x0F]);
});
it("should emit a lighting2 event when it receives message type 0x11", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("lighting2", function (evt, packetType) {
expect(packetType).toBe(0x11);
expect(this.packetNames[packetType]).toEqual("lighting2");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["HomeEasy EU"]);
done();
});
device.open();
device.parser.emit("data", [0x0B, 0x11, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x0F]);
});
it("should emit a lighting4 event when it receives message type 0x13", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("lighting4", function (evt, packetType) {
expect(packetType).toBe(0x13);
expect(this.packetNames[packetType]).toEqual("lighting4");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["PT2262"]);
done();
});
device.open();
device.parser.emit("data", [0x09, 0x13, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x12, 0x00]);
});
it("should emit a lighting5 event when it receives message type 0x14", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("lighting5", function (evt, packetType) {
expect(packetType).toBe(0x14);
expect(this.packetNames[packetType]).toEqual("lighting5");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["LightwaveRF", "Siemens"]);
done();
});
device.open();
device.parser.emit("data", [0x0A, 0x14, 0x00, 0x01, 0xF0, 0x9A, 0xC7, 0x02, 0x00, 0x00, 0x80]);
});
it("should emit a lighting6 event when it receives message type 0x15", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("lighting6", function (evt, packetType) {
expect(packetType).toBe(0x15);
expect(this.packetNames[packetType]).toEqual("lighting6");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Blyss"]);
done();
});
device.open();
device.parser.emit("data", [0x0b, 0x15, 0x00, 0x00, 0xF0, 0x9A, 0x42, 0x00, 0x03, 0x00, 0x00, 0x00]);
});
it("should emit a chime1 event when it receives message type 0x16 (old style)", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("chime1", function (evt, packetType) {
expect(packetType).toBe(0x16);
expect(this.packetNames[packetType]).toEqual("chime1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Byron SX"]);
expect(evt.id).toBe("0xFF")
expect(evt.commandNumber).toBe(13)
expect(evt.command).toBe("Tubular 3 Notes")
expect(evt.rssi).toBe(3)
done();
});
device.open();
device.parser.emit("data", [0x07, 0x16, 0x00, 0x00, 0x00, 0xff, 0x0d, 0x30]);
});
it("should emit a chime1 event when it receives message type 0x16 (new style)", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("chime1", function (evt, packetType) {
expect(packetType).toBe(0x16);
expect(this.packetNames[packetType]).toEqual("chime1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Byron DBY"]);
expect(evt.id).toBe("0x00FF0D01")
expect(evt.rssi).toBe(6)
done();
});
device.open();
device.parser.emit("data", [0x08, 0x16, 0x07, 0x00, 0x00, 0xff, 0x0d, 0x01, 0x60]);
});
it("should emit a blinds1 event when it receives message type 0x19", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("blinds1", function (evt, packetType) {
expect(packetType).toBe(0x19);
expect(this.packetNames[packetType]).toEqual("blinds1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Raex YR1326"]);
done();
});
device.open();
device.parser.emit("data", [0x09, 0x19, 0x04, 0x06, 0x00, 0xA2, 0x1B, 0x01, 0x02, 0x80]);
});
it("should emit a funkbus event when it receives message type 0x1e", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("funkbus", function (evt, packetType) {
expect(packetType).toBe(0x1e);
expect(this.packetNames[packetType]).toEqual("funkbus");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Gira"]);
done();
});
device.open();
device.parser.emit("data", [0x0B, 0x1e, 0x00, 0x00, 0x12, 0x34, 0x42, 0x01, 0x01, 0x00, 0x00, 0x80]);
});
it("should emit a security1 event when it receives message type 0x20", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("security1", function (evt, packetType) {
expect(packetType).toBe(0x20);
expect(this.packetNames[packetType]).toEqual("security1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["X10 security motion sensor"]);
done();
});
device.open();
device.parser.emit("data", [0x08, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
});
it("should emit a camera1 event when it receives message type 0x28", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("camera1", function (evt, packetType) {
expect(packetType).toBe(0x28);
expect(this.packetNames[packetType]).toEqual("camera1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["X10 Ninja Camera"]);
done();
});
device.open();
device.parser.emit("data", [0x06, 0x28, 0x00, 0x00, 0x42, 0x03, 0x90]);
});
it("should emit a remote event when it receives message type 0x30", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("remote", function (evt, packetType) {
expect(packetType).toBe(0x30);
expect(this.packetNames[packetType]).toEqual("remote");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["ATI Remote Wonder"]);
done();
});
device.open();
device.parser.emit("data", [0x06, 0x30, 0x00, 0x04, 0x0F, 0x0D, 0x82]);
});
it("should emit a blinds2 event when it receives message type 0x31", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("blinds2", function (evt, packetType) {
expect(packetType).toBe(0x31);
expect(this.packetNames[packetType]).toEqual("blinds2");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Brel", "Dooya DDxxxx"]);
done();
});
device.open();
device.parser.emit("data", [0x0c, 0x31, 0x00, 0x05, 0x12, 0x34, 0x56, 0x78, 0x04, 0x00, 50, 90, 0x83]);
});
it("should emit a thermostat1 event when it receives message type 0x40", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("thermostat1", function (evt, packetType) {
expect(packetType).toBe(0x40);
expect(this.packetNames[packetType]).toEqual("thermostat1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Digimax", "TLX7506"]);
done();
});
device.open();
device.parser.emit("data", [0x09, 0x40, 0x00, 0x1B, 0x6B, 0x18, 0x16, 0x15, 0x02, 0x70]);
});
it("should emit a thermostat3 event when it receives message type 0x42", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("thermostat3", function (evt, packetType) {
expect(packetType).toBe(0x42);
expect(this.packetNames[packetType]).toEqual("thermostat3");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Mertik G6R-H4TB", "Mertik G6R-H4T", "Mertik G6R-H4T21-Z22"]);
done();
});
device.open();
device.parser.emit("data", [0x08, 0x42, 0x01, 0x01, 0x01, 0x9F, 0xAB, 0x02, 0x81]);
});
it("should emit a bbq1 event when it receives message type 0x4e", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("bbq1", function (evt, packetType) {
expect(packetType).toBe(0x4e);
expect(this.packetNames[packetType]).toEqual("bbq1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Maverick ET-732"]);
done();
});
device.open();
device.parser.emit("data", [0x0A, 0x4E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x19, 0x00, 0x17, 0x89]);
});
it("should emit a temperaturerain1 event when it receives message type 0x4f, with device type 1", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("temperaturerain1", function (evt, packetType) {
expect(packetType).toBe(0x4f);
expect(this.packetNames[packetType]).toEqual("temperaturerain1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Alecto WS1200"]);
done();
});
device.open();
device.parser.emit("data", [0x0a, 0x4f, 0x01, 0x00, 0x12, 0x34, 0x01, 0x17, 0x00, 0x42, 0x55]);
});
it("should emit a temperature1 event when it receives message type 0x50, with device type 1", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("temperature1", function (evt, packetType) {
expect(packetType).toBe(0x50);
expect(this.packetNames[packetType]).toEqual("temperature1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["THR128", "THR138", "THC138"]);
done();
});
device.open();
device.parser.emit("data", [0x08, 0x50, 0x01, 0x01, 0xFA, 0xAF, 0x80, 0x14, 0x42]);
});
it("should emit a temperature1 event when it receives message type 0x50, with device type 2", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("temperature1", function (evt, packetType) {
expect(packetType).toBe(0x50);
expect(this.packetNames[packetType]).toEqual("temperature1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["THC238", "THC268", "THN132", "THWR288",
"THRN122", "THN122", "AW129", "AW131", "THN129"]);
done();
});
device.open();
device.parser.emit("data", [0x08, 0x50, 0x02, 0x01, 0xFA, 0xAF, 0x80, 0x14, 0x42]);
});
it("should emit a humidity1 event when it receives message type 0x51", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("humidity1", function (evt, packetType) {
expect(packetType).toBe(0x51);
expect(this.packetNames[packetType]).toEqual("humidity1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["La Crosse TX3"]);
done();
});
device.open();
device.parser.emit("data", [0x08, 0x51, 0x01, 0x02, 0x77, 0x00, 0x36, 0x01, 0x89]);
});
it("should emit a temperaturehumidity1 event when it receives message type 0x52, with device type 1", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("temperaturehumidity1", function (evt, packetType) {
expect(packetType).toBe(0x52);
expect(this.packetNames[packetType]).toEqual("temperaturehumidity1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["THGN122", "THGN123", "THGN132", "THGR122", "THGR228", "THGR238", "THGR268"]);
done();
});
device.open();
device.parser.emit("data", [0x0A, 0x52, 0x01, 0x04, 0xAF, 0x01, 0x00, 0x90, 0x36, 0x02, 0x59]);
});
it("should emit a temphumbaro1 event when it receives message type 0x54", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("temphumbaro1", function (evt, packetType) {
expect(packetType).toBe(0x54);
expect(this.packetNames[packetType]).toEqual("temphumbaro1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["BTHR918N", "BTHR968"]);
done();
});
device.open();
device.parser.emit("data", [0x0D, 0x54, 0x02, 0x0E, 0xE9, 0x00, 0x00, 0xC9, 0x27, 0x02, 0x03, 0xE7, 0x04, 0x39]);
});
it("should emit a rain1 event when it receives message type 0x55, with device type 2", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("rain1", function (evt, packetType) {
expect(packetType).toBe(0x55);
expect(this.packetNames[packetType]).toEqual("rain1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["PCR800"]);
done();
});
device.open();
device.parser.emit("data", [0x0B, 0x55, 0x02, 0x17, 0xB6, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x3C, 0x69]);
});
it("should emit a wind1 event when it receives message type 0x56, with device type 1", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("wind1", function (evt, packetType) {
expect(packetType).toBe(0x56);
expect(this.packetNames[packetType]).toEqual("wind1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["WTGR800"]);
done();
});
device.open();
device.parser.emit("data", [0x10, 0x56, 0x01, 0x12, 0x2F, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, 0x14, 0x00, 0x49, 0x00, 0x00, 0x79]);
});
it("should emit a uv1 event when it receives message type 0x57, with device type 1", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("uv1", function (evt, packetType) {
expect(packetType).toBe(0x57);
expect(this.packetNames[packetType]).toEqual("uv1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["UVN128", "UV138", "Davis"]);
done();
});
device.open();
device.parser.emit("data", [0x09, 0x57, 0x01, 0x00, 0x12, 0x34, 0x38, 0x01, 0x11, 0x79]);
});
it("should emit a datetime event when it receives message type 0x58, with device type 1", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("datetime", function (evt, packetType) {
expect(packetType).toBe(0x58);
expect(this.packetNames[packetType]).toEqual("datetime");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["RTGR328N", "RTGR383"]);
done();
});
device.open();
device.parser.emit("data", [0x0D, 0x58, 0x01, 0x00, 0x12, 0x34, 0x11, 0x08, 0x11, 0x05, 0x14, 0x1B, 0x11, 0x79]);
});
it("should emit an elec1 event when it receives message type 0x59", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("elec1", function (evt, packetType) {
expect(this.packetNames[packetType]).toEqual("elec1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["CM113", "Electrisave", "Cent-a-meter"]);
expect(packetType).toBe(0x59);
done();
});
device.open();
device.parser.emit("data", [0x0D, 0x59, 0x01, 0x0F, 0x86, 0x00, 0x04, 0x00, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x49]);
});
it("should emit an elec23 event when it receives message type 0x5a, with device type 1", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("elec23", function (evt, packetType) {
expect(packetType).toBe(0x5a);
expect(this.packetNames[packetType]).toEqual("elec23");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["CM119", "M160"]);
done();
});
device.open();
device.parser.emit("data", [0x11, 0x5a, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
});
it("should emit an elec4 event when it receives message type 0x5b", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("elec4", function (evt, packetType) {
expect(packetType).toBe(0x5b);
expect(this.packetNames[packetType]).toEqual("elec4");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["CM180i"]);
done();
});
device.open();
device.parser.emit("data", [0x13, 0x5B, 0x01, 0x06, 0xB8, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x6F, 0x14, 0x88, 0x89]);
});
it("should emit an elec5 event when it receives message type 0x5c", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("elec5", function (evt, packetType) {
expect(packetType).toBe(0x5c);
expect(this.packetNames[packetType]).toEqual("elec5");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["Revolt"]);
done();
});
device.open();
device.parser.emit("data", [0x0F, 0x5C, 0x01, 0x03, 0x00, 0x2D, 0xE4, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x32, 0x80]);
});
it("should emit a weight1 event when it receives message type 0x5D", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("weight1", function (evt, packetType) {
expect(packetType).toBe(0x5d);
expect(this.packetNames[packetType]).toEqual("weight1");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["BWR102", "BWR102"]);
done();
});
device.open();
device.parser.emit("data", [0x08, 0x5D, 0x01, 0xF5, 0x00, 0x07, 0x03, 0x40, 0x40]);
});
it("should emit a cartelectronic event when it receives message type 0x60", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("cartelectronic", function (evt, packetType) {
expect(packetType).toBe(0x60);
expect(this.packetNames[packetType]).toEqual("cartelectronic");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["TIC"]);
done();
});
device.open();
device.parser.emit("data", [0x15, 0x60, 0x01, 0x00, 0x12, 0x34, 0x56, 0x78, 0x9a, 0x01, 0x12,
0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x07, 0x5a, 0x012, 0x79]);
});
it("should emit an rfxsensor event when it receives message type 0x70", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("rfxsensor", function (evt, packetType) {
expect(packetType).toBe(0x70);
expect(this.packetNames[packetType]).toEqual("rfxsensor");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["RFXSensor temperature"]);
done();
});
device.open();
device.parser.emit("data", [0x07, 0x70, 0x00, 0xE9, 0x28, 0x02, 0xE1, 0x70]);
});
it("should emit an rfxmeter event when it receives message type 0x71", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("rfxmeter", function (evt, packetType) {
expect(packetType).toBe(0x71);
expect(this.packetNames[packetType]).toEqual("rfxmeter");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["RFXMeter data"]);
done();
});
device.open();
device.parser.emit("data", [0x0A, 0x71, 0x00, 0x37, 0x08, 0xF8, 0x00, 0x8A, 0x64, 0x67, 0x70]);
});
it("should emit a waterlevel event when it receives message type 0x73", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.on("waterlevel", function (evt, packetType) {
expect(packetType).toBe(0x73);
expect(this.packetNames[packetType]).toEqual("waterlevel");
expect(this.deviceNames[packetType][evt.subtype]).toEqual(["TS FT002"]);
done();
});
device.open();
device.parser.emit("data", [0x0D, 0x73, 0x00, 0x2A, 0x12, 0x34, 0x00, 0x01, 0xF4, 0x01, 0x5f, 0x00, 0x00, 0x73]);
});
});
describe(".initialise function", function () {
it("should emit a 'connectfailed' event if the serial port device file does not exist", function (done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/tty-i-dont-exist", {
port: fakeSerialPort
});
device.on("connectfailed", function () {
done();
});
device.open();
fakeSerialPort.emit("error", new Error("Error: No such file or directory, cannot open /dev/tty-i-dont-exist"));
});
describe("message sequence", function () {
let device = {};
beforeEach(function () {
const fakeSerialPort = new FakeSerialPort();
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
jasmine.clock().install(); // There is a 500ms Timeout in the initialisation code, we must mock it
});
afterEach(function () {
jasmine.clock().uninstall()
})
it("should prepare the device for use.", function (done) {
const
resetSpy = spyOn(device, "resetRFX").and.callThrough(),
flushSpy = spyOn(device, "flush").and.callThrough(),
getStatusSpy = spyOn(device, "getRFXStatus").and.callFake(function () {
device.statusMessageHandler([0x00, 0x01, 0x02, 0x53, 0x5E, 0x08, 0x02, 0x25, 0x00, 0x01, 0x01, 0x1C])
}),
openSpy = spyOn(device, "open").and.callFake(function () {
device.connected = true;
device.emit("ready");
});
device.initialise(() => { done() });
jasmine.clock().tick(501);
expect(resetSpy).toHaveBeenCalled();
// noinspection JSCheckFunctionSignatures
expect(flushSpy).toHaveBeenCalledWith(jasmine.any(Function));
// noinspection JSCheckFunctionSignatures
expect(getStatusSpy).toHaveBeenCalledWith(jasmine.any(Function));
expect(openSpy).toHaveBeenCalled();
});
it("should prepare the device for use (current firmware).", function (done) {
const
resetSpy = spyOn(device, "resetRFX").and.callThrough(),
flushSpy = spyOn(device, "flush").and.callThrough(),
startRxSpy = spyOn(device, "startRFXReceiver").and.callFake(function () {
device.statusMessageHandler([0x07, 0x02, 0x07, 0x43, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68,
0x74, 0x20, 0x52, 0x46, 0x58, 0x43, 0x4F, 0x4D])
}),
getStatusSpy = spyOn(device, "getRFXStatus").and.callFake(function () {
device.statusMessageHandler([0x00, 0x01, 0x02, 0x53, 0x5E, 0x08, 0x02, 0x25, 0x00, 0x01, 0x01,
0x1C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
}),
openSpy = spyOn(device, "open").and.callFake(function () {
device.connected = true;
device.emit("ready");
});
device.initialise(() => { done() });
jasmine.clock().tick(501);
expect(resetSpy).toHaveBeenCalled();
// noinspection JSCheckFunctionSignatures
expect(flushSpy).toHaveBeenCalledWith(jasmine.any(Function));
// noinspection JSCheckFunctionSignatures
expect(getStatusSpy).toHaveBeenCalledWith(jasmine.any(Function));
// noinspection JSCheckFunctionSignatures
expect(startRxSpy).toHaveBeenCalledWith(jasmine.any(Function));
expect(openSpy).toHaveBeenCalled();
});
});
});
it(".open should pipe data from the fake serialport to the parser", function() {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/", {
port: fakeSerialPort
});
device.open();
expect(fakeSerialPort.pipeDestination).toBe(device.parser);
});
describe(".bytesToUint48", function() {
it("should convert a sequence of 6 bytes to a longint", function() {
expect(rfxcom.RfxCom.bytesToUint48([0xF1, 0x27, 0xba, 0x67, 0x28, 0x97])).toBe(265152933341335);
});
});
describe(".bytesToUint32", function() {
it("should convert a sequence of 4 bytes to a longint", function() {
expect(rfxcom.RfxCom.bytesToUint32([0xFF, 0x76, 0x21, 0x72])).toBe(4285931890);
});
});
describe(".dumpHex", function() {
it("should convert a sequence of bytes to a string of hex numbers with a prefix if one is supplied", function() {
expect(rfxcom.RfxCom.dumpHex([0x00, 0x00, 0x01, 0x72], "0x").toString()).toBe("0x00,0x00,0x01,0x72");
});
it("should convert a sequence of bytes to a string of hex numbers with no prefix if none supplied", function() {
expect(rfxcom.RfxCom.dumpHex([0x00, 0x00, 0x01, 0x72]).toString()).toBe("00,00,01,72");
});
});
describe(".stringToBytes", function() {
it("should convert a sequence of characters to an array of bytes", function() {
expect(rfxcom.RfxCom.stringToBytes("203052").bytes.toString()).toBe([32, 48, 82].toString());
});
it("should convert a sequence of characters to hex value", function () {
expect(rfxcom.RfxCom.stringToBytes("203052").value).toBe(0x203052);
});
it("should ignore leading 0x on a string", function() {
expect(rfxcom.RfxCom.stringToBytes("0x203052").bytes.toString()).toBe([32, 48, 82].toString());
});
});
describe(".flush", function() {
it("should flush the underlying serialport", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.flush(function() {
expect(fakeSerialPort.flushed).toBeTruthy();
done();
});
});
});
describe(".resetRFX", function() {
it("should send the correct bytes to the serialport", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.resetRFX(function() {
done();
});
expect(fakeSerialPort).toHaveSent([13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
});
});
describe(".getRFXStatus", function() {
it("should send the correct bytes to the serialport", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.getRFXStatus(function() {
done();
});
expect(fakeSerialPort).toHaveSent([13, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
});
});
describe(".configureRFX", function() {
it("should send the correct bytes to the serialport", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.connected = true;
device.receiverTypeCode = 0x53;
device.configureRFX(433.92, +10, [protocols[0x53].LACROSSE, protocols[0x53].OREGON, protocols[0x53].AC, protocols[0x53].ARC, protocols[0x53].X10], function() {
done();
});
expect(fakeSerialPort).toHaveSent([0x0D, 0x00, 0x00, 0x00, 0x03, 0x53, 0x1c, 0x00, 0x08, 0x27, 0x00, 0x00, 0x00, 0x00]);
expect(device.receiverTypeCode).toBe(0x53);
expect(device.transmitterPower).toBe(10.0);
device.acknowledge.forEach(acknowledge => {if (typeof acknowledge === "function") {acknowledge()}});
});
it("should set 433.42MHz Rx frequency", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.connected = true;
device.receiverTypeCode = 0x53;
device.configureRFX(433.42, 0, [protocols[0x53].LACROSSE, protocols[0x53].OREGON, protocols[0x53].AC, protocols[0x53].ARC, protocols[0x53].X10], function() {
done();
});
expect(fakeSerialPort).toHaveSent([0x0D, 0x00, 0x00, 0x00, 0x03, 0x54, 0x1c, 0x00, 0x08, 0x27, 0x00, 0x00, 0x00, 0x00]);
expect(device.receiverTypeCode).toBe(0x54);
expect(device.transmitterPower).toBe(10.0);
device.acknowledge.forEach(acknowledge => {if (typeof acknowledge === "function") {acknowledge()}});
});
it("should set 434.50MHz Rx frequency", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.connected = true;
device.receiverTypeCode = 0x53;
device.configureRFX("434.50", 0, [protocols[0x53].LACROSSE, protocols[0x53].OREGON, protocols[0x53].AC, protocols[0x53].ARC, protocols[0x53].X10], function() {
done();
});
expect(fakeSerialPort).toHaveSent([0x0D, 0x00, 0x00, 0x00, 0x03, 0x5F, 0x1c, 0x00, 0x08, 0x27, 0x00, 0x00, 0x00, 0x00]);
expect(device.receiverTypeCode).toBe(0x5F);
expect(device.transmitterPower).toBe(10.0);
device.acknowledge.forEach(acknowledge => {if (typeof acknowledge === "function") {acknowledge()}});
});
it("should set the transmitter power for an RFXtrxIOT", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.connected = true;
device.receiverTypeCode = 0x5C;
device.configureRFX(433, -5, [protocols[0x5C].LIGHTWAVERF, protocols[0x5C].VISONIC, protocols[0x5C].KEELOQ, protocols[0x5C].MEIANTECH], function() {
done();
});
expect(fakeSerialPort).toHaveSent([0x0D, 0x00, 0x00, 0x00, 0x03, 0x5c, 0x0d, 0x00, 0x02, 0xC0, 0x01, 0x00, 0x00, 0x00]);
expect(device.receiverTypeCode).toBe(0x5C);
expect(device.transmitterPower).toBe(-5.0);
device.acknowledge.forEach(acknowledge => {if (typeof acknowledge === "function") {acknowledge()}});
});
it("should set the frequency & transmitter power for an RFXtrxIOT", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.connected = true;
device.receiverTypeCode = 0x5C;
device.configureRFX(868, 13, [protocols[0x5C].LIGHTWAVERF, protocols[0x5C].VISONIC, protocols[0x5C].KEELOQ, protocols[0x5C].MEIANTECH], function() {
done();
});
expect(fakeSerialPort).toHaveSent([0x0D, 0x00, 0x00, 0x00, 0x03, 0x5d, 0x1f, 0x00, 0x02, 0xC0, 0x01, 0x00, 0x00, 0x00]);
expect(device.receiverTypeCode).toBe(0x5D);
expect(device.transmitterPower).toBe(+13.0);
device.acknowledge.forEach(acknowledge => {if (typeof acknowledge === "function") {acknowledge()}});
});
it("should set the frequency for an RFXtrx315", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.connected = true;
device.receiverTypeCode = 0x50;
device.configureRFX(315, 13, [protocols[0x50].LIGHTING4, protocols[0x50].VISONIC, protocols[0x50].X10], function() {
done();
});
expect(fakeSerialPort).toHaveSent([0x0D, 0x00, 0x00, 0x00, 0x03, 0x51, 0x1c, 0x08, 0x00, 0x81, 0x00, 0x00, 0x00, 0x00]);
expect(device.receiverTypeCode).toBe(0x51);
expect(device.transmitterPower).toBe(+10.0);
device.acknowledge.forEach(acknowledge => {if (typeof acknowledge === "function") {acknowledge()}});
});
it("should set the frequency for an RFXtrx315", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.connected = true;
device.receiverTypeCode = 0x51;
device.configureRFX(310, 13, [protocols[0x51].LIGHTING4, protocols[0x51].VISONIC, protocols[0x51].X10], function() {
done();
});
expect(fakeSerialPort).toHaveSent([0x0D, 0x00, 0x00, 0x00, 0x03, 0x50, 0x1c, 0x08, 0x00, 0x81, 0x00, 0x00, 0x00, 0x00]);
expect(device.receiverTypeCode).toBe(0x50);
expect(device.transmitterPower).toBe(+10.0);
device.acknowledge.forEach(acknowledge => {if (typeof acknowledge === "function") {acknowledge()}});
});
});
describe(".enableRFXProtocols", function() {
it("should send the correct bytes to the serialport", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.connected = true;
device.receiverTypeCode = 0x53;
device.enableRFXProtocols([protocols[0x53].LACROSSE, protocols[0x53].OREGON, protocols[0x53].AC, protocols[0x53].ARC, protocols[0x53].X10], function() {
done();
});
expect(fakeSerialPort).toHaveSent([0x0D, 0x00, 0x00, 0x00, 0x03, 0x53, 0x1c, 0x00, 0x08, 0x27, 0x00, 0x00, 0x00, 0x00]);
device.acknowledge.forEach(acknowledge => {if (typeof acknowledge === "function") {acknowledge()}});
});
it("should send the correct bytes to the serialport for a single protocol", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.connected = true;
device.receiverTypeCode = 0x53;
device.enableRFXProtocols(protocols[0x53].LIGHTWAVERF, function() {
done();
});
expect(fakeSerialPort).toHaveSent([0x0D, 0x00, 0x00, 0x00, 0x03, 0x53, 0x1c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]);
device.acknowledge.forEach(acknowledge => {if (typeof acknowledge === "function") {acknowledge()}});
});
});
describe(".saveRFXProtocols", function() {
it("should send the correct bytes to the serialport", function(done) {
const fakeSerialPort = new FakeSerialPort(),
device = new rfxcom.RfxCom("/dev/ttyUSB0", {
port: fakeSerialPort
});
device.saveRFXProtocols(function() {
done();
});
expect(fakeSerialPort).toHaveSent([0x0D, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00]);
device.acknowledge.forEach(acknowledge => {if (typeof acknowledge === "function") {acknowledge()}});
});
});
describe(".statusMessageHandler", function() {
let device = {};
let packetType = 0x01;
beforeEach(function() {
device = new rfxcom.RfxCom("/dev/ttyUSB0");
});
it("should emit a status message when called", function(done) {
device.on("status", function(evt) {
expect(evt.subtype).toBe(0);
expect(evt.seqnbr).toBe(0x01);
expect(evt.cmnd).toBe(0x2);
expect(evt.receiverType).toBe("433.92MHz transceiver");
expect(evt.firmwareVersion).toBe(0x30);
expect(evt.firmwareType).toBe("Type 1");
expect(evt.enabledProtocols).toEqual(["RSL", "BYRONSX"]);
done();
});
device.statusMessageHandler([0, 1, 0x2, 0x53, 0x30, 0x30, 0, 0, 0, 0, 0, 0], packetType);
});
it("should emit a status message when called", function(done) {
device.on("status", function(evt) {
expect(evt.subtype).toBe(0);
expect(evt.seqnbr).toBe(0x01);
expect(evt.cmnd).toBe(0x2);
expect(evt.receiverType).toBe("433.92MHz transceiver");
expect(evt.receiverTypeCode).toBe(0x53);
expect(evt.firmwareVersion).toBe(161);
expect(evt.firmwareType).toBe("Type 1");
expect(evt.enabledProtocols).toEqual(["RSL", "BYRONSX"]);
done();
});
device.statusMessageHandler([0, 1, 0x2, 0x53, 161, 0x30, 0, 0, 0, 0, 0, 0], packetType);
});
it("should emit a status message when called", function(done) {
device.on("status", function(evt) {
expect(evt.subtype).toBe(0);
expect(evt.seqnbr).toBe(0x01);
expect(evt.cmnd).toBe(0x2);
expect(evt.receiverType).toBe("433.92MHz transceiver");
expect(evt.receiverTypeCode).toBe(0x53);
expect(evt.firmwareVersion).toBe(162);
expect(evt.firmwareType).toBe("Type 2");
expect(evt.enabledProtocols).toEqual(["RSL", "BYRONSX"]);
done();
});
device.statusMessageHandler([0, 1, 0x2, 0x53, 162, 0x30, 0, 0, 0, 0, 0, 0], packetType);
});
it("should emit a status message when called", function(done) {
device.on("status", function(evt) {
expect(evt.subtype).toBe(0);
expect(evt.seqnbr).toBe(0x01);
expect(evt.cmnd).toBe(0x2);
expect(evt.receiverType).toBe("433.92MHz transceiver");
expect(evt.receiverTypeCode).toBe(0x53);
expect(evt.firmwareVersion).toBe(224);
expect(evt.firmwareType).toBe("Type 2");
expect(evt.enabledProtocols).toEqual(["RSL", "BYRONSX"]);
done();
});
device.statusMessageHandler([0, 1, 0x2, 0x53, 224, 0x30, 0, 0, 0, 0, 0, 0], packetType);
});
it("should emit a status message when called", function(done) {
device.on("status", function(evt) {
expect(evt.subtype).toBe(0);
expect(evt.seqnbr).toBe(0x01);
expect(evt.cmnd).toBe(0x2);
expect(evt.receiverType).toBe("433.92MHz transceiver");
expect(evt.receiverTypeCode).toBe(0x53);
expect(evt.firmwareVersion).toBe(225);
expect(evt.firmwareType).toBe("Ext");
expect(evt.enabledProtocols).toEqual(["RSL", "BYRONSX"]);
done();
});
device.statusMessageHandler([0, 1, 0x2, 0x53, 225, 0x30, 0, 0, 0, 0, 0, 0], packetType);
});
it("should emit a status message when called with a long status packet", function(done) {
device.on("status", function(evt) {
expect(evt.subtype).toBe(0);
expect(evt.seqnbr).toBe(0x01);
expect(evt.cmnd).toBe(0x2);
expect(evt.receiverType).toBe("433.92MHz transceiver");
expect(evt.receiverTypeCode).toBe(0x53);
expect(evt.firmwareVersion).toBe(1001);
expect(evt.firmwareType).toBe("Type 1");
expect(evt.enabledProtocols).toEqual(["RSL", "BYRONSX"]);
done();
});
device.statusMessageHandler([0, 1, 0x2, 0x53, 1, 0x30, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], packetType);
});
it("should emit a status message when called with a long status packet", function(done) {
device.on("status", function(evt) {
expect(evt.subtype).toBe(0);
expect(evt.seqnbr).toBe(0x01);
expect(evt.cmnd).toBe(0x2);
expect(evt.receiverType).toBe("433.92MHz transceiver");
expect(evt.receiverTypeCode).toBe(0x53);
expect(evt.firmwareVersion).toBe(1001);
expect(evt.firmwareType).toBe("Type 2");
expect(evt.enabledProtocols).toEqual(["RSL", "BYRONSX"]);
done();
});
device.statusMessageHandler([0, 1, 0x2, 0x53, 1, 0x30, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], packetType);
});
it("should emit a status message when called with a long status packet", function(done) {
device.on("status", function(evt) {
expect(evt.subtype).toBe(0);
expect(evt.seqnbr).toBe(0x01);
expect(evt.cmnd).toBe(0x2);
expect(evt.receiverType).toBe("433.92MHz transceiver");
expect(evt.receiverTypeCode).toBe(0x53);
expect(evt.firmwareVersion).toBe(1001);
expect(evt.firmwareType).toBe("Ext");
expect(evt.enabledProtocols).toEqual(["RSL", "BYRONSX"]);
done();
});
device.statusMessageHandler([0, 1, 0x2, 0x53, 1, 0x30, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0], packetType);
});
it("should emit a status message when called with a long status packet", function(done) {
device.on("status", function(evt) {
expect(evt.subtype).toBe(0);
expect(evt.seqnbr).toBe(0x01);
expect(evt.cmnd).toBe(0x2);
expect(evt.receiverType).toBe("433.92MHz transceiver");
expect(evt.receiverTypeCode).toBe(0x53);
expect(evt.firmwareVersion).toBe(1001);
expect(evt.firmwareType).toBe("Ext 2");
expect(evt.enabledProtocols).toEqual(["RSL", "BYRONSX"]);
done();
});
device.statusMessageHandler([0, 1, 0x2, 0x53, 1, 0x30, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0], packetType);
});
it("should emit a status message when called with a long status packet", function(done) {
device.on("status", function(evt) {
expect(evt.subtype).toBe(0);
expect(evt.seqnbr).toBe(0x01);