homebridge-cmd4 5.1.0 → 6.0.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.
- package/CHANGELOG.md +51 -20
- package/Cmd4Accessory.js +521 -514
- package/Cmd4Platform.js +80 -65
- package/Cmd4PriorityPollingQueue.js +37 -44
- package/Extras/Cmd4Scripts/Examples/AirPurifier.js +2 -2
- package/Extras/Cmd4Scripts/Examples/AnyDevice +3 -3
- package/Extras/Cmd4Scripts/Examples/DoorLock.sh +3 -3
- package/Extras/Cmd4Scripts/Examples/ExampleJavaScript_template.js +2 -2
- package/Extras/Cmd4Scripts/Examples/ExampleShellScript_template.sh +4 -4
- package/Extras/Cmd4Scripts/Examples/SecuritySystem.js +368 -0
- package/Extras/Cmd4Scripts/State.js +301 -279
- package/Extras/config.json +735 -735
- package/Extras/config.min.json +778 -778
- package/README.md +1 -1
- package/RUNNING_CHANGELOG.md +57 -0
- package/cmd4Constants.js +139 -140
- package/docs/AdvancedTroubleShooting.md +2 -2
- package/docs/Developers.md +107 -108
- package/lib/CMD4_ACC_TYPE_ENUM.js +553 -282
- package/lib/CMD4_DEVICE_TYPE_ENUM.js +38 -12
- package/package.json +5 -2
- package/utils/Cmd4Storage.js +132 -0
- package/utils/HV.js +76 -0
- package/utils/Logger.js +1 -0
- package/utils/getAccessoryUUID.js +2 -0
- package/utils/isAccDirective.js +54 -0
- package/utils/isCmd4Directive.js +56 -0
- package/utils/isDevDirective.js +58 -0
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
const constants = require( "../cmd4Constants" );
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
// The sObject.defineProperty is to resolve a lint issue.
|
|
7
|
+
// See utils/indexOfEnumLintTest.js for further information.
|
|
8
|
+
let indexOfEnum = require( "../utils/indexOfEnum" );
|
|
9
|
+
Object.defineProperty( exports, "indexOfEnum", { enumerable: true, get: function ( ){ return indexOfEnum.indexOfEnum; } });
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
6
13
|
var CMD4_DEVICE_TYPE_ENUM =
|
|
7
14
|
{
|
|
8
15
|
AccessControl: 0,
|
|
@@ -73,7 +80,19 @@ var CMD4_DEVICE_TYPE_ENUM =
|
|
|
73
80
|
WindowCovering: 65,
|
|
74
81
|
EOL: 66,
|
|
75
82
|
|
|
76
|
-
properties:{}
|
|
83
|
+
properties:{},
|
|
84
|
+
|
|
85
|
+
devEnumIndexToC: function( index )
|
|
86
|
+
{
|
|
87
|
+
return CMD4_DEVICE_TYPE_ENUM.properties[ index ].deviceName;
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
indexOfEnum: function( deviceName )
|
|
91
|
+
{
|
|
92
|
+
return CMD4_DEVICE_TYPE_ENUM.properties.indexOfEnum( i => i.deviceName === deviceName );
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
|
|
77
96
|
};
|
|
78
97
|
|
|
79
98
|
// Export both the init function and the uninitialized data for unit testing
|
|
@@ -591,7 +610,8 @@ module.exports =
|
|
|
591
610
|
CMD4_ACC_TYPE_ENUM.Name
|
|
592
611
|
],
|
|
593
612
|
defaultPollingCharacteristics:
|
|
594
|
-
[ CMD4_ACC_TYPE_ENUM.CurrentPosition
|
|
613
|
+
[ CMD4_ACC_TYPE_ENUM.CurrentPosition,
|
|
614
|
+
CMD4_ACC_TYPE_ENUM.TargetPosition
|
|
595
615
|
]
|
|
596
616
|
},
|
|
597
617
|
17: { deviceName:'DoorBell',
|
|
@@ -758,7 +778,8 @@ module.exports =
|
|
|
758
778
|
CMD4_ACC_TYPE_ENUM.Name
|
|
759
779
|
],
|
|
760
780
|
defaultPollingCharacteristics:
|
|
761
|
-
[ CMD4_ACC_TYPE_ENUM.CurrentDoorState
|
|
781
|
+
[ CMD4_ACC_TYPE_ENUM.CurrentDoorState,
|
|
782
|
+
CMD4_ACC_TYPE_ENUM.TargetDoorState
|
|
762
783
|
]
|
|
763
784
|
},
|
|
764
785
|
24: { deviceName:'HeaterCooler',
|
|
@@ -1071,7 +1092,8 @@ module.exports =
|
|
|
1071
1092
|
[ CMD4_ACC_TYPE_ENUM.Name
|
|
1072
1093
|
],
|
|
1073
1094
|
defaultPollingCharacteristics:
|
|
1074
|
-
[ CMD4_ACC_TYPE_ENUM.LockCurrentState
|
|
1095
|
+
[ CMD4_ACC_TYPE_ENUM.LockCurrentState,
|
|
1096
|
+
CMD4_ACC_TYPE_ENUM.LockTargetState
|
|
1075
1097
|
]
|
|
1076
1098
|
},
|
|
1077
1099
|
34: { deviceName:'Microphone',
|
|
@@ -1177,22 +1199,22 @@ module.exports =
|
|
|
1177
1199
|
publishExternally: false,
|
|
1178
1200
|
devicesStateChangeDefaultTime: constants.MEDIUM_STATE_CHANGE_RESPONSE_TIME,
|
|
1179
1201
|
requiredCharacteristics:
|
|
1180
|
-
[ {type: CMD4_ACC_TYPE_ENUM.
|
|
1202
|
+
[ {type: CMD4_ACC_TYPE_ENUM.ListPairings,
|
|
1181
1203
|
defaultValue: 1, // Format: Uint8. Values ???
|
|
1182
1204
|
relatedCurrentAccTypeEnumArray: [ ],
|
|
1183
1205
|
relatedTargetAccTypeEnumArray: [ ]
|
|
1184
1206
|
},
|
|
1185
|
-
{type: CMD4_ACC_TYPE_ENUM.
|
|
1207
|
+
{type: CMD4_ACC_TYPE_ENUM.PairSetup,
|
|
1186
1208
|
defaultValue: 0, // Format: TLV8
|
|
1187
1209
|
relatedCurrentAccTypeEnumArray: [ ],
|
|
1188
1210
|
relatedTargetAccTypeEnumArray: [ ]
|
|
1189
1211
|
},
|
|
1190
|
-
{type: CMD4_ACC_TYPE_ENUM.
|
|
1212
|
+
{type: CMD4_ACC_TYPE_ENUM.PairVerify,
|
|
1191
1213
|
defaultValue: 0, // Format: Uint8
|
|
1192
1214
|
relatedCurrentAccTypeEnumArray: [ ],
|
|
1193
1215
|
relatedTargetAccTypeEnumArray: [ ]
|
|
1194
1216
|
},
|
|
1195
|
-
{type: CMD4_ACC_TYPE_ENUM.
|
|
1217
|
+
{type: CMD4_ACC_TYPE_ENUM.PairingFeatures,
|
|
1196
1218
|
defaultValue: 0, // Format: TLV8
|
|
1197
1219
|
relatedCurrentAccTypeEnumArray: [ ],
|
|
1198
1220
|
relatedTargetAccTypeEnumArray: [ ]
|
|
@@ -1300,8 +1322,10 @@ module.exports =
|
|
|
1300
1322
|
CMD4_ACC_TYPE_ENUM.Name
|
|
1301
1323
|
],
|
|
1302
1324
|
defaultPollingCharacteristics:
|
|
1303
|
-
[ CMD4_ACC_TYPE_ENUM.SecuritySystemCurrentState
|
|
1304
|
-
|
|
1325
|
+
[ CMD4_ACC_TYPE_ENUM.SecuritySystemCurrentState,
|
|
1326
|
+
CMD4_ACC_TYPE_ENUM.SecuritySystemTargetState
|
|
1327
|
+
]
|
|
1328
|
+
},
|
|
1305
1329
|
43: { deviceName:'ServiceLabel',
|
|
1306
1330
|
UUID: "000000CC-0000-1000-8000-0026BB765291",
|
|
1307
1331
|
service: Service.ServiceLabel,
|
|
@@ -1951,7 +1975,8 @@ module.exports =
|
|
|
1951
1975
|
CMD4_ACC_TYPE_ENUM.Name
|
|
1952
1976
|
],
|
|
1953
1977
|
defaultPollingCharacteristics:
|
|
1954
|
-
[ CMD4_ACC_TYPE_ENUM.CurrentPosition
|
|
1978
|
+
[ CMD4_ACC_TYPE_ENUM.CurrentPosition,
|
|
1979
|
+
CMD4_ACC_TYPE_ENUM.TargetPosition
|
|
1955
1980
|
]
|
|
1956
1981
|
},
|
|
1957
1982
|
65: { deviceName:'WindowCovering',
|
|
@@ -1989,7 +2014,8 @@ module.exports =
|
|
|
1989
2014
|
CMD4_ACC_TYPE_ENUM.Name
|
|
1990
2015
|
],
|
|
1991
2016
|
defaultPollingCharacteristics:
|
|
1992
|
-
[ CMD4_ACC_TYPE_ENUM.CurrentPosition
|
|
2017
|
+
[ CMD4_ACC_TYPE_ENUM.CurrentPosition,
|
|
2018
|
+
CMD4_ACC_TYPE_ENUM.TargetPosition
|
|
1993
2019
|
]
|
|
1994
2020
|
}
|
|
1995
2021
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-cmd4",
|
|
3
3
|
"description": "Exec Plugin for Homebridge supporting all accessorys and characteristics",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.0.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "John Talbot"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@commitlint/cli": "^11.0.0",
|
|
29
29
|
"@commitlint/config-conventional": "^11.0.0",
|
|
30
30
|
"chai": "^4.2.0",
|
|
31
|
-
"commander": "^2.
|
|
31
|
+
"commander": "^8.2.0",
|
|
32
32
|
"commitlint-plugin-function-rules": "^1.1.20",
|
|
33
33
|
"eslint": "^7.17.0",
|
|
34
34
|
"generate-changelog": "^1.8.0",
|
|
@@ -78,6 +78,9 @@
|
|
|
78
78
|
"pretest": "printf ' test is only done in a development environment\n';sleep 2 ",
|
|
79
79
|
"testDebug": "node_modules/.bin/mocha --require async-dump.js --file test/mocha-setup --ignore test/versionChecker.js",
|
|
80
80
|
"test": "node_modules/.bin/mocha --file test/mocha-setup --ignore test/versionChecker.js",
|
|
81
|
+
"singleTest": "node_modules/.bin/mocha --bail --file test/mocha-setup --ignore test/versionChecker.js",
|
|
82
|
+
"allTests": "node_modules/.bin/mocha --bail --file test/mocha-setup $( cat test/allTests )",
|
|
83
|
+
"sanityTests": "node_modules/.bin/mocha --bail --file test/mocha-setup $( cat test/sanityTests )",
|
|
81
84
|
"_Note0": "Excluded from commit as may fail for probing GitHub to much",
|
|
82
85
|
"testMarkDown": "markdown-link-check ./README.md && markdown-link-check ./CHANGELOG.md",
|
|
83
86
|
"commitTests": "npm run test && npm run testMarkDown",
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// These would already be initialized by index.js
|
|
4
|
+
let CMD4_ACC_TYPE_ENUM = require( "../lib/CMD4_ACC_TYPE_ENUM" ).CMD4_ACC_TYPE_ENUM;
|
|
5
|
+
|
|
6
|
+
class Cmd4Storage
|
|
7
|
+
{
|
|
8
|
+
constructor( log, cmd4Storage )
|
|
9
|
+
{
|
|
10
|
+
this.CLASS_VERSION = 1;
|
|
11
|
+
this.DATA = [ ];
|
|
12
|
+
|
|
13
|
+
if ( cmd4Storage == undefined )
|
|
14
|
+
{
|
|
15
|
+
log.debug("Init new cmd4Storage" );
|
|
16
|
+
|
|
17
|
+
// init new
|
|
18
|
+
this.DATA = new Array( CMD4_ACC_TYPE_ENUM.EOL ).fill( null );
|
|
19
|
+
|
|
20
|
+
} else if ( cmd4Storage instanceof Cmd4Storage )
|
|
21
|
+
{
|
|
22
|
+
log.debug("Class is Cmd4Storage version: %s", cmd4Storage.version );
|
|
23
|
+
if ( cmd4Storage.CLASS_VERSION == this.CLASS_VERSION )
|
|
24
|
+
{
|
|
25
|
+
// The same. I can just load its data
|
|
26
|
+
this.loadLatestData( cmd4Storage.DATA );
|
|
27
|
+
} else {
|
|
28
|
+
throw new Error( `Do not know how to handle Cmd4_Storage Class version: ${ cmd4Storage.CLASS_VERSION }` );
|
|
29
|
+
}
|
|
30
|
+
} else if ( Array.isArray( cmd4Storage ) )
|
|
31
|
+
{
|
|
32
|
+
log.debug("Cmd4Storage is Array" );
|
|
33
|
+
// Init original unversioned
|
|
34
|
+
let data = this.upgradeDataArray( 0, cmd4Storage );
|
|
35
|
+
this.loadLatestData( data );
|
|
36
|
+
|
|
37
|
+
} else if ( cmd4Storage.constructor === Object )
|
|
38
|
+
{
|
|
39
|
+
log.debug("Cmd4Storage is Object version %s", cmd4Storage.CLASS_VERSION );
|
|
40
|
+
if ( cmd4Storage.CLASS_VERSION == this.CLASS_VERSION )
|
|
41
|
+
{
|
|
42
|
+
// The same. I can just load its data
|
|
43
|
+
this.loadLatestData( cmd4Storage.DATA );
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error( `Do not know how to handle Cmd4_Storage Class version: ${ cmd4Storage.CLASS_VERSION }` );
|
|
46
|
+
}
|
|
47
|
+
} else
|
|
48
|
+
{
|
|
49
|
+
// Woops init new
|
|
50
|
+
log.error( "cmd4Storage is %s", cmd4Storage );
|
|
51
|
+
console.error( "cmd4Storage.constructor.name is %s", cmd4Storage.constructor.name );
|
|
52
|
+
throw new Error( `Do not know how to handle typeof: ${ typeof cmd4Storage } Cmd4_Storage parm: ${ cmd4Storage }` );
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
upgradeDataArray( fromVersion, fromData)
|
|
57
|
+
{
|
|
58
|
+
let data = [ ];
|
|
59
|
+
|
|
60
|
+
if ( fromVersion != 0 )
|
|
61
|
+
throw new Error( `Do not know how to handle Cmd4_Storage version: ${ fromVersion }` );
|
|
62
|
+
|
|
63
|
+
// Version 0 ACC_DATA went from 0-122
|
|
64
|
+
// This version goes from 1-123 and changes to
|
|
65
|
+
// Assoc array so that index changes like this will no longer
|
|
66
|
+
// impact the storage schema as much
|
|
67
|
+
let i=0;
|
|
68
|
+
for ( i=0; i < CMD4_ACC_TYPE_ENUM.ListPairings; i++ )
|
|
69
|
+
{
|
|
70
|
+
data[ i ] = fromData[ i ];
|
|
71
|
+
}
|
|
72
|
+
data[ CMD4_ACC_TYPE_ENUM.ListPairing ] = null;
|
|
73
|
+
for ( i = CMD4_ACC_TYPE_ENUM.ListPairings +1; i < CMD4_ACC_TYPE_ENUM.EOL; i++ )
|
|
74
|
+
{
|
|
75
|
+
data[ i ] = fromData[ i - 1 ];
|
|
76
|
+
}
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
loadLatestData( data )
|
|
81
|
+
{
|
|
82
|
+
this.DATA = data;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getStoredValueForIndex( accTypeEnumIndex )
|
|
86
|
+
{
|
|
87
|
+
if ( accTypeEnumIndex < 0 || accTypeEnumIndex >= CMD4_ACC_TYPE_ENUM.EOL )
|
|
88
|
+
throw new Error( `getStoredValue - Characteristic index: ${ accTypeEnumIndex } not between 0 and ${ CMD4_ACC_TYPE_ENUM.EOL }\nCheck your config.json file for unknown characteristic.` );
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
return this.DATA[ accTypeEnumIndex ];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getStoredValueForCharacteristic( characteristicString )
|
|
95
|
+
{
|
|
96
|
+
let accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.indexOfEnum( characteristicString );
|
|
97
|
+
|
|
98
|
+
return this.getStoredValueForIndex( accTypeEnumIndex );
|
|
99
|
+
}
|
|
100
|
+
setStoredValueForIndex( accTypeEnumIndex, value )
|
|
101
|
+
{
|
|
102
|
+
if ( accTypeEnumIndex < 0 || accTypeEnumIndex >= CMD4_ACC_TYPE_ENUM.EOL )
|
|
103
|
+
throw new Error( `setStoredValue - Characteristic index: ${ accTypeEnumIndex } not between 0 and ${ CMD4_ACC_TYPE_ENUM.EOL }\nCheck your config.json file for unknown characteristic.` );
|
|
104
|
+
|
|
105
|
+
this.DATA[ accTypeEnumIndex ] = value;
|
|
106
|
+
}
|
|
107
|
+
setStoredValueForCharacteristic( characteristicString, value )
|
|
108
|
+
{
|
|
109
|
+
let accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.indexOfEnum( characteristicString );
|
|
110
|
+
|
|
111
|
+
this.setStoredValueForIndex( accTypeEnumIndex, value );
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Unlike get/set, testStoredValueForIndex does not call process.exit,
|
|
115
|
+
// but undefined for an illegal range, in the case that rogue runtime data
|
|
116
|
+
// dies not take down CMD4.
|
|
117
|
+
testStoredValueForIndex( accTypeEnumIndex )
|
|
118
|
+
{
|
|
119
|
+
if ( accTypeEnumIndex < 0 || accTypeEnumIndex > CMD4_ACC_TYPE_ENUM.EOL )
|
|
120
|
+
return undefined;
|
|
121
|
+
|
|
122
|
+
return this.DATA[ accTypeEnumIndex ];
|
|
123
|
+
}
|
|
124
|
+
testStoredValueForCharacteristic( characteristicString )
|
|
125
|
+
{
|
|
126
|
+
let accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.indexOfEnum( characteristicString );
|
|
127
|
+
|
|
128
|
+
return this.testStoredValueForIndex( accTypeEnumIndex );
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = Cmd4Storage;
|
package/utils/HV.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const constants = require( "../cmd4Constants" );
|
|
4
|
+
|
|
5
|
+
// These would already be initialized by index.js
|
|
6
|
+
let CMD4_DEVICE_TYPE_ENUM = require( "../lib/CMD4_DEVICE_TYPE_ENUM" ).CMD4_DEVICE_TYPE_ENUM;
|
|
7
|
+
|
|
8
|
+
class HV
|
|
9
|
+
{
|
|
10
|
+
constructor ()
|
|
11
|
+
{
|
|
12
|
+
this.allowTLV8 = constants.DEFAULT_ALLOW_TLV8;
|
|
13
|
+
this.debug = constants.DEFAULT_DEBUG;
|
|
14
|
+
this.outputConstants = constants.DEFAULT_OUTPUTCONSTANTS;
|
|
15
|
+
this.interval = constants.DEFAULT_INTERVAL;
|
|
16
|
+
this.stateChangeResponseTime = constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME;
|
|
17
|
+
this.statusMsg = constants.DEFAULT_STATUSMSG;
|
|
18
|
+
this.timeout = constants.DEFAULT_TIMEOUT;
|
|
19
|
+
|
|
20
|
+
this.stateChangeResponseTimeHasBeenUpdated = false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
update( entity )
|
|
24
|
+
{
|
|
25
|
+
// Heirarchy Next the Device Properties
|
|
26
|
+
if ( entity.typeIndex != undefined &&
|
|
27
|
+
this.stateChangeResponseTimeHasBeenUpdated == false )
|
|
28
|
+
{
|
|
29
|
+
this.stateChangeResponseTime = CMD4_DEVICE_TYPE_ENUM.properties[ entity.typeIndex ].devicesStateChangeDefaultTime;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// FakeGato Hierarchy
|
|
33
|
+
if ( entity.storage != undefined )
|
|
34
|
+
this.storage = entity.storage;
|
|
35
|
+
if ( entity.storagePath != undefined )
|
|
36
|
+
this.storagePath = entity.storagePath;
|
|
37
|
+
if ( entity.folder != undefined )
|
|
38
|
+
this.folder = entity.folder;
|
|
39
|
+
if ( entity.keyPath != undefined )
|
|
40
|
+
this.keyPath = entity.keyPath;
|
|
41
|
+
|
|
42
|
+
// Heirarchy
|
|
43
|
+
if ( entity.allowTLV8 != undefined )
|
|
44
|
+
this.allowTLV8 = entity.allowTLV8;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if ( entity.debug != undefined )
|
|
48
|
+
this.debug = entity.debug;
|
|
49
|
+
if ( entity.definitions != undefined )
|
|
50
|
+
this.definitions = entity.definitions;
|
|
51
|
+
if ( entity.interval != undefined )
|
|
52
|
+
this.interval = entity.interval;
|
|
53
|
+
if ( entity.outputConstants != undefined )
|
|
54
|
+
this.outputConstants = entity.outputConstants;
|
|
55
|
+
if ( entity.queueTypes != undefined )
|
|
56
|
+
this.queueTypes = entity.queueTypes;
|
|
57
|
+
if ( entity.stateCmd != undefined )
|
|
58
|
+
this.stateCmd = entity.stateCmd;
|
|
59
|
+
if ( entity.state_cmd_prefix != undefined )
|
|
60
|
+
this.state_cmd_prefix = entity.state_cmd_prefix;
|
|
61
|
+
if ( entity.stateCmdSuffix != undefined )
|
|
62
|
+
this.state_cmd_suffix = entity.state_cmd_suffix;
|
|
63
|
+
if ( entity.stateChangeResponseTime != undefined )
|
|
64
|
+
{
|
|
65
|
+
this.stateChangeResponseTimeHasBeenUpdated = true;
|
|
66
|
+
this.stateChangeResponseTime = entity.stateChangeResponseTime;
|
|
67
|
+
}
|
|
68
|
+
if ( entity.statusMsg != undefined )
|
|
69
|
+
this.statusMsg = entity.statusMsg;
|
|
70
|
+
if ( entity.timeout != undefined )
|
|
71
|
+
this.timeout = entity.timeout;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = HV;
|
package/utils/Logger.js
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
let CMD4_ACC_TYPE_ENUM = require( "../lib/CMD4_ACC_TYPE_ENUM" ).CMD4_ACC_TYPE_ENUM;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// Description:
|
|
7
|
+
// Determine if parameter is a Cmd4 accessory characteristic
|
|
8
|
+
//
|
|
9
|
+
// @param type - The characteristic type to check. i.e. "On"
|
|
10
|
+
// @param allowUpper - if upper case allowed to be checked.
|
|
11
|
+
// @returns: { type: The CORRECT characteristic type
|
|
12
|
+
// accTypeEnumIndex: The index of the characteristic
|
|
13
|
+
// } or null
|
|
14
|
+
//
|
|
15
|
+
|
|
16
|
+
function isAccDirective( type, allowUpper = false )
|
|
17
|
+
{
|
|
18
|
+
// For backward compatability of testStoredValueForIndex of FakeGato
|
|
19
|
+
// we must return a null accTypeIndex, which should be checked instead
|
|
20
|
+
// of just rc.
|
|
21
|
+
let defaultRc = { "type": type,
|
|
22
|
+
"accTypeEnumIndex": null
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if ( ! type )
|
|
26
|
+
{
|
|
27
|
+
console.warn( "No parameter passed to isCmd4Directive" );
|
|
28
|
+
return defaultRc;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let accTypeEnumIndex;
|
|
32
|
+
|
|
33
|
+
// We want lower case to be correct
|
|
34
|
+
accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.properties.indexOfEnum( i => i.sche === type )
|
|
35
|
+
if ( accTypeEnumIndex >= 0 )
|
|
36
|
+
return { "type": type,
|
|
37
|
+
"accTypeEnumIndex": accTypeEnumIndex };
|
|
38
|
+
|
|
39
|
+
// Note: There are othes like WiFi ... but nobody uses them thankfully !
|
|
40
|
+
if ( allowUpper == true )
|
|
41
|
+
{
|
|
42
|
+
accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.properties.indexOfEnum( i => i.type === type );
|
|
43
|
+
|
|
44
|
+
// We return the correct lower case
|
|
45
|
+
if ( accTypeEnumIndex >= 0 )
|
|
46
|
+
return { "type": CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].sche,
|
|
47
|
+
"accTypeEnumIndex": accTypeEnumIndex };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return defaultRc;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
module.exports = isAccDirective;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const constants = require( "../cmd4Constants" );
|
|
4
|
+
const lcFirst = require( "./lcFirst" );
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// Description:
|
|
8
|
+
// Determine if parameter is a Cmd4 directive based on it being
|
|
9
|
+
// in the cmd4Constants.
|
|
10
|
+
//
|
|
11
|
+
// @param directive - The Cmd4 Directive to check
|
|
12
|
+
// @param allowUpper - if upper case allowed to be checked.
|
|
13
|
+
// @returns: { key: The CORRECT directive
|
|
14
|
+
// wasLower: If the directive was lowered to make it correct.
|
|
15
|
+
// } or null
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function isCmd4Directive( directive, allowUpper = false )
|
|
19
|
+
{
|
|
20
|
+
if ( ! directive )
|
|
21
|
+
{
|
|
22
|
+
console.warn( "No parameter passed to isCmd4Directive" );
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if ( Object.values( constants ).indexOf( directive ) >= 0 )
|
|
27
|
+
{
|
|
28
|
+
//console.log("isCmd4Directive directive: %s returning: %s", directive, directive );
|
|
29
|
+
return { key: directive,
|
|
30
|
+
wasLower: true };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if ( directive == "UUID" )
|
|
34
|
+
return { key: "uuid",
|
|
35
|
+
wasLower: false };
|
|
36
|
+
|
|
37
|
+
// Note: There are othes like WiFi ... but nobody uses them thankfully !
|
|
38
|
+
if ( allowUpper == true )
|
|
39
|
+
{
|
|
40
|
+
|
|
41
|
+
let lcDirective = lcFirst( directive );
|
|
42
|
+
if ( Object.values( constants ).indexOf( lcDirective ) >= 0 )
|
|
43
|
+
{
|
|
44
|
+
//console.log("isCmd4Directive directive: %s returning: %s", directive, lcDirective );
|
|
45
|
+
return { key: lcDirective,
|
|
46
|
+
wasLower: false };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//console.log("isCmd4Directive directive: %s returning null", directive );
|
|
51
|
+
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
module.exports = isCmd4Directive;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
let ucFirst = require( "../utils/ucFirst" );
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
let CMD4_DEVICE_TYPE_ENUM = require( "../lib/CMD4_DEVICE_TYPE_ENUM" ).CMD4_DEVICE_TYPE_ENUM;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// Description:
|
|
10
|
+
// Determine if type is a Cmd4 device based CMD4_DEVICE_TYPE_ENUM.deviceName
|
|
11
|
+
//
|
|
12
|
+
// @param deviceName - The device name to check. i.e. "Switch"
|
|
13
|
+
// @param allowUpper - if upper case allowed to be checked.
|
|
14
|
+
// @returns: { deviceName: The CORRECT device name
|
|
15
|
+
// devEnumIndex: The index of the characteristic
|
|
16
|
+
// } or null
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
function isDevDirective( deviceName, allowUpper = false )
|
|
20
|
+
{
|
|
21
|
+
// We return similiar to isAccDirective
|
|
22
|
+
// We must return a null devTypeIndex, which should be checked instead
|
|
23
|
+
// of just rc, like isAccDirective
|
|
24
|
+
let defaultRc = { "deviceName": deviceName,
|
|
25
|
+
"devEnumIndex": null
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if ( ! deviceName )
|
|
29
|
+
{
|
|
30
|
+
console.warn( "No parameter passed to isDevDirective" );
|
|
31
|
+
return defaultRc;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let devEnumIndex;
|
|
35
|
+
|
|
36
|
+
// We want lower case to be correct
|
|
37
|
+
devEnumIndex = CMD4_DEVICE_TYPE_ENUM.indexOfEnum( deviceName );
|
|
38
|
+
if ( devEnumIndex >= 0 )
|
|
39
|
+
return { "deviceName": deviceName,
|
|
40
|
+
"devEnumIndex": devEnumIndex };
|
|
41
|
+
|
|
42
|
+
// Note: There are othes like WiFi ... but nobody uses them thankfully !
|
|
43
|
+
if ( allowUpper == true )
|
|
44
|
+
{
|
|
45
|
+
let ucDeviceName = ucFirst( deviceName );
|
|
46
|
+
devEnumIndex = CMD4_DEVICE_TYPE_ENUM.indexOfEnum( ucDeviceName );
|
|
47
|
+
|
|
48
|
+
// We return the correct upper case
|
|
49
|
+
if ( devEnumIndex >= 0 )
|
|
50
|
+
return { "deviceName": CMD4_DEVICE_TYPE_ENUM.devEnumIndexToC( devEnumIndex ),
|
|
51
|
+
"devEnumIndex": devEnumIndex };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return defaultRc;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
module.exports = isDevDirective;
|