-
Notifications
You must be signed in to change notification settings - Fork 20
/
zwave-classifier.js
2176 lines (2012 loc) · 66.3 KB
/
zwave-classifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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
/**
*
* ZWaveClassifier - Determines properties from command classes.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.*
*/
'use strict';
const ZWaveProperty = require('./zwave-property');
const {
CENTRAL_SCENE,
COLOR_CAPABILITY,
COLOR_INDEX,
COMMAND_CLASS,
GENERIC_TYPE,
GENERIC_TYPE_STR,
} = require('./zwave-constants');
const {
DEBUG_classifier,
} = require('./zwave-debug');
const DEBUG = DEBUG_classifier;
// See; http://wiki.micasaverde.com/index.php/ZWave_Command_Classes for a
// complete list of command classes.
const AEOTEC_MANUFACTURER_ID = '0x0086';
const AEOTEC_ZW096_PRODUCT_ID = '0x0060'; // SmartPlug (Switch)
const AEOTEC_ZW099_PRODUCT_ID = '0x0063'; // SmartPlug (Dimmer)
const AEOTEC_ZW100_PRODUCT_ID = '0x0064'; // Multisensor 6
const AEOTEC_ZW111_PRODUCT_ID = '0x006f'; // Nano Dimmer with metering
const AEOTEC_ZW116_PRODUCT_ID = '0x0074'; // Nano Switch
const AEOTEC_ZW130_PRODUCT_ID = '0x0082'; // WallMote Quad
const AEOTEC_ZW132_PRODUCT_ID = '0x0084'; // Dual Nano Switch with metering
const AEOTEC_ZW139_PRODUCT_ID = '0x008b'; // Nano Switch (End of Life)
const AEOTEC_ZW140_PRODUCT_ID = '0x008c'; // Dual Nano Switch
const AEOTEC_ZW141_PRODUCT_ID = '0x008d'; // Nano Shutter
const ECOLINK_MANUFACTURER_ID = '0x014a';
const ECOLINK_FLOOD_FREEZE_PRODUCT_ID = '0x0010';
const FIRST_ALERT_MANUFACTURER_ID = '0x0138';
const FIRST_ALERT_ZCOMBO_PRODUCT_ID = '0x0002';
function nodeHasAeotecS1S2Mode(node) {
// These devices have an S1 and S2 input which can control the output(s).
// They also have config options which determine which type of external
// switch is connected to S1 and S2, and we expose these config options
// as properties.
return node.zwInfo.manufacturerId === AEOTEC_MANUFACTURER_ID &&
(node.zwInfo.productId === AEOTEC_ZW111_PRODUCT_ID ||
node.zwInfo.productId === AEOTEC_ZW116_PRODUCT_ID ||
node.zwInfo.productId === AEOTEC_ZW132_PRODUCT_ID ||
node.zwInfo.productId === AEOTEC_ZW139_PRODUCT_ID ||
node.zwInfo.productId === AEOTEC_ZW140_PRODUCT_ID ||
node.zwInfo.productId === AEOTEC_ZW141_PRODUCT_ID);
}
// From cpp/src/command_classes/SwitchMultilevel.cpp
// The code uses "_data[5]+3" for the index.
//
// Refer to ZWave document SDS13781 "Z-Wave Application Command Class
// Specification". In the Notification Type and Event fields. The
// notification type of "Home Security" has a Notification Type of 7,
// which means it will be reported as an index of 10 (due to the +3
// mentioned above).
const ALARM_INDEX_HOME_SECURITY = 10;
const ALARM_INDEX_TYPE_V1 = 512;
const ALARM_INDEX_LEVEL_V1 = 513;
// The following come from:
// SDS13713 Notification Command Class, list of assigned Notifications.xlsx
// and also from
const NOTIFICATION_SMOKE_DETECTOR = 1;
const NOTIFICATION_CO_DETECTOR = 2;
const NOTIFICATION_OVERHEAT = 4;
const NOTIFICATION_WATER_LEAK = 5;
const NOTIFICATION_ACCESS_CONTROL = 6;
const NOTIFICATION_HOME_SECURITY = 7;
const NOTIFICATION_COMBUSTIBLE_GAS = 18;
const NOTIFICATION_SENSOR = {
[NOTIFICATION_SMOKE_DETECTOR]: {// 1
name: 'smoke',
'@type': ['SmokeSensor'],
propertyName: 'on',
propertyDescr: {
'@type': 'SmokeProperty',
type: 'boolean',
label: 'Smoke',
description: 'Smoke Sensor',
readOnly: true,
},
valueListMap: [false, true],
},
[NOTIFICATION_CO_DETECTOR]: {// 2
name: 'co',
'@type': ['Alarm'],
propertyName: 'co',
propertyDescr: {
'@type': 'AlarmProperty',
type: 'boolean',
label: 'CO',
description: 'Carbon Monoxide Detector',
readOnly: true,
},
valueListMap: [false, true],
},
[NOTIFICATION_OVERHEAT]: {// 4
name: 'overheat',
propertyName: 'overheat',
propertyDescr: {
'@type': 'AlarmProperty',
type: 'boolean',
label: 'Overheat',
description: 'Overheat property',
readOnly: true,
},
valueListMap: [false, true],
},
[NOTIFICATION_WATER_LEAK]: {// 5
name: 'water',
'@type': ['LeakSensor'],
propertyName: 'on',
propertyDescr: {
'@type': 'LeakProperty',
type: 'boolean',
label: 'Water',
description: 'Water Sensor',
readOnly: true,
},
valueListMap: [false, true],
addValueId2: true,
},
[NOTIFICATION_ACCESS_CONTROL]: {// 6
name: 'switch',
'@type': ['DoorSensor'],
propertyName: 'open',
propertyDescr: {
'@type': 'OpenProperty',
type: 'boolean',
label: 'Open',
description: 'Contact Switch',
readOnly: true,
},
valueListMap: [false, true, false],
},
[NOTIFICATION_HOME_SECURITY]: {// 7
name: 'motion',
'@type': ['MotionSensor'],
propertyName: 'motion',
propertyDescr: {
'@type': 'MotionProperty',
type: 'boolean',
label: 'Motion',
description: 'MotionDetected',
readOnly: true,
},
valueMap: ['Clear', 'Motion'],
},
[NOTIFICATION_COMBUSTIBLE_GAS]: {// 18
name: 'combustible_gas',
'@type': ['Alarm'],
propertyName: 'combustible_gas',
propertyDescr: {
'@type': 'AlarmProperty',
type: 'boolean',
label: 'Combustible Gas',
description: 'Combustible Gas Detector',
readOnly: true,
},
valueListMap: [false, true],
},
};
// These are additional sensors that aren't the main function of the sensor.
const NOTIFICATION_SENSOR2 = {
[NOTIFICATION_HOME_SECURITY]: {// 7
name: 'tamper',
propertyName: 'tamper',
propertyDescr: {
'@type': 'TamperProperty',
type: 'boolean',
label: 'Tamper',
description: 'Tamper Switch',
readOnly: true,
},
valueMap: ['Clear', 'Tamper'],
},
};
// This would be from Battery.cpp, but it only has a single index.
const BATTERY_INDEX_LEVEL = 0;
const DOOR_LOCK_LOCKED = 0;
// These constants come from the OpenZWave ValueIDIndexesDefines.def
// Search for ValueID_Index_Meter
const METER_INDEX_ELECTRIC_INSTANT_POWER = 2;
const METER_INDEX_ELECTRIC_INSTANT_VOLTAGE = 4;
const METER_INDEX_ELECTRIC_INSTANT_CURRENT = 5;
// This would be from SensorBinary.cpp, but it only has a single index.
const SENSOR_BINARY_INDEX_SENSOR = 0;
// From the SensorType enum in OpenZWave:
// cpp/src/command_classes/SensorMultilevel.cpp#L50
//
// Note: These constants are specific to the OpenZWave library and not
// part of the ZWave specification.
const SENSOR_MULTILEVEL_INDEX_TEMPERATURE = 1;
const SENSOR_MULTILEVEL_INDEX_LUMINANCE = 3;
const SENSOR_MULTILEVEL_INDEX_RELATIVE_HUMIDITY = 5;
const SENSOR_MULTILEVEL_INDEX_ULTRAVIOLET = 27;
const SENSOR_MULTILEVEL_INDEX_CO_LEVEL = 40;
// This would be from SwitchBinary.cpp, but it only has a single index.
const SWITCH_BINARY_INDEX_SWITCH = 0;
// From the SwitchMultilevelIndex enum in OpenZWave:
// cpp/src/command_classes/SwitchMultilevel.cpp
//
// Note: These constants are specific to the OpenZWave library and not
// part of the ZWave specification.
const SWITCH_MULTILEVEL_INDEX_LEVEL = 0;
// From ValueIDIndexesDefines.def
const WAKEUP_INTERVAL_VALUE = 0;
const WAKEUP_INTERVAL_MIN = 1;
const WAKEUP_INTERVAL_MAX = 2;
// From ValueIDIndexesDefines.def (ValueID_Index_ThermostatMode)
const THERMOSTAT_INDEX_MODE = 0;
// From ValueIDIndexesDefines.def (ValueID_Index_ThermostatOperatingState)
const THERMOSTAT_INDEX_OPERATING_STATE = 0;
// From ValueIDIndexesDefines.def (ValueID_Index_ThermostatSetpoint)
const THERMOSTAT_INDEX_SETPOINT_HEATING = 1;
const THERMOSTAT_INDEX_SETPOINT_COOLING = 2;
// From ValueIDIndexesDefines.def (ValueID_Index_ThermostatFanMode)
const THERMOSTAT_INDEX_FAN_MODE = 0;
// From ValueIDIndexesDefines.def (ValueID_Index_ThermostatFanState)
const THERMOSTAT_INDEX_FAN_STATE = 0;
const QUIRKS = [
{
// The Aeotec devices don't seem to notify on current changes, only on
// instantaneous power changes. So we exclude this for now. We might be
// able to support this by adding a read of current each time we get a
// power change.
zwInfo: {
manufacturerId: AEOTEC_MANUFACTURER_ID,
},
excludeProperties: ['current'],
},
{
// The Aeotec ZW096 (Smart Switch 6) says it supports the MULTILEVEL
// command class, but setting it acts like a no-op. We remove the
// 'level' property so that the UI doesn't see it.
zwInfo: {
manufacturerId: AEOTEC_MANUFACTURER_ID,
productId: AEOTEC_ZW096_PRODUCT_ID,
},
excludeProperties: ['level'],
},
{
// Aeotec products which have Enery Metering
zwInfo: {
manufacturerId: AEOTEC_MANUFACTURER_ID,
productIds: [
AEOTEC_ZW096_PRODUCT_ID, // Smart Switch 6
AEOTEC_ZW099_PRODUCT_ID, // Smart Dimmer 6
AEOTEC_ZW111_PRODUCT_ID, // Nano Swith with energy metering
AEOTEC_ZW132_PRODUCT_ID, // Dual Nano Switch with metering
],
},
// polling isn't required with the configuration change below
disablePoll: true,
setConfigs: [
// Enable to send a Basic CC Report when the switch state
// changes.
{paramId: 80, value: 2, size: 1},
// Setting parameter 90 to 1 causes instantaneous reports to be
// sent based on parameters 91 & 92
{paramId: 90, value: 1, size: 1},
// Parameter 91 is the minimum change (in watts) required to induce
// a meter report.
{paramId: 91, value: 25, size: 2},
// Parameter 92 is the minimum change (in wattage percent) to induce
// a meter report.
{paramId: 92, value: 5, size: 1},
// Setting the following to non-zero causes periodic reports to
// be sent based on parameters 111-113
{paramId: 101, value: 0, size: 4},
{paramId: 102, value: 0, size: 4},
{paramId: 103, value: 0, size: 4},
],
isLight: false,
},
{
// Aeotec Products without Energy Metering
zwInfo: {
manufacturerId: AEOTEC_MANUFACTURER_ID,
productIds: [
AEOTEC_ZW116_PRODUCT_ID, // Nano Switch
AEOTEC_ZW139_PRODUCT_ID, // Nano Switch (End of Life)
AEOTEC_ZW140_PRODUCT_ID, // Dual Nano Switch
AEOTEC_ZW141_PRODUCT_ID, // Nano Shutter
],
},
// polling isn't required with the configuration change below
disablePoll: true,
setConfigs: [
// Enable to send a Basic CC Report when the switch state
// changes.
{paramId: 80, value: 2, size: 1},
],
isLight: false,
},
{
// The Aeotec ZW100 says it supports the SENSOR_BINARY command class,
// but this is only true for some configurations. We use the alarm
// command class instead.
// We remove the 'on' property so that the UI doesn't see it.
zwInfo: {
manufacturerId: AEOTEC_MANUFACTURER_ID,
productId: AEOTEC_ZW100_PRODUCT_ID,
},
excludeProperties: ['on'],
setConfigs: [
// Configure motion sensor to send 'Basic Set', rather than
// 'Binary Sensor report'.
{paramId: 5, value: 1, size: 1},
// Enable threshold reporting
{paramId: 40, value: 1, size: 1},
// Report 0.5C temperature changes
{paramId: 41, value: 0x00050100, size: 4},
],
},
{
// By default, the Aeotec ZW130 only sends presses and not
// swipes. Setting this config allows swipes to be detected
// as well.
zwInfo: {
manufacturerId: AEOTEC_MANUFACTURER_ID,
productId: AEOTEC_ZW130_PRODUCT_ID,
},
setConfigs: [
// Configure what will be sent when pressing a button. The
// default value of 2 just sends a Central Scene Notification.
// A value of 3 also sends configuration reports.
// Note: We want to set the value to 3, which corresponds to the
// an item index of 2 since the zw130.xml file is missing an
// entry for a value of 2.
// Index 0 = Value 0
// Index 1 = Value 1
// Index 2 = Value 3
// The OpenZWave C++ API is a bit deceiving in that it's called
// SetByValue, but for lists, the value is in the index into the
// list.
{paramId: 4, value: 2, size: 1},
],
},
];
function quirkMatches(quirk, node) {
let match = true;
for (const id in quirk.zwInfo) {
if (id === 'productIds') {
if (!quirk.zwInfo.productIds.includes(node.zwInfo.productId)) {
match = false;
break;
}
} else if (node.zwInfo[id] !== quirk.zwInfo[id]) {
match = false;
break;
}
}
return match;
}
function levelToHex(level) {
// level is excpected to be 0-100
// this returns 00-ff
const hexValue = Math.round(Math.min(255, Math.max(0, level * 255 / 100)));
const hexStr = `00${hexValue.toString(16)}`.substr(-2);
const newLevel = Math.round(hexValue * 100 / 255);
return [hexStr, newLevel];
}
class ZWaveClassifier {
classify(node) {
DEBUG && console.log(`classify: called for ${node.id}`,
`name = ${node.name}`,
`defaultName = ${node.defaultName}`);
this.classifyInternal(node);
node.classified = true;
// Any type of device can be battery powered, so we do this check for
// all devices.
const batteryValueId =
node.findValueId(COMMAND_CLASS.BATTERY,
1,
BATTERY_INDEX_LEVEL);
if (batteryValueId) {
this.addBatteryProperty(node, batteryValueId);
}
DEBUG && console.log(`classify: ${node.id} named ${node.name}`,
`defaultName: ${node.defaultName} types:`,
node['@type']);
}
classifyInternal(node) {
const zwave = node.adapter.zwave;
const nodeId = node.zwInfo.nodeId;
DEBUG_classifier &&
console.log('classifyInternal:',
`manufacturerId: ${node.zwInfo.manufacturerId}`,
`productId: ${node.zwInfo.productId}`);
// Search through the known quirks and see if we need to apply any
// configurations
for (const quirk of QUIRKS) {
if (!quirkMatches(quirk, node)) {
continue;
}
if (quirk.hasOwnProperty('disablePoll')) {
console.log(`Device ${node.id}`,
`Setting disablePoll to ${quirk.disablePoll}`);
node.disablePoll = quirk.disablePoll;
}
if (quirk.hasOwnProperty('isLight')) {
node.isLight = quirk.isLight;
}
if (!quirk.hasOwnProperty('setConfigs')) {
continue;
}
for (const setConfig of quirk.setConfigs) {
const valueId = node.findValueId(COMMAND_CLASS.CONFIGURATION,
1, setConfig.paramId);
if (valueId) {
const zwValue = node.zwValues[valueId];
if (zwValue) {
let value = zwValue.value;
if (zwValue.type == 'list') {
// For lists, the value contains the looked up string
// rather than the index. Figure out the index.
const idx = zwValue.values.indexOf(zwValue.value);
if (idx < 0) {
// This shouldn't happen. If it does it means that
// something in the config file has changed.
console.error(`Device ${node.id} config ` +
`paramId: ${setConfig.paramId} ` +
`unable to determine index of '${value}'`);
continue;
}
value = idx;
}
console.log(`Setting device ${node.id} config ` +
`paramId: ${setConfig.paramId} ` +
`to value: ${setConfig.value} ` +
`size: ${setConfig.size}`);
zwave.setConfigParam(nodeId,
setConfig.paramId,
setConfig.value,
setConfig.size);
} else {
console.error(`Device ${node.id} config ` +
`paramId: ${setConfig.paramId} ` +
`unable to find value with id ${valueId}`);
}
} else {
console.error(`Device ${node.id} config ` +
`paramId: ${setConfig.paramId} ` +
`unable to find valueId`);
}
}
}
const genericType = zwave.getNodeGeneric(nodeId);
node.zwInfo.genericType = genericType;
const basicType = zwave.getNodeBasic(nodeId);
node.zwInfo.basicType = basicType;
const specificType = zwave.getNodeSpecific(nodeId);
node.zwInfo.specificType = specificType;
const colorCapabilitiesValueId =
node.findValueId(COMMAND_CLASS.COLOR,
1,
COLOR_INDEX.CAPABILITIES);
const binarySwitchValueId =
node.findValueId(COMMAND_CLASS.SWITCH_BINARY,
1,
SWITCH_BINARY_INDEX_SWITCH);
const doorLockValueId =
node.findValueId(COMMAND_CLASS.DOOR_LOCK,
1,
DOOR_LOCK_LOCKED);
const levelValueId =
node.findValueId(COMMAND_CLASS.SWITCH_MULTILEVEL,
1,
SWITCH_MULTILEVEL_INDEX_LEVEL);
const alarmValueId =
node.findValueId(COMMAND_CLASS.ALARM,
1,
ALARM_INDEX_HOME_SECURITY);
const binarySensorValueId =
node.findValueId(COMMAND_CLASS.SENSOR_BINARY,
1,
SENSOR_BINARY_INDEX_SENSOR);
const centralSceneValueId =
node.findValueId(COMMAND_CLASS.CENTRAL_SCENE,
1,
CENTRAL_SCENE.SCENE_COUNT);
const temperatureValueId =
node.findValueId(COMMAND_CLASS.SENSOR_MULTILEVEL,
1,
SENSOR_MULTILEVEL_INDEX_TEMPERATURE);
const carbonMonoxideValueId =
node.findValueId(COMMAND_CLASS.SENSOR_MULTILEVEL,
1,
SENSOR_MULTILEVEL_INDEX_CO_LEVEL);
const luminanceValueId =
node.findValueId(COMMAND_CLASS.SENSOR_MULTILEVEL,
1,
SENSOR_MULTILEVEL_INDEX_LUMINANCE);
const humidityValueId =
node.findValueId(COMMAND_CLASS.SENSOR_MULTILEVEL,
1,
SENSOR_MULTILEVEL_INDEX_RELATIVE_HUMIDITY);
const uvValueId =
node.findValueId(COMMAND_CLASS.SENSOR_MULTILEVEL,
1,
SENSOR_MULTILEVEL_INDEX_ULTRAVIOLET);
const wakeUpIntervalValueId =
node.findValueId(COMMAND_CLASS.WAKE_UP,
1,
WAKEUP_INTERVAL_VALUE);
const minWakeUpIntervalValueId =
node.findValueId(COMMAND_CLASS.WAKE_UP,
1,
WAKEUP_INTERVAL_MIN);
const maxWakeUpIntervalValueId =
node.findValueId(COMMAND_CLASS.WAKE_UP,
1,
WAKEUP_INTERVAL_MAX);
if (DEBUG) {
const genericTypeStr = GENERIC_TYPE_STR[genericType] || 'unknown';
console.log(`classify: called for node ${node.id},`,
`genericType = ${genericTypeStr}`,
`(0x${genericType.toString(16)})`);
console.log('classify: colorCapabilitiesValueId =',
colorCapabilitiesValueId);
console.log('classify: binarySwitchValueId =', binarySwitchValueId);
console.log('classify: doorLockValueId =', doorLockValueId);
console.log('classify: levelValueId =', levelValueId);
console.log('classify: binarySensorValueId =', binarySensorValueId);
console.log('classify: centralSceneValueId =', centralSceneValueId);
console.log('classify: alarmValueId =', alarmValueId);
console.log('classify: temperatureValueId =', temperatureValueId);
console.log('classify: luminanceValueId =', luminanceValueId);
console.log('classify: humidityValueId =', humidityValueId);
console.log('classify: wakeUpIntervalValueId =',
wakeUpIntervalValueId);
console.log('classify: minWakeUpIntervalValueId =',
minWakeUpIntervalValueId);
console.log('classify: maxWakeUpIntervalValueId =',
maxWakeUpIntervalValueId);
console.log('classify: carbonMonoxideValueId =',
carbonMonoxideValueId);
console.log('classify: quirk.isLight =', node.isLight);
}
node.type = 'thing'; // Just in case it doesn't classify as anything else
if (!node.hasOwnProperty('@type')) {
node['@type'] = [];
}
switch (genericType) {
case GENERIC_TYPE.SWITCH_BINARY:
case GENERIC_TYPE.SWITCH_MULTILEVEL:
{
// The Aeotec Smart Switch 6 and Smart Dimmer 6 have color capabilities
// but aren't lights.
if (colorCapabilitiesValueId) {
if (!node.hasOwnProperty('isLight') || node.isLight) {
this.initLight(node, colorCapabilitiesValueId, levelValueId);
return;
}
}
const bsValueId = [null, binarySwitchValueId];
const lvlValueId = [null, levelValueId];
let instance = 1;
do {
instance += 1;
bsValueId[instance] =
node.findValueId(COMMAND_CLASS.SWITCH_BINARY,
instance,
SWITCH_BINARY_INDEX_SWITCH);
lvlValueId[instance] =
node.findValueId(COMMAND_CLASS.SWITCH_MULTILEVEL,
instance,
SWITCH_MULTILEVEL_INDEX_LEVEL);
} while (bsValueId[instance] || lvlValueId[instance]);
// Instances are numbered starting at 1 (not zero), and instance
// will also be 1 higher since the last time through the do/while
// loop will have stored undefined in both bsValueId and lvlValueId
const instanceCount = instance - 1;
if (instanceCount < 3) {
// Some devices (like the ZW099 Smart Dimmer 6) advertise instance
// 1 and 2, and don't seem to work on instance 2. So we always
// use instance 1 for the first outlet, and then 3 and beyond for the
// second and beyond outlets.
this.initSwitch(node, bsValueId[1], lvlValueId[1], '');
} else {
// 2 or more switches
if (node.zwInfo.manufacturerId == AEOTEC_MANUFACTURER_ID) {
// With Aeotec, when there are multiple switches, then
// instances 2 - N are used. Instance 1 seems to control
// all of the switches.
// At least this is true for the Dual Nano Switch
this.initSwitch(node, bsValueId[2], lvlValueId[2], '');
} else {
// The only other dual switch tested needed to use instance
// 1 and 3. It was an inovelli 2 channel Dual Smart Plug (ZW37)
// and I can't find it for sale anyplace. The one I tested with
// was loaned from Lars.
this.initSwitch(node, bsValueId[1], lvlValueId[1], '');
}
let switchNum = 2;
for (instance = 3; instance <= instanceCount; instance++) {
this.initSwitch(node, bsValueId[instance], lvlValueId[instance],
switchNum.toString());
switchNum += 1;
}
}
break;
}
case GENERIC_TYPE.SENSOR_BINARY:
this.initBinarySensor(node, binarySensorValueId);
break;
case GENERIC_TYPE.SENSOR_MULTILEVEL:
case GENERIC_TYPE.SENSOR_NOTIFICATION:
this.initSensorNotification(node);
break;
case GENERIC_TYPE.SENSOR_ALARM:
this.initSensorAlarm(node);
break;
case GENERIC_TYPE.WALL_CONTROLLER:
this.initCentralScene(node);
break;
case GENERIC_TYPE.ENTRY_CONTROL:
this.initEntryControl(node, doorLockValueId);
break;
case GENERIC_TYPE.THERMOSTAT:
this.initThermostat(node);
break;
default: {
const genericTypeStr = GENERIC_TYPE_STR[genericType] || 'unknown';
console.error(`Node: ${nodeId}`,
`unsupported genericType: ${genericType}`,
`(${genericTypeStr})`);
break;
}
}
if (alarmValueId) {
this.addAlarmProperty(node, alarmValueId);
}
if (temperatureValueId) {
this.addTemperatureProperty(node, temperatureValueId);
}
if (carbonMonoxideValueId) {
this.addCarbonMonoxideLevelProperty(node, carbonMonoxideValueId);
}
if (luminanceValueId) {
this.addLuminanceProperty(node, luminanceValueId);
}
if (humidityValueId) {
this.addHumidityProperty(node, humidityValueId);
}
if (uvValueId) {
this.addUltravioletProperty(node, uvValueId);
}
if (wakeUpIntervalValueId) {
this.addWakeUpProperty(node, wakeUpIntervalValueId,
minWakeUpIntervalValueId,
maxWakeUpIntervalValueId);
}
}
addActions(node, actions) {
for (const actionName in actions) {
node.addAction(actionName, actions[actionName]);
}
}
addEvents(node, events) {
for (const eventName in events) {
node.addEvent(eventName, events[eventName]);
}
}
addProperty(node, name, descr, valueId,
setZwValueFromValue, parseValueFromZwValue) {
// Search through the known quirks and see if we need to apply any.
for (const quirk of QUIRKS) {
if (!quirk.hasOwnProperty('excludeProperties')) {
continue;
}
if (quirkMatches(quirk, node) && quirk.excludeProperties.includes(name)) {
console.log(
`Not adding property ${name} to device ${node.id} due to quirk.`);
return;
}
}
const property = new ZWaveProperty(node, name, descr, valueId,
setZwValueFromValue,
parseValueFromZwValue);
DEBUG && console.log(`classify: ${node.id} added property: ${name}`,
`valueId: ${valueId} value: ${property.value}`);
if (name[0] == '_') {
property.visible = false;
}
node.properties.set(name, property);
// Invisible properties are no longer exposed in Thing Descriptions so
// should eventually be removed entirely.
// See https://github.com/WebThingsIO/zwave-adapter/issues/140
return property;
}
addAlarmProperty(node, alarmValueId) {
this.addProperty(
node,
'motion',
{
'@type': 'BooleanProperty',
label: 'Motion',
type: 'boolean',
},
alarmValueId,
'',
'parseAlarmMotionZwValue'
);
this.addProperty(
node,
'tamper',
{
'@type': 'BooleanProperty',
label: 'Tamper',
type: 'boolean',
},
alarmValueId,
'',
'parseAlarmTamperZwValue'
);
}
addBatteryProperty(node, batteryValueId) {
this.addProperty(
node,
'batteryLevel',
{
'@type': 'LevelProperty',
label: 'Battery',
type: 'number',
minimum: 0,
maximum: 100,
unit: 'percent',
readOnly: true,
},
batteryValueId
);
}
addHumidityProperty(node, humidityValueId) {
this.addProperty(
node,
'humidity',
{
'@type': 'HumidityProperty',
label: 'Humidity',
type: 'number',
minimum: 0,
maximum: 100,
unit: 'percent',
readOnly: true,
},
humidityValueId
);
if (!node['@type'].includes('HumiditySensor')) {
node['@type'].push('HumiditySensor');
}
}
addLuminanceProperty(node, luminanceValueId) {
this.addProperty(
node,
'luminance',
{
// TODO: add proper @type
label: 'Luminance',
type: 'number',
unit: 'lux',
readOnly: true,
},
luminanceValueId
);
}
addTemperatureProperty(node, temperatureValueId) {
this.addProperty(
node,
'temperature',
{
'@type': 'TemperatureProperty',
title: 'Temperature',
type: 'number',
unit: 'degree celsius',
multipleOf: 0.1,
readOnly: true,
},
temperatureValueId,
null,
'parseTemperatureZwValue'
);
if (!node['@type'].includes('TemperatureSensor')) {
node['@type'].push('TemperatureSensor');
}
}
addCarbonMonoxideLevelProperty(node, carbonMonoxideValueId) {
this.addProperty(
node,
'carbonMonoxideLevel',
{
'@type': 'ConcentrationProperty',
label: 'Carbon Monoxide Level',
type: 'number',
readOnly: true,
unit: 'ppm',
multipleOf: 0.1,
},
carbonMonoxideValueId,
);
if (!node['@type'].includes('AirQualitySensor')) {
node['@type'].push('AirQualitySensor');
}
}
addHeatingTargetTemperatureProperty(node, heatingTargetTempValueId) {
this.addProperty(
node,
'heatingTargetTemperature',
{
'@type': 'TargetTemperatureProperty',
title: 'Heating Target',
type: 'number',
unit: 'degree celsius',
multipleOf: 0.5,
minimum: 0,
maximum: 40,
},
heatingTargetTempValueId,
'setTemperatureValue',
'parseTemperatureZwValue'
);
}
addCoolingTargetTemperatureProperty(node, coolingTargetTempValueId) {
this.addProperty(
node,
'coolingTargetTemperature',
{
'@type': 'TargetTemperatureProperty',
title: 'Cooling Target',
type: 'number',
unit: 'degree celsius',
multipleOf: 0.5,
minimum: 0,
maximum: 40,
},
coolingTargetTempValueId,
'setTemperatureValue',
'parseTemperatureZwValue'
);
}
addFanModeProperty(node, fanModeValueId) {
const zwValue = node.zwValues[fanModeValueId];
if (!zwValue) {
return;
}
this.addProperty(
node,
'fanMode',
{
title: 'Fan Mode',
type: 'string',
enum: zwValue.values,
},
fanModeValueId
);
}
addFanStateProperty(node, fanStateValueId) {
const zwValue = node.zwValues[fanStateValueId];
if (!zwValue) {
return;
}
this.addProperty(
node,
'fanState',
{
title: 'Fan State',
type: 'string',
readOnly: true,
},
fanStateValueId
);
}
addThermostatModeProperty(node, thermostatModeValueId) {
const zwValue = node.zwValues[thermostatModeValueId];
if (!zwValue) {
return;
}
const lowerCaseValues = zwValue.values.map((v) => v.toLowerCase());
const property = this.addProperty(
node,
'thermostatMode',
{
title: 'Mode',
type: 'string',
'@type': 'ThermostatModeProperty',
enum: lowerCaseValues,
},
thermostatModeValueId,
'setLowerCaseValue',
'parseZwStringToLowerCase'
);
property.lowerCaseValues = lowerCaseValues;
}
addThermostatStateProperty(node, thermostatStateValueId) {
const zwValue = node.zwValues[thermostatStateValueId];
if (!zwValue) {
return;
}
this.addProperty(
node,
'heating',
{
title: 'Heating/Cooling',
type: 'string',
'@type': 'HeatingCoolingProperty',
readOnly: true,
},
thermostatStateValueId,
null,
'parseZwStringToLowerCase'