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
package/Cmd4Accessory.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const moment = require( "moment" );
|
|
4
|
-
const fs = require( "fs" );
|
|
5
|
-
const commandExistsSync = require( "command-exists" ).sync;
|
|
6
4
|
|
|
7
5
|
// Settings, Globals and Constants
|
|
8
6
|
let settings = require( "./cmd4Settings" );
|
|
9
7
|
const constants = require( "./cmd4Constants" );
|
|
10
8
|
|
|
11
|
-
var cmd4Dbg = settings.cmd4Dbg;
|
|
12
|
-
|
|
13
|
-
|
|
14
9
|
let Logger = require( "./utils/Logger" );
|
|
15
10
|
const { getAccessoryName, getAccessoryDisplayName
|
|
16
11
|
} = require( "./utils/getAccessoryNameFunctions" );
|
|
17
12
|
let getAccessoryUUID = require( "./utils/getAccessoryUUID" );
|
|
18
13
|
const { addQueue, parseAddQueueTypes, queueExists } = require( "./Cmd4PriorityPollingQueue" );
|
|
19
14
|
|
|
15
|
+
// Hierarchy variables
|
|
16
|
+
let HV = require( "./utils/HV" );
|
|
20
17
|
|
|
21
18
|
let createAccessorysInformationService = require( "./utils/createAccessorysInformationService" );
|
|
22
19
|
|
|
23
|
-
let ucFirst = require( "./utils/ucFirst" );
|
|
24
20
|
let lcFirst = require( "./utils/lcFirst" );
|
|
25
21
|
let trueTypeOf = require( "./utils/trueTypeOf" );
|
|
26
22
|
|
|
@@ -34,6 +30,9 @@ var { transposeConstantToValidValue,
|
|
|
34
30
|
} = require( "./utils/transposeCMD4Props" );
|
|
35
31
|
|
|
36
32
|
let isJSON = require( "./utils/isJSON" );
|
|
33
|
+
let isCmd4Directive = require( "./utils/isCmd4Directive" );
|
|
34
|
+
let isAccDirective = require( "./utils/isAccDirective" );
|
|
35
|
+
let isDevDirective = require( "./utils/isDevDirective" );
|
|
37
36
|
|
|
38
37
|
// Pretty Colors
|
|
39
38
|
var chalk = require( "chalk" );
|
|
@@ -42,12 +41,27 @@ var chalk = require( "chalk" );
|
|
|
42
41
|
let CMD4_ACC_TYPE_ENUM = require( "./lib/CMD4_ACC_TYPE_ENUM" ).CMD4_ACC_TYPE_ENUM;
|
|
43
42
|
let CMD4_DEVICE_TYPE_ENUM = require( "./lib/CMD4_DEVICE_TYPE_ENUM" ).CMD4_DEVICE_TYPE_ENUM;
|
|
44
43
|
|
|
44
|
+
const Cmd4Storage = require( "./utils/Cmd4Storage" );
|
|
45
|
+
|
|
45
46
|
let FakeGatoHistoryService = null;
|
|
46
47
|
|
|
47
48
|
// Only one TV is allowed per bridge. Circumvented by
|
|
48
49
|
// publishing the TV externally.
|
|
49
50
|
let numberOfTVsPerBridge = 0;
|
|
50
51
|
|
|
52
|
+
// Array Remove
|
|
53
|
+
function removeFromArray( arr, val )
|
|
54
|
+
{
|
|
55
|
+
for (let i = arr.length - 1; i >= 0; i--)
|
|
56
|
+
{
|
|
57
|
+
if (arr[i] === val)
|
|
58
|
+
{
|
|
59
|
+
// console.log("Removing %s", val );
|
|
60
|
+
arr.splice(i, 1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return arr;
|
|
64
|
+
}
|
|
51
65
|
|
|
52
66
|
// Accessory definitions - THE GOOD STUFF STARTs HERE
|
|
53
67
|
//
|
|
@@ -75,22 +89,21 @@ class Cmd4Accessory
|
|
|
75
89
|
this.log = log;
|
|
76
90
|
|
|
77
91
|
// Carry the debug flag from the platform
|
|
78
|
-
cmd4Dbg = log.debugEnabled;
|
|
92
|
+
settings.cmd4Dbg = log.debugEnabled;
|
|
79
93
|
}
|
|
80
94
|
else
|
|
81
95
|
{
|
|
82
96
|
this.log = new Logger( );
|
|
83
97
|
|
|
84
98
|
if ( config[ constants.DEBUG ] == true ||
|
|
85
|
-
config[
|
|
99
|
+
config[ "Debug" ] == true ||
|
|
86
100
|
process.env.DEBUG == settings.PLATFORM_NAME )
|
|
87
101
|
{
|
|
88
102
|
settings.cmd4Dbg = true;
|
|
89
|
-
cmd4Dbg = true;
|
|
90
103
|
}
|
|
91
104
|
|
|
92
105
|
}
|
|
93
|
-
this.log.setDebugEnabled( cmd4Dbg );
|
|
106
|
+
this.log.setDebugEnabled( settings.cmd4Dbg );
|
|
94
107
|
|
|
95
108
|
this.config = config;
|
|
96
109
|
this.api = api;
|
|
@@ -107,7 +120,7 @@ class Cmd4Accessory
|
|
|
107
120
|
|
|
108
121
|
let typeMsg = [ "", "Linked ", "Added " ][ this.LEVEL ] || "";
|
|
109
122
|
|
|
110
|
-
if ( cmd4Dbg ) log.debug( chalk.blue ( `Creating ${ typeMsg }${ this.CMD4 } Accessory type for : ${ config.displayName } LEVEL: ${ this.LEVEL }` ) );
|
|
123
|
+
if ( settings.cmd4Dbg ) log.debug( chalk.blue ( `Creating ${ typeMsg }${ this.CMD4 } Accessory type for : ${ config.displayName } LEVEL: ${ this.LEVEL }` ) );
|
|
111
124
|
|
|
112
125
|
this.services = [ ];
|
|
113
126
|
this.linkedAccessories = [ ];
|
|
@@ -127,30 +140,16 @@ class Cmd4Accessory
|
|
|
127
140
|
this.displayName = getAccessoryDisplayName( this.config );
|
|
128
141
|
|
|
129
142
|
|
|
130
|
-
// Bring the parent config variables forward.
|
|
131
|
-
// If they do not exist, they would still be undefined.
|
|
132
|
-
// For stateChangeResponseTime, if not the parentInfo, then
|
|
133
|
-
// it gets defined by the accessoryType devicesStateChangeDefaultTime
|
|
134
|
-
if ( parentInfo && parentInfo.stateChangeResponseTime )
|
|
135
|
-
this.stateChangeResponseTime = parentInfo.stateChangeResponseTime;
|
|
136
|
-
|
|
137
|
-
// Direct if Constants should be sent or their value.
|
|
138
|
-
this.outputConstants = ( parentInfo && parentInfo.outputConstants ) ? parentInfo.outputConstants : constants.DEFAULT_OUTPUTCONSTANTS;
|
|
139
|
-
|
|
140
|
-
this.interval = ( parentInfo && parentInfo.interval ) ? parentInfo.interval : constants.DEFAULT_INTERVAL;
|
|
141
|
-
this.timeout = ( parentInfo && parentInfo.timeout ) ? parentInfo.timeout : constants.DEFAULT_TIMEOUT;
|
|
142
|
-
this.statusMsg = ( parentInfo && parentInfo.statusMsg ) ? parentInfo.statusMsg : constants.DEFAULT_STATUSMSG;
|
|
143
143
|
// Everything that needs to talk to the device now goes through the queue
|
|
144
144
|
this.queue = null;
|
|
145
145
|
|
|
146
|
-
// undefined is acceptable. It can be overwritten by parseConfig
|
|
147
|
-
this.state_cmd = parentInfo && parentInfo.state_cmd;
|
|
148
|
-
this.state_cmd_prefix = parentInfo && parentInfo.state_cmd_prefix;
|
|
149
|
-
this.state_cmd_suffix = parentInfo && parentInfo.state_cmd_suffix;
|
|
150
146
|
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
// Use the Hierarhy variables from the parent, if not create it.
|
|
148
|
+
this.hV = new HV( );
|
|
149
|
+
if ( parentInfo && parentInfo.hV )
|
|
150
|
+
{
|
|
151
|
+
this.hV.update( parentInfo.hV );
|
|
152
|
+
}
|
|
154
153
|
|
|
155
154
|
// In case it is not passed in.
|
|
156
155
|
if ( STORED_DATA_ARRAY == undefined || STORED_DATA_ARRAY == null )
|
|
@@ -168,27 +167,72 @@ class Cmd4Accessory
|
|
|
168
167
|
// generate a unique id for the accessory this should be generated from
|
|
169
168
|
// something globally unique, but constant, for example, the device serial
|
|
170
169
|
// number or MAC address.
|
|
171
|
-
let
|
|
170
|
+
let uuid = getAccessoryUUID( config, this.api.hap.uuid );
|
|
171
|
+
|
|
172
|
+
// Handle case change
|
|
173
|
+
let existingDataU = this.STORED_DATA_ARRAY.find( data => data[ "UUID" ] === uuid );
|
|
174
|
+
if ( existingDataU )
|
|
175
|
+
{
|
|
176
|
+
//Z this.log.info( chalk.blue ( `THIS MSG TO BE REMOVED. RENAMING UUID for: ${ config.displayName } LEVEL: ${ this.LEVEL }` ) );
|
|
177
|
+
existingDataU[ "uuid" ] = existingDataU[ "UUID" ];
|
|
178
|
+
delete existingDataU[ "UUID" ];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// NOTE: We saved the data via lower case uuid.
|
|
182
|
+
let existingData = this.STORED_DATA_ARRAY.find( data => data[ constants.UUID ] === uuid );
|
|
172
183
|
|
|
173
|
-
let existingData = this.STORED_DATA_ARRAY.find( data => data[ constants.UUID ] === UUID );
|
|
174
184
|
if ( existingData )
|
|
175
185
|
{
|
|
176
|
-
|
|
177
|
-
this.
|
|
186
|
+
//Z this.log.info( chalk.blue ( `THIS MSG TO BE REMOVED. Found existing data for: ${ this.displayName }` ) );
|
|
187
|
+
if ( settings.cmd4Dbg ) this.log.debug(`Cmd4Accessory: found existingData for ${ this.displayName }` );
|
|
188
|
+
if ( existingData.storedValuesPerCharacteristic )
|
|
189
|
+
{
|
|
190
|
+
//Z this.log.info( chalk.blue ( `THIS MSG TO BE REMOVED. Found old storedValuesPerCharacteristic for: ${ this.displayName }` ) );
|
|
191
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Upgrading to cmd4Storage` );
|
|
192
|
+
this.cmd4Storage = new Cmd4Storage( this.log, existingData.storedValuesPerCharacteristic );
|
|
193
|
+
this.STORED_DATA_ARRAY.push( { [ constants.UUID ]: uuid,
|
|
194
|
+
[ constants.CMD4_STORAGE_lv ]: this.cmd4Storage
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
//this.STORED_DATA_ARRAY.remove( existingData );
|
|
198
|
+
removeFromArray( this.STORED_DATA_ARRAY, existingData );
|
|
199
|
+
} else if ( existingData.cmd4Storage )
|
|
200
|
+
{
|
|
201
|
+
//Z this.log.info( chalk.blue ( `THIS MSG TO BE REMOVED. Using existing cmd4Storage for: ${ this.displayName }` ) );
|
|
202
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Using existing cmd4Storage` );
|
|
203
|
+
this.cmd4Storage = new Cmd4Storage( this.log, existingData.cmd4Storage );
|
|
204
|
+
this.STORED_DATA_ARRAY.push( { [ constants.UUID ]: uuid,
|
|
205
|
+
[ constants.CMD4_STORAGE_lv ]: this.cmd4Storage
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
//this.STORED_DATA_ARRAY.remove( existingData );
|
|
209
|
+
removeFromArray( this.STORED_DATA_ARRAY, existingData );
|
|
210
|
+
} else {
|
|
211
|
+
//Z log.info( chalk.blue ( `THIS MSG TO BE REMOVED. Unexpected empty cmd4Storage for: ${ this.displayName }` ) );
|
|
212
|
+
this.log.warn( `Unexpected empty cmd4Storage` );
|
|
213
|
+
this.cmd4Storage = new Cmd4Storage( this.log );
|
|
214
|
+
this.STORED_DATA_ARRAY.push( { [ constants.UUID ]: uuid,
|
|
215
|
+
[ constants.CMD4_STORAGE_lv ]: this.cmd4Storage
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
//this.STORED_DATA_ARRAY.remove( existingData );
|
|
219
|
+
removeFromArray( this.STORED_DATA_ARRAY, existingData );
|
|
220
|
+
}
|
|
178
221
|
|
|
179
222
|
// Do not read stored values from config.json
|
|
180
223
|
parseConfigShouldUseCharacteristicValues = false;
|
|
181
224
|
} else
|
|
182
225
|
{
|
|
183
|
-
|
|
226
|
+
//Z log.info( chalk.blue ( `THIS MSG TO BE REMOVED. Creating new cmd4Storage for: ${ this.displayName }` ) );
|
|
227
|
+
if ( settings.cmd4Dbg ) this.log.debug(`Cmd4Accessory: creating new cmd4Storage for ${ this.displayName }` );
|
|
184
228
|
// Instead of local variables for every characteristic, create an array to
|
|
185
229
|
// hold values for all characteristics based on the size of all possible
|
|
186
230
|
// characteristics. Placing them in .config will make them be cached over
|
|
187
231
|
// restarts.
|
|
188
|
-
this.
|
|
232
|
+
this.cmd4Storage = new Cmd4Storage( this.log );
|
|
189
233
|
|
|
190
|
-
this.STORED_DATA_ARRAY.push( { [ constants.UUID ]:
|
|
191
|
-
[ constants.
|
|
234
|
+
this.STORED_DATA_ARRAY.push( { [ constants.UUID ]: uuid,
|
|
235
|
+
[ constants.CMD4_STORAGE_lv ]: this.cmd4Storage
|
|
192
236
|
}
|
|
193
237
|
);
|
|
194
238
|
}
|
|
@@ -204,22 +248,20 @@ class Cmd4Accessory
|
|
|
204
248
|
if ( FakeGatoHistoryService == null )
|
|
205
249
|
FakeGatoHistoryService = require( "fakegato-history" )( api );
|
|
206
250
|
|
|
207
|
-
// Fakegato-history definitions from parent, if any.
|
|
208
|
-
this.storage = parentInfo && parentInfo.storage;
|
|
209
|
-
this.storagePath = parentInfo && parentInfo.storagePath;
|
|
210
|
-
this.folder = parentInfo && parentInfo.folder;
|
|
211
|
-
this.keyPath = parentInfo && parentInfo.keyPath;
|
|
212
|
-
|
|
213
|
-
|
|
214
251
|
// Get the supplied values from the accessory config.
|
|
215
252
|
this.parseConfig( this.config, parseConfigShouldUseCharacteristicValues );
|
|
216
253
|
|
|
254
|
+
// Update the accessories namespace for stored variables
|
|
255
|
+
// like timeout, stateChangeResponseTime ... As it may require
|
|
256
|
+
// changes from parseConfig.
|
|
257
|
+
this.hV.update( this );
|
|
258
|
+
|
|
217
259
|
// Add any required characteristics of a device that are missing from
|
|
218
260
|
// a users config.json file.
|
|
219
261
|
this.addRequiredCharacteristicStoredValues( );
|
|
220
262
|
|
|
221
263
|
// The accessory cannot have the same UUID as any other
|
|
222
|
-
checkAccessoryForDuplicateUUID( this, this.
|
|
264
|
+
checkAccessoryForDuplicateUUID( this, this.uuid );
|
|
223
265
|
|
|
224
266
|
// The default response time is in seconds
|
|
225
267
|
if ( ! this.stateChangeResponseTime )
|
|
@@ -258,12 +300,12 @@ class Cmd4Accessory
|
|
|
258
300
|
// This can be done for only LEVEL 0 accessories and itself
|
|
259
301
|
if ( this.LEVEL == 0 )
|
|
260
302
|
{
|
|
261
|
-
// if ( cmd4Dbg ) log.debug( "CMD4=%s LEVEL=%s for %s", accessory.CMD4, accessory.LEVEL, accessory.displayName );
|
|
303
|
+
// if ( settings.cmd4Dbg ) log.debug( "CMD4=%s LEVEL=%s for %s", accessory.CMD4, accessory.LEVEL, accessory.displayName );
|
|
262
304
|
// The linked accessory children are at different levels of recursion, so only
|
|
263
305
|
// allow what is posssible.
|
|
264
306
|
if ( this.linkedAccessories && this.linkedAccessories.length > 0 )
|
|
265
307
|
{
|
|
266
|
-
if ( cmd4Dbg ) this.log.debug( `Setting up which characteristics will be polled for Linked Accessories of ${ this.displayName }` );
|
|
308
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Setting up which characteristics will be polled for Linked Accessories of ${ this.displayName }` );
|
|
267
309
|
|
|
268
310
|
this.linkedAccessories.forEach( ( linkedAccessory ) =>
|
|
269
311
|
{
|
|
@@ -277,7 +319,7 @@ class Cmd4Accessory
|
|
|
277
319
|
// The Television Speaker Platform Example
|
|
278
320
|
if ( this.accessories && this.accessories.length > 0 )
|
|
279
321
|
{
|
|
280
|
-
if ( cmd4Dbg ) this.log.debug( `Setting up which characteristics will be polled for Added Accessories of ${ this.displayName }` );
|
|
322
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Setting up which characteristics will be polled for Added Accessories of ${ this.displayName }` );
|
|
281
323
|
this.accessories.forEach( ( addedAccessory ) =>
|
|
282
324
|
{
|
|
283
325
|
if ( addedAccessory.polling )
|
|
@@ -287,7 +329,7 @@ class Cmd4Accessory
|
|
|
287
329
|
});
|
|
288
330
|
}
|
|
289
331
|
|
|
290
|
-
if ( cmd4Dbg ) this.log.debug( `Setting up which characteristics will be polled for ${ this.displayName }` );
|
|
332
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Setting up which characteristics will be polled for ${ this.displayName }` );
|
|
291
333
|
this.determineCharacteristicsToPollForAccessory( this );
|
|
292
334
|
}
|
|
293
335
|
|
|
@@ -296,7 +338,7 @@ class Cmd4Accessory
|
|
|
296
338
|
// polling started. Otherwise the platform will have to do this.
|
|
297
339
|
if ( this.CMD4 == constants.STANDALONE && this.LEVEL == 0 )
|
|
298
340
|
{
|
|
299
|
-
if ( cmd4Dbg ) log.debug( `Creating Standalone service for: ${ this.displayName }` );
|
|
341
|
+
if ( settings.cmd4Dbg ) log.debug( `Creating Standalone service for: ${ this.displayName }` );
|
|
300
342
|
this.createServicesForStandaloneAccessoryAndItsChildren( this )
|
|
301
343
|
}
|
|
302
344
|
|
|
@@ -311,41 +353,13 @@ class Cmd4Accessory
|
|
|
311
353
|
{
|
|
312
354
|
//if ( this.services )
|
|
313
355
|
//{
|
|
314
|
-
// if ( cmd4Dbg ) this.log.debug( Fg.Red + "ZZZZ Returning:%s number of services for:%s" + Fg.Rm, this.services.length, this.displayName );
|
|
356
|
+
// if ( settings.cmd4Dbg ) this.log.debug( Fg.Red + "ZZZZ Returning:%s number of services for:%s" + Fg.Rm, this.services.length, this.displayName );
|
|
315
357
|
//} else {
|
|
316
|
-
// if ( cmd4Dbg ) this.log.debug( Fg.Red + "ZZZZ Returning this.services:%s for:%s" + Fg.Rm, this.services, this.displayName );
|
|
358
|
+
// if ( settings.cmd4Dbg ) this.log.debug( Fg.Red + "ZZZZ Returning this.services:%s for:%s" + Fg.Rm, this.services, this.displayName );
|
|
317
359
|
//}
|
|
318
360
|
return this.services;
|
|
319
361
|
}
|
|
320
362
|
|
|
321
|
-
setStoredValueForIndex( accTypeEnumIndex, value )
|
|
322
|
-
{
|
|
323
|
-
if ( accTypeEnumIndex < 0 || accTypeEnumIndex >= CMD4_ACC_TYPE_ENUM.EOL )
|
|
324
|
-
throw new Error( `setStoredValue - Characteristic index: ${ accTypeEnumIndex } not between 0 and ${ CMD4_ACC_TYPE_ENUM.EOL } for "${ this.displayName }"\nCheck your config.json file for unknown characteristic.` );
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
this.storedValuesPerCharacteristic[ accTypeEnumIndex ] = value;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
getStoredValueForIndex( accTypeEnumIndex )
|
|
331
|
-
{
|
|
332
|
-
if ( accTypeEnumIndex < 0 || accTypeEnumIndex >= CMD4_ACC_TYPE_ENUM.EOL )
|
|
333
|
-
throw new Error( `getStoredValue - Characteristic index: ${ accTypeEnumIndex } not between 0 and ${ CMD4_ACC_TYPE_ENUM.EOL } for "${ this.displayName }"\nCheck your config.json file for unknown characteristic.` );
|
|
334
|
-
|
|
335
|
-
return this.storedValuesPerCharacteristic[ accTypeEnumIndex ];
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// Unlike get/set, testStoredValueForIndex does not call process.exit,
|
|
339
|
-
// but undefined for an illegal range, in the case that rogue runtime data
|
|
340
|
-
// dies not take down CMD4.
|
|
341
|
-
testStoredValueForIndex( accTypeEnumIndex )
|
|
342
|
-
{
|
|
343
|
-
if ( accTypeEnumIndex < 0 || accTypeEnumIndex > CMD4_ACC_TYPE_ENUM.EOL )
|
|
344
|
-
return undefined;
|
|
345
|
-
|
|
346
|
-
return this.storedValuesPerCharacteristic[ accTypeEnumIndex ];
|
|
347
|
-
}
|
|
348
|
-
|
|
349
363
|
// Any required characteristic of an accessory that is not in the accessories
|
|
350
364
|
// config will be added later by the existance of its stored value, so
|
|
351
365
|
// find the missing characteristics and add their value s here.
|
|
@@ -366,11 +380,11 @@ class Cmd4Accessory
|
|
|
366
380
|
let format = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].props.format;
|
|
367
381
|
|
|
368
382
|
// No matter what, remove it
|
|
369
|
-
if ( format == this.api.hap.Characteristic.Formats.TLV8 && this.allowTLV8 == false )
|
|
383
|
+
if ( format == this.api.hap.Characteristic.Formats.TLV8 && this.hV.allowTLV8 == false )
|
|
370
384
|
{
|
|
371
|
-
if ( this.getStoredValueForIndex( accTypeEnumIndex ) != null )
|
|
385
|
+
if ( this.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex ) != null )
|
|
372
386
|
{
|
|
373
|
-
this.setStoredValueForIndex( accTypeEnumIndex, null );
|
|
387
|
+
this.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, null );
|
|
374
388
|
|
|
375
389
|
this.log.warn( `****** Removing TLV8 required characteristic: ${ CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type }` );
|
|
376
390
|
}
|
|
@@ -378,7 +392,7 @@ class Cmd4Accessory
|
|
|
378
392
|
}
|
|
379
393
|
|
|
380
394
|
// if it is required and not stored, add it
|
|
381
|
-
if ( requiredIndex != -1 && this.getStoredValueForIndex( accTypeEnumIndex ) == null )
|
|
395
|
+
if ( requiredIndex != -1 && this.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex ) == null )
|
|
382
396
|
{
|
|
383
397
|
this.log.warn( `**** Adding required characteristic ${ CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type } for ${ this.displayName }` );
|
|
384
398
|
this.log.warn( `Not defining a required characteristic can be problematic` );
|
|
@@ -390,9 +404,9 @@ class Cmd4Accessory
|
|
|
390
404
|
if ( accTypeEnumIndex == CMD4_ACC_TYPE_ENUM.ConfiguredName )
|
|
391
405
|
defaultValue = getAccessoryName( this.config );
|
|
392
406
|
|
|
393
|
-
if ( cmd4Dbg ) this.log.debug( `*****Adding default value ${ defaultValue } for: ${ this.displayName }` );
|
|
407
|
+
if ( settings.cmd4Dbg ) this.log.debug( `*****Adding default value ${ defaultValue } for: ${ this.displayName }` );
|
|
394
408
|
|
|
395
|
-
this.setStoredValueForIndex( accTypeEnumIndex, defaultValue );
|
|
409
|
+
this.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, defaultValue );
|
|
396
410
|
}
|
|
397
411
|
}
|
|
398
412
|
}
|
|
@@ -402,7 +416,7 @@ class Cmd4Accessory
|
|
|
402
416
|
if ( trueTypeOf( pollingConfig ) != Array )
|
|
403
417
|
return;
|
|
404
418
|
|
|
405
|
-
if ( cmd4Dbg ) this.log.debug( `Checking ${ this.displayName } for polling of unset characteristics.` );
|
|
419
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Checking ${ this.displayName } for polling of unset characteristics.` );
|
|
406
420
|
|
|
407
421
|
pollingConfig.forEach( ( jsonPollingConfig ) =>
|
|
408
422
|
{
|
|
@@ -413,10 +427,29 @@ class Cmd4Accessory
|
|
|
413
427
|
|
|
414
428
|
for ( key in jsonPollingConfig )
|
|
415
429
|
{
|
|
416
|
-
let ucKey = ucFirst( key );
|
|
417
430
|
value = jsonPollingConfig[ key ];
|
|
418
431
|
|
|
419
|
-
|
|
432
|
+
let rcDirective = isCmd4Directive( key );
|
|
433
|
+
if ( rcDirective == null )
|
|
434
|
+
{
|
|
435
|
+
rcDirective = isCmd4Directive( key, true );
|
|
436
|
+
if ( rcDirective != null )
|
|
437
|
+
{
|
|
438
|
+
// warn now
|
|
439
|
+
this.log.warn( `The config.json Cmd4 Polling Directive: ${ key } is Capitalized. It should be: ${ rcDirective.key }. In the near future this will be an error for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
|
|
440
|
+
// create the proper lower case value
|
|
441
|
+
jsonPollingConfig[ rcDirective.key ] = value;
|
|
442
|
+
// delete the upper case value
|
|
443
|
+
delete jsonPollingConfig[ key ];
|
|
444
|
+
|
|
445
|
+
//set the key
|
|
446
|
+
key = rcDirective.key;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
// Not finding the key is not an error as it could be a Characteristic
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
switch ( key )
|
|
420
453
|
{
|
|
421
454
|
case constants.TIMEOUT:
|
|
422
455
|
case constants.INTERVAL:
|
|
@@ -435,13 +468,20 @@ class Cmd4Accessory
|
|
|
435
468
|
{
|
|
436
469
|
//2 checkPollingOfUnsetCharacteristics
|
|
437
470
|
valueToStore = null;
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
if ( accTypeEnumIndex
|
|
441
|
-
|
|
471
|
+
|
|
472
|
+
let rcDirective = isAccDirective( value, false );
|
|
473
|
+
if ( rcDirective.accTypeEnumIndex == null )
|
|
474
|
+
{
|
|
475
|
+
rcDirective = isAccDirective( value, true );
|
|
476
|
+
if ( rcDirective.accTypeEnumIndex == null )
|
|
477
|
+
throw new Error( `No such polling characteristic: "${ value }" for: "${ this.displayName }".` );
|
|
478
|
+
|
|
479
|
+
this.log.warn( `The config.json Polling characteristic: ${ value } is Capitalized it should be: ${ rcDirective.type }. In the near future this will be an Error so that Cmd4 can use homebridge-ui.\nTo remove this Warning, Please fix your config.json.` );
|
|
480
|
+
}
|
|
481
|
+
accTypeEnumIndex = rcDirective.accTypeEnumIndex;
|
|
442
482
|
|
|
443
483
|
// We can do this as this is a new way to do things.
|
|
444
|
-
let storedValue = this.getStoredValueForIndex( accTypeEnumIndex );
|
|
484
|
+
let storedValue = this.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex );
|
|
445
485
|
if ( storedValue == undefined )
|
|
446
486
|
throw new Error( `Polling for: "${ value }" requested, but characteristic is not in your config.json file for: "${ this.displayName }".` );
|
|
447
487
|
|
|
@@ -452,10 +492,11 @@ class Cmd4Accessory
|
|
|
452
492
|
default:
|
|
453
493
|
{
|
|
454
494
|
// Is this still useful?
|
|
455
|
-
accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.
|
|
495
|
+
accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.indexOfEnum( key );
|
|
456
496
|
|
|
457
497
|
if ( accTypeEnumIndex < 0 )
|
|
458
|
-
throw new Error( `OOPS: "${ key }" not found while parsing for characteristic polling. There something wrong with your config.json file?` );
|
|
498
|
+
// throw new Error( `OOPS: "${ key }" not found while parsing for characteristic polling. There something wrong with your config.json file?` );
|
|
499
|
+
throw new Error( `OOPS: "${ key }" not found while parsing for characteristic polling of "${ this.displayName }". There something wrong with your config.json file?` );
|
|
459
500
|
|
|
460
501
|
valueToStore = value;
|
|
461
502
|
}
|
|
@@ -465,23 +506,23 @@ class Cmd4Accessory
|
|
|
465
506
|
if ( accTypeEnumIndex == -1 )
|
|
466
507
|
throw new Error( `No characteristic found while parsing for characteristic polling of: "${ this.displayName }". There something wrong with your config.json file?` );
|
|
467
508
|
|
|
468
|
-
if ( this.getStoredValueForIndex( accTypeEnumIndex ) == undefined )
|
|
509
|
+
if ( this.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex ) == undefined )
|
|
469
510
|
{
|
|
470
511
|
this.log.warn( `Polling for: "${ key }" requested, but characteristic` );
|
|
471
512
|
this.log.warn( `is not in your config.json file for: ${ this.displayName }` );
|
|
472
513
|
this.log.warn( `This will be an error in the future.` );
|
|
473
514
|
}
|
|
474
515
|
|
|
475
|
-
this.setStoredValueForIndex( accTypeEnumIndex, valueToStore );
|
|
516
|
+
this.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, valueToStore );
|
|
476
517
|
});
|
|
477
518
|
}
|
|
478
519
|
|
|
479
520
|
createServicesForStandaloneAccessoryAndItsChildren( accessory )
|
|
480
521
|
{
|
|
481
|
-
if ( cmd4Dbg ) accessory.log.debug( chalk.blue( `createServicesFor${ this.CMD4 }AccessoryAndItsChildren` ) );
|
|
522
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( chalk.blue( `createServicesFor${ this.CMD4 }AccessoryAndItsChildren` ) );
|
|
482
523
|
if ( accessory.ServiceCreated == true )
|
|
483
524
|
{
|
|
484
|
-
if ( cmd4Dbg ) accessory.log.debug( chalk.red( `SERVICES ALREADY CREATED FOR ${ this.displayName } ${ this.CMD4 } ${ this.LEVEL }` ) );
|
|
525
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( chalk.red( `SERVICES ALREADY CREATED FOR ${ this.displayName } ${ this.CMD4 } ${ this.LEVEL }` ) );
|
|
485
526
|
return;
|
|
486
527
|
} else {
|
|
487
528
|
accessory.ServiceCreated = true;
|
|
@@ -497,7 +538,7 @@ class Cmd4Accessory
|
|
|
497
538
|
// Create the accessory's service
|
|
498
539
|
accessory.service = new properties.service( accessory.name, accessory.subType )
|
|
499
540
|
|
|
500
|
-
if ( cmd4Dbg ) accessory.log.debug( `Creating information service for standalone accessory: ${ accessory.displayName }` );
|
|
541
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( `Creating information service for standalone accessory: ${ accessory.displayName }` );
|
|
501
542
|
|
|
502
543
|
|
|
503
544
|
// Create the Standalone accessory's information service.
|
|
@@ -512,16 +553,16 @@ class Cmd4Accessory
|
|
|
512
553
|
|
|
513
554
|
// Standalone Step 4.
|
|
514
555
|
// const hdmi1InputService = this.tvAccessory.addService( this.Service.InputSource, `hdmi1', 'HDMI 1' );
|
|
515
|
-
if ( cmd4Dbg ) accessory.log.debug( `Standalone Step 4. linkedAccessory( ${ accessory.displayName } ).service = new Service( ${ linkedAccessory.name }, ${ linkedAccessory.subType } )` );
|
|
556
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( `Standalone Step 4. linkedAccessory( ${ accessory.displayName } ).service = new Service( ${ linkedAccessory.name }, ${ linkedAccessory.subType } )` );
|
|
516
557
|
linkedAccessory.service = new properties.service( linkedAccessory.name, linkedAccessory.subType )
|
|
517
558
|
accessory.services.push( linkedAccessory.service );
|
|
518
559
|
|
|
519
560
|
// Hmmm Double Check this !!
|
|
520
561
|
// Create Information Service
|
|
521
|
-
//if ( cmd4Dbg ) linkedAccessory.log.debug( "Creating information service for linkedAccessory:%s", linkedAccessory.displayName );
|
|
562
|
+
//if ( settings.cmd4Dbg ) linkedAccessory.log.debug( "Creating information service for linkedAccessory:%s", linkedAccessory.displayName );
|
|
522
563
|
//createAccessorysInformationService( linkedAccessory );
|
|
523
564
|
|
|
524
|
-
if ( cmd4Dbg ) accessory.log.debug( `Standalone Step 5. ${ accessory.displayName }.service.addLinkedService( ${ linkedAccessory.displayName }.service` );
|
|
565
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( `Standalone Step 5. ${ accessory.displayName }.service.addLinkedService( ${ linkedAccessory.displayName }.service` );
|
|
525
566
|
// Standalone Step 5.
|
|
526
567
|
// tvService.addLinkedService( hdmi1InputService ); // link to tv service
|
|
527
568
|
accessory.service.addLinkedService( linkedAccessory.service );
|
|
@@ -560,15 +601,15 @@ class Cmd4Accessory
|
|
|
560
601
|
{
|
|
561
602
|
let self = this;
|
|
562
603
|
|
|
563
|
-
if ( self.statusMsg == "TRUE" )
|
|
604
|
+
if ( self.hV.statusMsg == "TRUE" )
|
|
564
605
|
self.log.info( chalk.blue( `Setting (Cached) ${ self.displayName } ${ characteristicString }` ) + ` ${ value }` );
|
|
565
606
|
else
|
|
566
|
-
if ( cmd4Dbg ) self.log.debug( `setCachedvalue accTypeEnumIndex:( ${ accTypeEnumIndex } )-"${ characteristicString }" function for: ${ self.displayName } value: ${ value }` );
|
|
607
|
+
if ( settings.cmd4Dbg ) self.log.debug( `setCachedvalue accTypeEnumIndex:( ${ accTypeEnumIndex } )-"${ characteristicString }" function for: ${ self.displayName } value: ${ value }` );
|
|
567
608
|
|
|
568
609
|
|
|
569
610
|
// Save the cached value.
|
|
570
611
|
// Fakegato does not need to be updated as that is done on a "Get".
|
|
571
|
-
self.setStoredValueForIndex( accTypeEnumIndex, value );
|
|
612
|
+
self.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, value );
|
|
572
613
|
|
|
573
614
|
let relatedCurrentAccTypeEnumIndex = this.getDevicesRelatedCurrentAccTypeEnumIndex( accTypeEnumIndex );
|
|
574
615
|
|
|
@@ -585,7 +626,7 @@ class Cmd4Accessory
|
|
|
585
626
|
{
|
|
586
627
|
let relatedCharacteristicString = CMD4_ACC_TYPE_ENUM.properties[ relatedCurrentAccTypeEnumIndex ].type;
|
|
587
628
|
self.log.info( chalk.blue( `Also Setting (Cached) ${ self.displayName } ${ relatedCharacteristicString }` ) + ` ${ value }` );
|
|
588
|
-
self.setStoredValueForIndex( relatedCurrentAccTypeEnumIndex, value );
|
|
629
|
+
self.cmd4Storage.setStoredValueForIndex( relatedCurrentAccTypeEnumIndex, value );
|
|
589
630
|
}
|
|
590
631
|
}
|
|
591
632
|
|
|
@@ -603,7 +644,7 @@ class Cmd4Accessory
|
|
|
603
644
|
{
|
|
604
645
|
let self = this;
|
|
605
646
|
|
|
606
|
-
let storedValue = self.getStoredValueForIndex( accTypeEnumIndex );
|
|
647
|
+
let storedValue = self.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex );
|
|
607
648
|
if ( storedValue == null || storedValue == undefined )
|
|
608
649
|
{
|
|
609
650
|
self.log.warn( `getCachedValue ${ characteristicString } for: ${ self.displayName } has no cached value` );
|
|
@@ -611,7 +652,7 @@ class Cmd4Accessory
|
|
|
611
652
|
callback( 10, null );
|
|
612
653
|
}
|
|
613
654
|
|
|
614
|
-
if ( cmd4Dbg ) self.log.debug( `getCachedValue ${ characteristicString } for: ${ self.displayName } returned (CACHED) value: ${ storedValue }` );
|
|
655
|
+
if ( settings.cmd4Dbg ) self.log.debug( `getCachedValue ${ characteristicString } for: ${ self.displayName } returned (CACHED) value: ${ storedValue }` );
|
|
615
656
|
|
|
616
657
|
callback( 0, storedValue );
|
|
617
658
|
|
|
@@ -631,8 +672,8 @@ class Cmd4Accessory
|
|
|
631
672
|
return undefined;
|
|
632
673
|
|
|
633
674
|
let characteristicProps = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].props;
|
|
634
|
-
let type = CMD4_ACC_TYPE_ENUM.
|
|
635
|
-
let ucType =
|
|
675
|
+
let type = CMD4_ACC_TYPE_ENUM.accEnumIndexToLC( accTypeEnumIndex );
|
|
676
|
+
let ucType = CMD4_ACC_TYPE_ENUM.accEnumIndexToUC( accTypeEnumIndex );
|
|
636
677
|
|
|
637
678
|
let definitions;
|
|
638
679
|
|
|
@@ -648,11 +689,18 @@ class Cmd4Accessory
|
|
|
648
689
|
let rc = definitions;
|
|
649
690
|
for ( let key in definitions )
|
|
650
691
|
{
|
|
651
|
-
|
|
692
|
+
// warn now
|
|
693
|
+
if ( key.charAt( 0 ) === key.charAt( 0 ).toUpperCase() )
|
|
694
|
+
{
|
|
695
|
+
this.log.warn( `The property definition key: ${ key } is Capitalized. In the near future all characteristics will start with a lower case character for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
|
|
696
|
+
}
|
|
697
|
+
let lcKey = lcFirst ( key );
|
|
698
|
+
|
|
699
|
+
if ( characteristicProps[ lcKey ] == undefined )
|
|
652
700
|
throw new Error( `props for key "${ key }" not in definition of "${ type }"` );
|
|
653
701
|
|
|
654
702
|
|
|
655
|
-
if ( typeof characteristicProps[
|
|
703
|
+
if ( typeof characteristicProps[ lcKey ] != typeof definitions[ lcKey ] )
|
|
656
704
|
throw new Error( `props for key "${ key }" type "${ typeof definitions[ key ] }" Not equal to definition of "${ typeof characteristicProps[ key ] }"` );
|
|
657
705
|
|
|
658
706
|
}
|
|
@@ -665,7 +713,7 @@ class Cmd4Accessory
|
|
|
665
713
|
// We fix this here.
|
|
666
714
|
if ( accTypeEnumIndex == CMD4_ACC_TYPE_ENUM.CurrentHeatingCoolingState )
|
|
667
715
|
{
|
|
668
|
-
if ( cmd4Dbg ) this.log.debug( "fixing heatingCoolingState" );
|
|
716
|
+
if ( settings.cmd4Dbg ) this.log.debug( "fixing heatingCoolingState" );
|
|
669
717
|
accessory.service.getCharacteristic(
|
|
670
718
|
CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].
|
|
671
719
|
characteristic ).setProps(
|
|
@@ -712,23 +760,24 @@ class Cmd4Accessory
|
|
|
712
760
|
// ***********************************************
|
|
713
761
|
addAllServiceCharacteristicsForAccessory( accessory )
|
|
714
762
|
{
|
|
715
|
-
if ( cmd4Dbg ) accessory.log.debug( `Adding All Service Characteristics for: ${ accessory.displayName }` );
|
|
763
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( `Adding All Service Characteristics for: ${ accessory.displayName }` );
|
|
716
764
|
|
|
717
765
|
let perms = "";
|
|
718
|
-
let len = this.storedValuesPerCharacteristic.length;
|
|
719
766
|
|
|
720
767
|
// Check every possible characteristic
|
|
721
|
-
for ( let accTypeEnumIndex = 0; accTypeEnumIndex <
|
|
768
|
+
for ( let accTypeEnumIndex = 0; accTypeEnumIndex < CMD4_ACC_TYPE_ENUM.EOL; accTypeEnumIndex++ )
|
|
722
769
|
{
|
|
723
|
-
|
|
770
|
+
// For "Get" or "Set" commands, we send uppercase
|
|
771
|
+
let uCCharacteristicString = CMD4_ACC_TYPE_ENUM.accEnumIndexToUC( accTypeEnumIndex );
|
|
724
772
|
|
|
725
773
|
// If there is a stored value for this characteristic ( defined by the config file )
|
|
726
774
|
// Then we need to add the characteristic too
|
|
727
|
-
|
|
775
|
+
let storedValue = accessory.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex );
|
|
776
|
+
if ( storedValue != undefined )
|
|
728
777
|
{
|
|
729
|
-
if ( cmd4Dbg ) accessory.log.debug( "Found characteristic:%s value:%s for:%s",
|
|
730
|
-
|
|
731
|
-
|
|
778
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( "Found characteristic:%s value:%s for:%s",
|
|
779
|
+
uCCharacteristicString,
|
|
780
|
+
storedValue,
|
|
732
781
|
this.displayName );
|
|
733
782
|
|
|
734
783
|
// Find out if the characteristic is not part of the service
|
|
@@ -736,7 +785,8 @@ class Cmd4Accessory
|
|
|
736
785
|
if ( ! accessory.service.testCharacteristic(
|
|
737
786
|
CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].characteristic ) )
|
|
738
787
|
{
|
|
739
|
-
if ( cmd4Dbg ) accessory.log.debug( "Adding optional characteristic:%s for: %s", CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type, this.displayName );
|
|
788
|
+
//if ( settings.cmd4Dbg ) accessory.log.debug( "Adding optional characteristic:%s for: %s", CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type, this.displayName );
|
|
789
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( "Adding optional characteristic:%s for: %s", uCCharacteristicString, this.displayName );
|
|
740
790
|
|
|
741
791
|
accessory.service.addCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].characteristic );
|
|
742
792
|
}
|
|
@@ -747,7 +797,8 @@ class Cmd4Accessory
|
|
|
747
797
|
let props = accessory.configHasCharacteristicProps( accTypeEnumIndex );
|
|
748
798
|
if ( props )
|
|
749
799
|
{
|
|
750
|
-
if ( cmd4Dbg ) accessory.log.debug( "Overriding characteristic %s props for: %s ", CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type, this.displayName );
|
|
800
|
+
//if ( settings.cmd4Dbg ) accessory.log.debug( "Overriding characteristic %s props for: %s ", CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type, this.displayName );
|
|
801
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( "Overriding characteristic %s props for: %s ", uCCharacteristicString, this.displayName );
|
|
751
802
|
accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].
|
|
752
803
|
characteristic )
|
|
753
804
|
.setProps(
|
|
@@ -789,7 +840,7 @@ class Cmd4Accessory
|
|
|
789
840
|
{
|
|
790
841
|
accessory.service.setCharacteristic(
|
|
791
842
|
CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].characteristic,
|
|
792
|
-
this.getStoredValueForIndex( accTypeEnumIndex ) );
|
|
843
|
+
this.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex ) );
|
|
793
844
|
}
|
|
794
845
|
|
|
795
846
|
|
|
@@ -803,28 +854,28 @@ class Cmd4Accessory
|
|
|
803
854
|
{
|
|
804
855
|
|
|
805
856
|
// getCachedValue or getValue
|
|
806
|
-
if (
|
|
857
|
+
if ( ! accessory.polling ||
|
|
807
858
|
accessory.listOfPollingCharacteristics[ accTypeEnumIndex ] == undefined
|
|
808
859
|
)
|
|
809
860
|
{
|
|
810
|
-
if ( cmd4Dbg ) this.log.debug( chalk.yellow( `Adding getCachedValue for ${ accessory.displayName } characteristic: ${
|
|
861
|
+
if ( settings.cmd4Dbg ) this.log.debug( chalk.yellow( `Adding getCachedValue for ${ accessory.displayName } characteristic: ${ uCCharacteristicString } ` ) );
|
|
811
862
|
//Get cachedValue
|
|
812
863
|
accessory.service.getCharacteristic(
|
|
813
864
|
CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ]
|
|
814
865
|
.characteristic )
|
|
815
|
-
.on( "get", accessory.getCachedValue.bind( accessory, accTypeEnumIndex,
|
|
866
|
+
.on( "get", accessory.getCachedValue.bind( accessory, accTypeEnumIndex, uCCharacteristicString ) );
|
|
816
867
|
} else
|
|
817
868
|
{
|
|
818
|
-
if ( cmd4Dbg ) this.log.debug( chalk.yellow( `Adding priorityGetValue for ${ accessory.displayName } characteristic: ${
|
|
869
|
+
if ( settings.cmd4Dbg ) this.log.debug( chalk.yellow( `Adding priorityGetValue for ${ accessory.displayName } characteristic: ${ uCCharacteristicString }` ) );
|
|
819
870
|
|
|
820
|
-
let details =
|
|
871
|
+
let details = accessory.lookupAccessoryHVForPollingCharacteristic( accessory, accTypeEnumIndex );
|
|
821
872
|
|
|
822
873
|
// Set parms are accTypeEnumIndex, value, callback
|
|
823
874
|
// Get parms are accTypeEnumIndex, callback
|
|
824
875
|
accessory.service.getCharacteristic(
|
|
825
876
|
CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ]
|
|
826
877
|
.characteristic )
|
|
827
|
-
.on( "get", accessory.queue.priorityGetValue.bind( accessory, accTypeEnumIndex,
|
|
878
|
+
.on( "get", accessory.queue.priorityGetValue.bind( accessory, accTypeEnumIndex, uCCharacteristicString, details.timeout ) );
|
|
828
879
|
}
|
|
829
880
|
}
|
|
830
881
|
}
|
|
@@ -841,11 +892,11 @@ class Cmd4Accessory
|
|
|
841
892
|
if ( ! accessory.polling ||
|
|
842
893
|
accessory.listOfPollingCharacteristics[ accTypeEnumIndex ] == undefined)
|
|
843
894
|
{
|
|
844
|
-
if ( cmd4Dbg ) this.log.debug( chalk.yellow( `Adding setCachedValue for ${ accessory.displayName } characteristic: ${
|
|
895
|
+
if ( settings.cmd4Dbg ) this.log.debug( chalk.yellow( `Adding setCachedValue for ${ accessory.displayName } characteristic: ${ uCCharacteristicString } ` ) );
|
|
845
896
|
// setCachedValue has parameters:
|
|
846
897
|
// accTypeEnumIndex, value, callback
|
|
847
898
|
// The first bound value though is "this"
|
|
848
|
-
let boundSetCachedValue = accessory.setCachedValue.bind( this, accTypeEnumIndex,
|
|
899
|
+
let boundSetCachedValue = accessory.setCachedValue.bind( this, accTypeEnumIndex, uCCharacteristicString );
|
|
849
900
|
accessory.service.getCharacteristic(
|
|
850
901
|
CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ]
|
|
851
902
|
.characteristic ).on( "set", ( value, callback ) => {
|
|
@@ -854,12 +905,13 @@ class Cmd4Accessory
|
|
|
854
905
|
});
|
|
855
906
|
|
|
856
907
|
} else {
|
|
857
|
-
if ( cmd4Dbg ) this.log.debug( chalk.yellow( `Adding prioritySetValue for ${ accessory.displayName } characteristic: ${
|
|
908
|
+
if ( settings.cmd4Dbg ) this.log.debug( chalk.yellow( `Adding prioritySetValue for ${ accessory.displayName } characteristic: ${ uCCharacteristicString } ` ) );
|
|
909
|
+
|
|
910
|
+
let details = accessory.lookupAccessoryHVForPollingCharacteristic( accessory, accTypeEnumIndex );
|
|
858
911
|
|
|
859
|
-
let details = this.lookupDetailsForPollingCharacteristic( accessory, accTypeEnumIndex );
|
|
860
912
|
// Set parms are accTypeEnumIndex, value, callback
|
|
861
913
|
// Get parms are accTypeEnumIndex, callback
|
|
862
|
-
let boundSetValue = accessory.queue.prioritySetValue.bind( this, accTypeEnumIndex,
|
|
914
|
+
let boundSetValue = accessory.queue.prioritySetValue.bind( this, accTypeEnumIndex, uCCharacteristicString, details.timeout, details.stateChangeResponseTime );
|
|
863
915
|
accessory.service.getCharacteristic(
|
|
864
916
|
CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ]
|
|
865
917
|
.characteristic ).on( "set", ( value, callback ) => {
|
|
@@ -880,188 +932,163 @@ class Cmd4Accessory
|
|
|
880
932
|
return;
|
|
881
933
|
}
|
|
882
934
|
|
|
883
|
-
this.setStoredValueForIndex( accTypeEnumIndex, value );
|
|
935
|
+
this.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, value );
|
|
884
936
|
|
|
885
937
|
if ( this.loggingService )
|
|
886
938
|
{
|
|
887
939
|
let firstParm, secondParm, thirdParm;
|
|
888
|
-
let ucFirstParm, ucSecondParm, ucThirdParm;
|
|
889
940
|
let firstParmValue, secondParmValue, thirdParmValue = 0;
|
|
890
|
-
let
|
|
941
|
+
let firstParmDirective, secondParmDirective, thirdParmDirective;
|
|
891
942
|
|
|
892
943
|
switch ( this.eve )
|
|
893
944
|
{
|
|
894
|
-
case constants.
|
|
945
|
+
case constants.FAKEGATO_TYPE_ENERGY:
|
|
895
946
|
{
|
|
896
|
-
firstParm = this.fakegatoConfig[ constants.
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
947
|
+
firstParm = this.fakegatoConfig[ constants.POWER ] || "0";
|
|
948
|
+
firstParmDirective = isAccDirective( firstParm, true );
|
|
949
|
+
firstParmValue = ( this.cmd4Storage.testStoredValueForIndex( firstParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
950
|
+
firstParmValue : this.cmd4Storage.getStoredValueForIndex( firstParmDirective.accTypeEnumIndex );
|
|
900
951
|
|
|
901
|
-
|
|
902
|
-
firstParmValue : this.getStoredValueForIndex( firstParmIndex );
|
|
903
|
-
|
|
904
|
-
if ( cmd4Dbg ) this.log.debug( `Logging ${ constants.POWER_l }: ${ firstParmValue }` );
|
|
952
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Logging ${ constants.POWER }: ${ firstParmValue }` );
|
|
905
953
|
// Eve Energy ( Outlet service )
|
|
906
954
|
this.loggingService.addEntry(
|
|
907
|
-
{ [ constants.
|
|
908
|
-
[ constants.
|
|
955
|
+
{ [ constants.TIME ] : moment( ).unix( ),
|
|
956
|
+
[ constants.POWER ] : firstParmValue
|
|
909
957
|
});
|
|
910
958
|
break;
|
|
911
959
|
}
|
|
912
|
-
case constants.
|
|
960
|
+
case constants.FAKEGATO_TYPE_ROOM:
|
|
913
961
|
{
|
|
914
|
-
firstParm = this.fakegatoConfig[ constants.
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
thirdParmValue = ( this.testStoredValueForIndex( thirdParmIndex ) == undefined ) ?
|
|
931
|
-
thirdParmValue : this.getStoredValueForIndex( thirdParmIndex );
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
if ( cmd4Dbg ) this.log.debug( `Logging ${ constants.TEMP_l }:${ firstParmValue } ${constants.HUMIDITY_l }:${ secondParmValue } ${ constants.PPM_l }:${ thirdParmValue }` );
|
|
962
|
+
firstParm = this.fakegatoConfig[ constants.TEMP ] || "0";
|
|
963
|
+
firstParmDirective = isAccDirective( firstParm, true );
|
|
964
|
+
secondParm = this.fakegatoConfig[ constants.HUMIDITY ] || "0";
|
|
965
|
+
secondParmDirective = isAccDirective( secondParm, true );
|
|
966
|
+
thirdParm = this.fakegatoConfig[ constants.PPM ] || "0";
|
|
967
|
+
thirdParmDirective = isAccDirective( thirdParm, true );
|
|
968
|
+
|
|
969
|
+
firstParmValue = ( this.cmd4Storage.testStoredValueForIndex( firstParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
970
|
+
firstParmValue : this.cmd4Storage.getStoredValueForIndex( firstParmDirective.accTypeEnumIndex );
|
|
971
|
+
secondParmValue = ( this.cmd4Storage.testStoredValueForIndex( secondParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
972
|
+
secondParmValue : this.cmd4Storage.getStoredValueForIndex( secondParmDirective.accTypeEnumIndex );
|
|
973
|
+
thirdParmValue = ( this.cmd4Storage.testStoredValueForIndex( thirdParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
974
|
+
thirdParmValue : this.cmd4Storage.getStoredValueForIndex( thirdParmDirective.accTypeEnumIndex );
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Logging ${ constants.TEMP }:${ firstParmValue } ${constants.HUMIDITY }:${ secondParmValue } ${ constants.PPM }:${ thirdParmValue }` );
|
|
935
978
|
// Eve Room ( TempSensor, HumiditySensor and AirQuality Services )
|
|
936
979
|
this.loggingService.addEntry(
|
|
937
|
-
{ [ constants.
|
|
938
|
-
[ constants.
|
|
939
|
-
[ constants.
|
|
940
|
-
[ constants.
|
|
980
|
+
{ [ constants.TIME ] : moment( ).unix( ),
|
|
981
|
+
[ constants.TEMP ] : firstParmValue,
|
|
982
|
+
[ constants.HUMIDITY ] : secondParmValue,
|
|
983
|
+
[ constants.PPM ] : thirdParmValue
|
|
941
984
|
});
|
|
942
985
|
break;
|
|
943
986
|
}
|
|
944
|
-
case constants.
|
|
987
|
+
case constants.FAKEGATO_TYPE_WEATHER:
|
|
945
988
|
{
|
|
946
|
-
firstParm = this.fakegatoConfig[ constants.
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
thirdParmValue = ( this.testStoredValueForIndex( thirdParmIndex ) == undefined ) ?
|
|
962
|
-
thirdParmValue : this.getStoredValueForIndex( thirdParmIndex );
|
|
963
|
-
|
|
964
|
-
if ( cmd4Dbg ) this.log.debug( `Logging ${ constants.TEMP_l }: ${ firstParmValue } ${ constants.PRESSURE_l }: ${ secondParmValue } ${ constants.HUMIDITY_l }: ${ thirdParmValue }` );
|
|
989
|
+
firstParm = this.fakegatoConfig[ constants.TEMP ] || "0";
|
|
990
|
+
firstParmDirective = isAccDirective( firstParm, true );
|
|
991
|
+
secondParm = this.fakegatoConfig[ constants.PRESSURE ] || "0";
|
|
992
|
+
secondParmDirective = isAccDirective( secondParm, true );
|
|
993
|
+
thirdParm = this.fakegatoConfig[ constants.HUMIDITY ] || "0";
|
|
994
|
+
thirdParmDirective = isAccDirective( thirdParm, true );
|
|
995
|
+
|
|
996
|
+
firstParmValue = ( this.cmd4Storage.testStoredValueForIndex( firstParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
997
|
+
firstParmValue : this.cmd4Storage.getStoredValueForIndex( firstParmDirective.accTypeEnumIndex );
|
|
998
|
+
secondParmValue = ( this.cmd4Storage.testStoredValueForIndex( secondParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
999
|
+
secondParmValue : this.cmd4Storage.getStoredValueForIndex( secondParmDirective.accTypeEnumIndex );
|
|
1000
|
+
thirdParmValue = ( this.cmd4Storage.testStoredValueForIndex( thirdParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
1001
|
+
thirdParmValue : this.cmd4Storage.getStoredValueForIndex( thirdParmDirective.accTypeEnumIndex );
|
|
1002
|
+
|
|
1003
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Logging ${ constants.TEMP }: ${ firstParmValue } ${ constants.PRESSURE }: ${ secondParmValue } ${ constants.HUMIDITY }: ${ thirdParmValue }` );
|
|
965
1004
|
|
|
966
1005
|
// Eve Weather ( TempSensor Service )
|
|
967
1006
|
this.loggingService.addEntry(
|
|
968
|
-
{ [ constants.
|
|
969
|
-
[ constants.
|
|
970
|
-
[ constants.
|
|
971
|
-
[ constants.
|
|
1007
|
+
{ [ constants.TIME ] : moment( ).unix( ),
|
|
1008
|
+
[ constants.TEMP ] : firstParmValue,
|
|
1009
|
+
[ constants.PRESSURE ] : secondParmValue,
|
|
1010
|
+
[ constants.HUMIDITY ] : thirdParmValue
|
|
972
1011
|
});
|
|
973
1012
|
break;
|
|
974
1013
|
}
|
|
975
|
-
case constants.
|
|
1014
|
+
case constants.FAKEGATO_TYPE_DOOR:
|
|
976
1015
|
{
|
|
977
|
-
firstParm = this.fakegatoConfig[ constants.
|
|
978
|
-
|
|
1016
|
+
firstParm = this.fakegatoConfig[ constants.STATUS ] || "0";
|
|
1017
|
+
firstParmDirective = isAccDirective( firstParm, true );
|
|
979
1018
|
|
|
980
|
-
|
|
1019
|
+
firstParmValue = ( this.cmd4Storage.testStoredValueForIndex( firstParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
1020
|
+
firstParmValue : this.cmd4Storage.getStoredValueForIndex( firstParmDirective.accTypeEnumIndex );
|
|
981
1021
|
|
|
982
|
-
|
|
983
|
-
firstParmValue : this.getStoredValueForIndex( firstParmIndex );
|
|
984
|
-
|
|
985
|
-
if ( cmd4Dbg ) this.log.debug( `Logging ${ constants.STATUS_l } status: ${ firstParmValue }` );
|
|
1022
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Logging ${ constants.STATUS } status: ${ firstParmValue }` );
|
|
986
1023
|
|
|
987
1024
|
this.loggingService.addEntry(
|
|
988
|
-
{ [ constants.
|
|
989
|
-
[ constants.
|
|
1025
|
+
{ [ constants.TIME ] : moment( ).unix( ),
|
|
1026
|
+
[ constants.STATUS ] : firstParmValue
|
|
990
1027
|
});
|
|
991
1028
|
break;
|
|
992
1029
|
}
|
|
993
|
-
case constants.
|
|
1030
|
+
case constants.FAKEGATO_TYPE_MOTION:
|
|
994
1031
|
{
|
|
995
|
-
firstParm = this.fakegatoConfig[ constants.
|
|
996
|
-
|
|
997
|
-
firstParmIndex = CMD4_ACC_TYPE_ENUM.properties.indexOfEnum( i => i.type === ucFirstParm );
|
|
998
|
-
|
|
999
|
-
firstParmIndex = CMD4_ACC_TYPE_ENUM.properties.indexOfEnum( i => i.type === ucFirstParm );
|
|
1032
|
+
firstParm = this.fakegatoConfig[ constants.STATUS ] || "0";
|
|
1033
|
+
firstParmDirective = isAccDirective( firstParm, true );
|
|
1000
1034
|
|
|
1001
|
-
firstParmValue = ( this.testStoredValueForIndex(
|
|
1002
|
-
firstParmValue : this.getStoredValueForIndex(
|
|
1035
|
+
firstParmValue = ( this.cmd4Storage.testStoredValueForIndex( firstParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
1036
|
+
firstParmValue : this.cmd4Storage.getStoredValueForIndex( firstParmDirective.accTypeEnumIndex );
|
|
1003
1037
|
|
|
1004
|
-
if ( cmd4Dbg ) this.log.debug( `Logging ${ constants.
|
|
1038
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Logging ${ constants.STATUS }: ${ firstParmValue }` );
|
|
1005
1039
|
|
|
1006
1040
|
this.loggingService.addEntry(
|
|
1007
|
-
{ [ constants.
|
|
1008
|
-
[ constants.
|
|
1041
|
+
{ [ constants.TIME ] : moment( ).unix( ),
|
|
1042
|
+
[ constants.STATUS ] : firstParmValue
|
|
1009
1043
|
});
|
|
1010
1044
|
break;
|
|
1011
1045
|
}
|
|
1012
|
-
case constants.
|
|
1046
|
+
case constants.FAKEGATO_TYPE_THERMO:
|
|
1013
1047
|
{
|
|
1014
|
-
firstParm = this.fakegatoConfig[ constants.
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
thirdParmValue = ( this.testStoredValueForIndex( thirdParmIndex ) == undefined ) ?
|
|
1030
|
-
thirdParmValue : this.getStoredValueForIndex( thirdParmIndex );
|
|
1031
|
-
|
|
1032
|
-
if ( cmd4Dbg ) this.log.debug( `Logging ${ constants.CURRENTTEMP_l }: ${ firstParmValue } ${ constants.SETTEMP_l }:${ secondParmValue } ${constants.VALVEPOSITION_l }:${ thirdParmValue } ` );
|
|
1048
|
+
firstParm = this.fakegatoConfig[ constants.CURRENTTEMP ] || "0";
|
|
1049
|
+
firstParmDirective = isAccDirective( firstParm, true );
|
|
1050
|
+
secondParm = this.fakegatoConfig[ constants.SETTEMP ] || "0";
|
|
1051
|
+
secondParmDirective = isAccDirective( secondParm, true );
|
|
1052
|
+
thirdParm = this.fakegatoConfig[ constants.VALVEPOSITION ] || "0";
|
|
1053
|
+
thirdParmDirective = isAccDirective( thirdParm, true );
|
|
1054
|
+
|
|
1055
|
+
firstParmValue = ( this.cmd4Storage.testStoredValueForIndex( firstParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
1056
|
+
firstParmValue : this.cmd4Storage.getStoredValueForIndex( firstParmDirective.accTypeEnumIndex );
|
|
1057
|
+
secondParmValue = ( this.cmd4Storage.testStoredValueForIndex( secondParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
1058
|
+
secondParmValue : this.cmd4Storage.getStoredValueForIndex( secondParmDirective.accTypeEnumIndex );
|
|
1059
|
+
thirdParmValue = ( this.cmd4Storage.testStoredValueForIndex( thirdParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
1060
|
+
thirdParmValue : this.cmd4Storage.getStoredValueForIndex( thirdParmDirective.accTypeEnumIndex );
|
|
1061
|
+
|
|
1062
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Logging ${ constants.CURRENTTEMP }: ${ firstParmValue } ${ constants.SETTEMP }:${ secondParmValue } ${constants.VALVEPOSITION }:${ thirdParmValue } ` );
|
|
1033
1063
|
|
|
1034
1064
|
// Eve Thermo ( Thermostat service )
|
|
1035
1065
|
this.loggingService.addEntry(
|
|
1036
|
-
{ [ constants.
|
|
1037
|
-
[ constants.
|
|
1038
|
-
[ constants.
|
|
1039
|
-
[ constants.
|
|
1066
|
+
{ [ constants.TIME ] : moment( ).unix( ),
|
|
1067
|
+
[ constants.CURRENTTEMP ] : firstParmValue,
|
|
1068
|
+
[ constants.SETTEMP ] : secondParmValue,
|
|
1069
|
+
[ constants.VALVEPOSITION ] : thirdParmValue
|
|
1040
1070
|
});
|
|
1041
1071
|
break;
|
|
1042
1072
|
}
|
|
1043
|
-
case constants.
|
|
1073
|
+
case constants.FAKEGATO_TYPE_AQUA:
|
|
1044
1074
|
{
|
|
1045
|
-
firstParm = this.fakegatoConfig[ constants.
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
firstParmIndex = CMD4_ACC_TYPE_ENUM.properties.indexOfEnum( i => i.type === ucFirstParm );
|
|
1051
|
-
secondParmIndex = CMD4_ACC_TYPE_ENUM.properties.indexOfEnum( i => i.type === ucSecondParm );
|
|
1075
|
+
firstParm = this.fakegatoConfig[ constants.STATUS ] || "0";
|
|
1076
|
+
firstParmDirective = isAccDirective( firstParm, true );
|
|
1077
|
+
secondParm = this.fakegatoConfig[ constants.WATERAMOUNT ] || "0";
|
|
1078
|
+
secondParmDirective = isAccDirective( secondParm, true );
|
|
1052
1079
|
|
|
1053
|
-
firstParmValue = ( this.testStoredValueForIndex(
|
|
1054
|
-
|
|
1055
|
-
secondParmValue = ( this.testStoredValueForIndex(
|
|
1056
|
-
|
|
1080
|
+
firstParmValue = ( this.cmd4Storage.testStoredValueForIndex( firstParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
1081
|
+
firstParmValue : this.cmd4Storage.getStoredValueForIndex( firstParmDirective.accTypeEnumIndex );
|
|
1082
|
+
secondParmValue = ( this.cmd4Storage.testStoredValueForIndex( secondParmDirective.accTypeEnumIndex ) == undefined ) ?
|
|
1083
|
+
secondParmValue : this.cmd4Storage.getStoredValueForIndex( secondParmDirective.accTypeEnumIndex );
|
|
1057
1084
|
|
|
1058
|
-
if ( cmd4Dbg ) this.log.debug( `Logging ${ constants.
|
|
1085
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Logging ${ constants.STATUS }: ${ firstParmValue } ${ constants.WATERAMOUNT }: ${ secondParmValue }` );
|
|
1059
1086
|
|
|
1060
1087
|
// Eve Aqua ( Valve service set to Irrigation Type )
|
|
1061
1088
|
this.LoggingService.addEntry(
|
|
1062
|
-
{ [ constants.
|
|
1063
|
-
[ constants.
|
|
1064
|
-
[ constants.
|
|
1089
|
+
{ [ constants.TIME ] : moment( ).unix( ),
|
|
1090
|
+
[ constants.STATUS ] : firstParmValue,
|
|
1091
|
+
[ constants.WATERAMOUNT ] : secondParmValue
|
|
1065
1092
|
});
|
|
1066
1093
|
break;
|
|
1067
1094
|
}
|
|
@@ -1076,101 +1103,120 @@ class Cmd4Accessory
|
|
|
1076
1103
|
|
|
1077
1104
|
for ( let key in fakegatoConfig )
|
|
1078
1105
|
{
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1106
|
+
let value = fakegatoConfig[ key ];
|
|
1107
|
+
|
|
1108
|
+
let rcDirective = isCmd4Directive( key, false );
|
|
1109
|
+
if ( rcDirective == null )
|
|
1110
|
+
{
|
|
1111
|
+
rcDirective = isCmd4Directive( key, true );
|
|
1112
|
+
if ( rcDirective != null )
|
|
1113
|
+
{
|
|
1114
|
+
// warn now
|
|
1115
|
+
this.log.warn( `The config.json FakeGato key: ${ key } is Capitalized. It should be: ${ rcDirective.key }. In the near future this will be an error for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
|
|
1116
|
+
// create the proper lower case value
|
|
1117
|
+
fakegatoConfig[ rcDirective.key ] = value;
|
|
1118
|
+
// delete the upper case value
|
|
1119
|
+
fakegatoConfig[ key ].remove();
|
|
1120
|
+
|
|
1121
|
+
//set the key
|
|
1122
|
+
key = rcDirective.key;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
switch ( key )
|
|
1127
|
+
{
|
|
1128
|
+
case constants.EVE:
|
|
1129
|
+
this.eve = fakegatoConfig[ key ];
|
|
1130
|
+
switch( value )
|
|
1131
|
+
{
|
|
1132
|
+
case constants.FAKEGATO_TYPE_ENERGY:
|
|
1133
|
+
case constants.FAKEGATO_TYPE_ROOM:
|
|
1134
|
+
case constants.FAKEGATO_TYPE_WEATHER:
|
|
1135
|
+
case constants.FAKEGATO_TYPE_DOOR:
|
|
1136
|
+
case constants.FAKEGATO_TYPE_MOTION:
|
|
1137
|
+
case constants.FAKEGATO_TYPE_THERMO:
|
|
1138
|
+
case constants.FAKEGATO_TYPE_AQUA:
|
|
1139
|
+
break;
|
|
1140
|
+
default:
|
|
1141
|
+
throw new Error( `Invalid fakegato eve type: "${ value }". It must be one of ( ${ constants.FAKEGATO_TYPE_ENERGY }, ${ constants.FAKEGATO_TYPE_ROOM }, ${ constants.FAKEGATO_TYPE_WEATHER }, ${ constants.FAKEGATO_TYPE_DOOR }, ${ constants.FAKEGATO_TYPE_MOTION }, ${ constants.FAKEGATO_TYPE_THERMO }, ${ constants.FAKEGATO_TYPE_AQUA } ). Check the Cmd4 README at: "https://github.com/simont77/fakegato-history".` );
|
|
1097
1142
|
}
|
|
1098
1143
|
break;
|
|
1099
|
-
|
|
1144
|
+
case constants.STORAGE:
|
|
1100
1145
|
this.storage = fakegatoConfig[ key ];
|
|
1101
1146
|
break;
|
|
1102
|
-
|
|
1147
|
+
case constants.STORAGEPATH:
|
|
1103
1148
|
this.storagePath = fakegatoConfig[ key ];
|
|
1104
1149
|
break;
|
|
1105
|
-
|
|
1150
|
+
case constants.KEYPATH:
|
|
1106
1151
|
this.keyPath = fakegatoConfig[ key ];
|
|
1107
1152
|
break;
|
|
1108
|
-
|
|
1153
|
+
case constants.FOLDER:
|
|
1109
1154
|
this.Folder = fakegatoConfig[ key ];
|
|
1110
1155
|
break;
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
throw new Error( `Invalid characteristic "${ value }" for fakegato to log of "${ key }".` );
|
|
1156
|
+
case constants.STATUS:
|
|
1157
|
+
case constants.TEMP:
|
|
1158
|
+
case constants.SETTEMP:
|
|
1159
|
+
case constants.HUMIDITY:
|
|
1160
|
+
case constants.PPM:
|
|
1161
|
+
case constants.POWER:
|
|
1162
|
+
case constants.PRESSURE:
|
|
1163
|
+
case constants.CURRENTTEMP:
|
|
1164
|
+
case constants.VALVEPOSITION:
|
|
1165
|
+
{
|
|
1166
|
+
if ( value != "0" )
|
|
1167
|
+
{
|
|
1168
|
+
let rcDirective = isAccDirective( value, false );
|
|
1169
|
+
if ( rcDirective.accTypeEnumIndex == null )
|
|
1170
|
+
{
|
|
1171
|
+
rcDirective = isAccDirective( value, true );
|
|
1172
|
+
if ( rcDirective.accTypeEnumIndex == null )
|
|
1173
|
+
throw new Error( `Invalid characteristic "${ value }" for fakegato to log of "${ key }".` );
|
|
1130
1174
|
|
|
1175
|
+
this.log.warn( `The config.json FakeGato characteristic: ${ value } is Capitalized it should be: ${ rcDirective.type }. In the near future this will be an Error so that Cmd4 can use homebridge-ui.\nTo remove this Warning, Please fix your config.json.` );
|
|
1176
|
+
}
|
|
1131
1177
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1178
|
+
// Make sure the characteristic is being polled (Changing) so I do
|
|
1179
|
+
// not get any more tickets.
|
|
1180
|
+
if ( this.queue.isCharacteristicPolled( rcDirective.accTypeEnumIndex, this.queue, this ) == false )
|
|
1181
|
+
throw new Error(`Characteristic: "${ value }" for fakegato to log of "${ key }" is not being polled.\nHistory can not be updated continiously.` );
|
|
1182
|
+
}
|
|
1136
1183
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
}
|
|
1184
|
+
break;
|
|
1185
|
+
}
|
|
1186
|
+
default:
|
|
1187
|
+
throw new Error( `Invalid fakegato key: "${ key }" in json.config for: "${ this.displayName }".` );
|
|
1188
|
+
}
|
|
1143
1189
|
}
|
|
1144
1190
|
|
|
1145
1191
|
// Optional
|
|
1146
1192
|
if ( this.storage != undefined )
|
|
1147
1193
|
{
|
|
1148
|
-
if ( this.storage == constants.
|
|
1194
|
+
if ( this.storage == constants.FS )
|
|
1149
1195
|
{
|
|
1150
1196
|
this.loggingService = new FakeGatoHistoryService
|
|
1151
1197
|
(
|
|
1152
1198
|
this.eve,
|
|
1153
1199
|
this,
|
|
1154
|
-
{ [ constants.
|
|
1155
|
-
[ constants.
|
|
1200
|
+
{ [ constants.STORAGE ] : constants.FS,
|
|
1201
|
+
[ constants.PATH ] : this.storagePath
|
|
1156
1202
|
}
|
|
1157
1203
|
);
|
|
1158
1204
|
this.services.push( this.loggingService );
|
|
1159
1205
|
|
|
1160
|
-
} else if ( this.storage == constants.
|
|
1206
|
+
} else if ( this.storage == constants.GOOGLE_DRIVE )
|
|
1161
1207
|
{
|
|
1162
1208
|
this.loggingService = new FakeGatoHistoryService
|
|
1163
1209
|
(
|
|
1164
1210
|
this.eve,
|
|
1165
1211
|
this,
|
|
1166
|
-
{ [ constants.
|
|
1167
|
-
[ constants.
|
|
1168
|
-
[ constants.
|
|
1212
|
+
{ [ constants.STORAGE ] : constants.GOOGLE_DRIVE,
|
|
1213
|
+
[ constants.FOLDER ] : this.folder,
|
|
1214
|
+
[ constants.KEYPATH ] : this.keyPath }
|
|
1169
1215
|
);
|
|
1170
1216
|
this.services.push( this.loggingService );
|
|
1171
1217
|
} else
|
|
1172
1218
|
{
|
|
1173
|
-
this.log.warn( chalk.yellow( "WARNING" ) + `: Cmd4 Unknown accessory config.storage:{ this.storage } Expected:${ constants.
|
|
1219
|
+
this.log.warn( chalk.yellow( "WARNING" ) + `: Cmd4 Unknown accessory config.storage:{ this.storage } Expected:${ constants.FS } or ${ constants.GOOGLEDRIVE } for: ${ this.displayName }` );
|
|
1174
1220
|
}
|
|
1175
1221
|
}
|
|
1176
1222
|
|
|
@@ -1189,81 +1235,27 @@ class Cmd4Accessory
|
|
|
1189
1235
|
if ( typeof state_cmd != "string" )
|
|
1190
1236
|
throw new Error( `No state_cmd for: "${ this.displayName }".` );
|
|
1191
1237
|
|
|
1192
|
-
|
|
1193
|
-
// Split the state_cmd into words.
|
|
1194
|
-
let cmdArray = state_cmd.match(/\S+/gi);
|
|
1195
|
-
|
|
1196
|
-
// Assume no words
|
|
1197
|
-
let arrayLength = 0;
|
|
1198
|
-
|
|
1199
|
-
// Get the number of words
|
|
1200
|
-
if ( cmdArray )
|
|
1201
|
-
arrayLength = cmdArray.length;
|
|
1202
|
-
|
|
1203
|
-
// Check that the state_cmd is valid.
|
|
1204
|
-
// The first word must be in the persons path
|
|
1205
|
-
// The second word, if it exists must be a file
|
|
1206
|
-
// and have the correct path.
|
|
1207
|
-
switch ( arrayLength )
|
|
1208
|
-
{
|
|
1209
|
-
case 0:
|
|
1210
|
-
this.log.error( `No state_cmd given` );
|
|
1211
|
-
return false;
|
|
1212
|
-
default:
|
|
1213
|
-
{
|
|
1214
|
-
let checkFile = cmdArray[ arrayLength -1 ];
|
|
1215
|
-
|
|
1216
|
-
try {
|
|
1217
|
-
fs.accessSync( checkFile, fs.F_OK );
|
|
1218
|
-
// File exists - OK
|
|
1219
|
-
|
|
1220
|
-
} catch ( e ) {
|
|
1221
|
-
// It isn't accessible
|
|
1222
|
-
throw new Error( `The file: "${ checkFile }" does not exist, It is highly likely the state_cmd will fail. Hint: Do not use wildcards that would normally be expanded by a shell.` );
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
// Purposely fall through to check the command as well
|
|
1226
|
-
// break omitted
|
|
1227
|
-
case 1:
|
|
1228
|
-
{
|
|
1229
|
-
let checkCmd = cmdArray[ 0 ];
|
|
1230
|
-
|
|
1231
|
-
// if the lone command is a path to a command
|
|
1232
|
-
// Then check if it exists, oTherwise check if it is
|
|
1233
|
-
// in Their path.
|
|
1234
|
-
if ( checkCmd.charAt( 0 ) == "/" || (
|
|
1235
|
-
checkCmd.length > 1 &&
|
|
1236
|
-
checkCmd.charAt( 0 ) == "." &&
|
|
1237
|
-
checkCmd.charAt( 1 ) == "/" )
|
|
1238
|
-
)
|
|
1239
|
-
{
|
|
1240
|
-
try {
|
|
1241
|
-
fs.accessSync( checkCmd, fs.F_OK );
|
|
1242
|
-
// File exists - OK
|
|
1243
|
-
} catch ( e ) {
|
|
1244
|
-
throw new Error( `The file: "${ checkCmd }" does not exist, It is highly likely the state_cmd will fail. Hint: Do not use wildcards that would normally be expanded by a shell.` );
|
|
1245
|
-
}
|
|
1246
|
-
} else
|
|
1247
|
-
{
|
|
1248
|
-
if ( ! commandExistsSync( checkCmd ) )
|
|
1249
|
-
throw new Error( `The file: "${ checkCmd }" does not exist, It is highly likely the state_cmd will fail. Hint: Do not use wildcards that would normally be expanded by a shell.` );
|
|
1250
|
-
}
|
|
1251
|
-
break;
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1238
|
+
// This was messy, did not like spaces. let the user be the judge of it.
|
|
1254
1239
|
return true;
|
|
1255
1240
|
}
|
|
1256
1241
|
|
|
1242
|
+
// We are looking for things like Volume: <value>, Name: <value>, Mute: <value>
|
|
1257
1243
|
parseKeyForCharacteristics( key, value, parseConfigShouldUseCharacteristicValues )
|
|
1258
1244
|
{
|
|
1259
1245
|
// fix the their scripts, fix it here.
|
|
1260
|
-
let
|
|
1246
|
+
let rcDirective = isAccDirective( key, false );
|
|
1247
|
+
if ( rcDirective.accTypeEnumIndex == null )
|
|
1248
|
+
{
|
|
1249
|
+
rcDirective = isAccDirective( key, true );
|
|
1250
|
+
if ( rcDirective.accTypeEnumIndex == null )
|
|
1251
|
+
throw new Error( `OOPS: "${ key }" not found for parsing characteristics in: "${ this.displayName }".` );
|
|
1261
1252
|
|
|
1262
|
-
|
|
1253
|
+
this.log.warn( `The config.json characteristic key: ${ key } is Capitalized. It should be: ${ rcDirective.type }. In the near future this will be an error for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
|
|
1254
|
+
}
|
|
1263
1255
|
|
|
1264
|
-
if ( accTypeEnumIndex < 0 )
|
|
1265
|
-
throw new Error( `OOPS: "${ key }" not found for parsing characteristics in: "${ this.displayName }".` );
|
|
1266
1256
|
|
|
1257
|
+
let characteristicString = rcDirective.type;
|
|
1258
|
+
let accTypeEnumIndex = rcDirective.accTypeEnumIndex;
|
|
1267
1259
|
|
|
1268
1260
|
// Do not update the stored values as it is being restored from cache
|
|
1269
1261
|
if ( parseConfigShouldUseCharacteristicValues == false )
|
|
@@ -1275,11 +1267,11 @@ class Cmd4Accessory
|
|
|
1275
1267
|
value = transposeConstantToValidValue( CMD4_ACC_TYPE_ENUM.properties, accTypeEnumIndex, value ) ;
|
|
1276
1268
|
}
|
|
1277
1269
|
|
|
1270
|
+
|
|
1278
1271
|
// Return the appropriate type, by seeing what it is defined as in Homebridge,
|
|
1279
1272
|
let properValue = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].stringConversionFunction( value );
|
|
1280
1273
|
if ( properValue == undefined )
|
|
1281
1274
|
{
|
|
1282
|
-
let characteristicString = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type;
|
|
1283
1275
|
// If the value is not convertable, just return it.
|
|
1284
1276
|
this.log.warn( `parseKeyForCharacterisitcs: ${ this.displayName } ` + chalk.red( `Cannot convert value: ${ value } to ${ CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].props.format } for ${ characteristicString }` ) );
|
|
1285
1277
|
|
|
@@ -1287,7 +1279,8 @@ class Cmd4Accessory
|
|
|
1287
1279
|
}
|
|
1288
1280
|
|
|
1289
1281
|
|
|
1290
|
-
this.
|
|
1282
|
+
//this.log.debug("Setting %s to %s", characteristicString, properValue );
|
|
1283
|
+
this.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, properValue );
|
|
1291
1284
|
}
|
|
1292
1285
|
|
|
1293
1286
|
processRequires( requires )
|
|
@@ -1310,7 +1303,7 @@ class Cmd4Accessory
|
|
|
1310
1303
|
throw new Error( `Requires definition: "${ required }" must be a string.` );
|
|
1311
1304
|
|
|
1312
1305
|
|
|
1313
|
-
if ( cmd4Dbg ) this.log.debug( `Requiring ${ required }` );
|
|
1306
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Requiring ${ required }` );
|
|
1314
1307
|
|
|
1315
1308
|
require( required );
|
|
1316
1309
|
}
|
|
@@ -1349,11 +1342,11 @@ class Cmd4Accessory
|
|
|
1349
1342
|
valueToAdd.replace(/'$/, "")
|
|
1350
1343
|
|
|
1351
1344
|
this.listOfConstants[ keyToAdd ] = valueToAdd;
|
|
1352
|
-
|
|
1353
|
-
|
|
1345
|
+
}
|
|
1346
|
+
return;
|
|
1354
1347
|
}
|
|
1355
1348
|
|
|
1356
|
-
|
|
1349
|
+
throw new Error( `Constants must be an array of/or list of key/value pairs: "${ constantArg }".` );
|
|
1357
1350
|
}
|
|
1358
1351
|
|
|
1359
1352
|
processVariables( variables )
|
|
@@ -1446,17 +1439,46 @@ class Cmd4Accessory
|
|
|
1446
1439
|
{
|
|
1447
1440
|
let value = config[ key ];
|
|
1448
1441
|
|
|
1449
|
-
//
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1442
|
+
// warn now - Cmd4 Directives
|
|
1443
|
+
let rcDirective = isCmd4Directive( key, false );
|
|
1444
|
+
if ( rcDirective == null )
|
|
1445
|
+
{
|
|
1446
|
+
rcDirective = isCmd4Directive( key, true );
|
|
1447
|
+
if ( rcDirective != null )
|
|
1448
|
+
{
|
|
1449
|
+
this.log.warn( `The config.json Cmd4 Directive: ${ key } is Capitalized. It should be: ${ rcDirective.key }. In the near future this will be an error for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
|
|
1450
|
+
// create the proper lower case value
|
|
1451
|
+
config[ rcDirective.key ] = value;
|
|
1452
|
+
// delete the upper case value
|
|
1453
|
+
delete config[ key ];
|
|
1454
|
+
|
|
1455
|
+
//set the key
|
|
1456
|
+
key = rcDirective.key;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
// Not finding the key is not an error as it could be a Characteristic
|
|
1453
1460
|
|
|
1454
|
-
switch (
|
|
1461
|
+
switch ( key )
|
|
1455
1462
|
{
|
|
1456
1463
|
case constants.TYPE:
|
|
1464
|
+
{
|
|
1457
1465
|
this.type = value;
|
|
1466
|
+
let rcValue = isDevDirective( value, false );
|
|
1467
|
+
if ( rcValue.devEnumIndex == null )
|
|
1468
|
+
{
|
|
1469
|
+
rcValue = isDevDirective( value, true );
|
|
1470
|
+
if ( rcValue.devEnumIndex == null )
|
|
1471
|
+
throw new Error( `Unknown device type: "${ value }" given in: "${ this.displayName }".` );
|
|
1472
|
+
|
|
1473
|
+
// warn now
|
|
1474
|
+
this.log.warn( `The config.json Cmd4 device type: ${ value } is lowerCase. It should be: ${ rcValue.deviceName }. In the near future this will be an error for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
|
|
1475
|
+
|
|
1476
|
+
this.type = rcValue.deviceName;
|
|
1477
|
+
}
|
|
1478
|
+
this.typeIndex = rcValue.devEnumIndex;
|
|
1458
1479
|
|
|
1459
1480
|
break;
|
|
1481
|
+
}
|
|
1460
1482
|
case constants.SUBTYPE:
|
|
1461
1483
|
this.subType = value;
|
|
1462
1484
|
|
|
@@ -1470,7 +1492,7 @@ class Cmd4Accessory
|
|
|
1470
1492
|
break;
|
|
1471
1493
|
case constants.UUID:
|
|
1472
1494
|
// For those who define there own UUID
|
|
1473
|
-
this.
|
|
1495
|
+
this.uuid = value;
|
|
1474
1496
|
|
|
1475
1497
|
break;
|
|
1476
1498
|
case constants.ACCESSORY:
|
|
@@ -1495,38 +1517,10 @@ class Cmd4Accessory
|
|
|
1495
1517
|
// Allow characteristic property changes.
|
|
1496
1518
|
this.props = value;
|
|
1497
1519
|
|
|
1498
|
-
break;
|
|
1499
|
-
case constants.NAME:
|
|
1500
|
-
// This has already been parsed, but
|
|
1501
|
-
// here so that parseConfig passes and because
|
|
1502
|
-
// name is also a characteristic.
|
|
1503
|
-
this.name = value;
|
|
1504
|
-
|
|
1505
|
-
// Name is also a characteristic, which must be added.
|
|
1506
|
-
this.parseKeyForCharacteristics( key, value, parseConfigShouldUseCharacteristicValues );
|
|
1507
|
-
|
|
1508
|
-
break;
|
|
1509
|
-
case constants.MODEL:
|
|
1510
|
-
this.model = value;
|
|
1511
|
-
|
|
1512
|
-
break;
|
|
1513
|
-
case constants.MANUFACTURER:
|
|
1514
|
-
this.manufacturer = value;
|
|
1515
|
-
|
|
1516
|
-
break;
|
|
1517
|
-
case constants.SERIALNUMBER:
|
|
1518
|
-
this.serialNumber = value;
|
|
1519
|
-
|
|
1520
|
-
break;
|
|
1521
|
-
case constants.FIRMWAREREVISION:
|
|
1522
|
-
this.firmwareRevision = value;
|
|
1523
|
-
|
|
1524
1520
|
break;
|
|
1525
1521
|
case constants.OUTPUTCONSTANTS:
|
|
1526
1522
|
// Define if we should ouput constant strings
|
|
1527
|
-
|
|
1528
|
-
if ( value === true )
|
|
1529
|
-
this.outputConstants = value;
|
|
1523
|
+
this.outputConstants = value;
|
|
1530
1524
|
|
|
1531
1525
|
break;
|
|
1532
1526
|
case constants.STATUSMSG:
|
|
@@ -1538,12 +1532,6 @@ class Cmd4Accessory
|
|
|
1538
1532
|
|
|
1539
1533
|
break;
|
|
1540
1534
|
case "QueueStatMsgInterval":
|
|
1541
|
-
|
|
1542
|
-
// Never put into production
|
|
1543
|
-
this.log.warn( `Warning: ${ key } has been deprecated. It was never even used.` );
|
|
1544
|
-
this.log.warn( `To remove this message, just remove ${ key } from your config.json` );
|
|
1545
|
-
|
|
1546
|
-
break;
|
|
1547
1535
|
case "QueueMsg":
|
|
1548
1536
|
|
|
1549
1537
|
// Never put into production
|
|
@@ -1579,6 +1567,7 @@ class Cmd4Accessory
|
|
|
1579
1567
|
this.polling = value;
|
|
1580
1568
|
break;
|
|
1581
1569
|
case "Cmd4_Mode":
|
|
1570
|
+
case "cmd4_Mode":
|
|
1582
1571
|
this.log.warn( `Warning: ${ key } has been deprecated.` );
|
|
1583
1572
|
cmd4Mode = value;
|
|
1584
1573
|
|
|
@@ -1601,6 +1590,7 @@ class Cmd4Accessory
|
|
|
1601
1590
|
break;
|
|
1602
1591
|
case constants.STATE_CMD_SUFFIX:
|
|
1603
1592
|
// This gets added after any Get/Set <value>
|
|
1593
|
+
// We replace any constants already defined
|
|
1604
1594
|
this.state_cmd_suffix = value;
|
|
1605
1595
|
|
|
1606
1596
|
break;
|
|
@@ -1643,12 +1633,12 @@ class Cmd4Accessory
|
|
|
1643
1633
|
|
|
1644
1634
|
break;
|
|
1645
1635
|
case constants.LINKEDTYPES:
|
|
1646
|
-
if ( cmd4Dbg ) this.log.debug( `parseConfig. Found linked Accessories` );
|
|
1636
|
+
if ( settings.cmd4Dbg ) this.log.debug( `parseConfig. Found linked Accessories` );
|
|
1647
1637
|
this.linkedAccessoriesConfig = value;
|
|
1648
1638
|
|
|
1649
1639
|
break;
|
|
1650
1640
|
case constants.ACCESSORIES:
|
|
1651
|
-
if ( cmd4Dbg ) this.log.debug( `parseConfig. Found Accessories` );
|
|
1641
|
+
if ( settings.cmd4Dbg ) this.log.debug( `parseConfig. Found Accessories` );
|
|
1652
1642
|
this.accessoriesConfig = value;
|
|
1653
1643
|
|
|
1654
1644
|
break;
|
|
@@ -1675,12 +1665,8 @@ class Cmd4Accessory
|
|
|
1675
1665
|
this.log.warn( `To remove this message, just remove "Cmd4_Mode" from your config.json` );
|
|
1676
1666
|
}
|
|
1677
1667
|
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
this.ucType = ucFirst( this.type );
|
|
1682
|
-
this.typeIndex = CMD4_DEVICE_TYPE_ENUM.properties.indexOfEnum( i => i.deviceName === this.ucType );
|
|
1683
|
-
if ( this.typeIndex < 0 )
|
|
1668
|
+
// A device type must be specified
|
|
1669
|
+
if ( this.typeIndex == undefined || this.typeIndex < 0 )
|
|
1684
1670
|
throw new Error( `Unknown device type: "${ this.type }" given in: "${ this.displayName }".` );
|
|
1685
1671
|
|
|
1686
1672
|
// Create a subType to delimit services with multiple accessories of
|
|
@@ -1688,7 +1674,7 @@ class Cmd4Accessory
|
|
|
1688
1674
|
this.subType = this.subType || this.displayName;
|
|
1689
1675
|
|
|
1690
1676
|
// UUID must be defined or created.
|
|
1691
|
-
this.
|
|
1677
|
+
this.uuid = this.uuid || getAccessoryUUID( config, this.api.hap.uuid );
|
|
1692
1678
|
|
|
1693
1679
|
// Solve some issues people have encounterred who
|
|
1694
1680
|
// have had problems with shell completion which is
|
|
@@ -1707,6 +1693,10 @@ class Cmd4Accessory
|
|
|
1707
1693
|
this.log.info( chalk.blue( `Cmd4 is running in Demo Mode for ${ this.displayName }` ) );
|
|
1708
1694
|
}
|
|
1709
1695
|
|
|
1696
|
+
// Add the global constants to the listOfConstants
|
|
1697
|
+
if ( this.parentInfo.globalConstants != null )
|
|
1698
|
+
this.processConstants( this.parentInfo.globalConstants );
|
|
1699
|
+
|
|
1710
1700
|
// Handle seperation of strings of state_cmd for a prefix
|
|
1711
1701
|
if ( this.state_cmd_prefix )
|
|
1712
1702
|
this.state_cmd_prefix = this.state_cmd_prefix + " ";
|
|
@@ -1715,9 +1705,15 @@ class Cmd4Accessory
|
|
|
1715
1705
|
|
|
1716
1706
|
// Handle seperation of strings of state_cmd for a suffix
|
|
1717
1707
|
if ( this.state_cmd_suffix )
|
|
1718
|
-
|
|
1719
|
-
|
|
1708
|
+
{
|
|
1709
|
+
if ( typeof this.state_cmd_suffix != "string" )
|
|
1710
|
+
throw new Error( `state_cmd_suffix must be a string: "${ this.state_cmd_suffix }".` );
|
|
1711
|
+
|
|
1712
|
+
this.state_cmd_suffix = " " + this.replaceConstantsInString( this.state_cmd_suffix );
|
|
1713
|
+
} else
|
|
1714
|
+
{
|
|
1720
1715
|
this.state_cmd_suffix = "";
|
|
1716
|
+
}
|
|
1721
1717
|
|
|
1722
1718
|
if ( this.typeIndex == CMD4_DEVICE_TYPE_ENUM.Television )
|
|
1723
1719
|
{
|
|
@@ -1739,10 +1735,10 @@ class Cmd4Accessory
|
|
|
1739
1735
|
{
|
|
1740
1736
|
case null:
|
|
1741
1737
|
case undefined:
|
|
1742
|
-
if ( cmd4Dbg ) this.log.debug( `No polling configured.` );
|
|
1738
|
+
if ( settings.cmd4Dbg ) this.log.debug( `No polling configured.` );
|
|
1743
1739
|
return;
|
|
1744
1740
|
case Boolean:
|
|
1745
|
-
if ( cmd4Dbg ) this.log.debug( `Polling config is Default Polling. Nothing to check for unset polling characteristics` );
|
|
1741
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Polling config is Default Polling. Nothing to check for unset polling characteristics` );
|
|
1746
1742
|
return;
|
|
1747
1743
|
case String:
|
|
1748
1744
|
throw new Error( `Unknown type for Polling "${ this.polling }" given in: "${ this.displayName }".` );
|
|
@@ -1758,52 +1754,46 @@ class Cmd4Accessory
|
|
|
1758
1754
|
throw new Error( `Do not know how to handle polling type of: "${ pollingType }" for: "${ this.displayName }".` );
|
|
1759
1755
|
}
|
|
1760
1756
|
|
|
1761
|
-
// We need to check for removed
|
|
1762
|
-
let
|
|
1763
|
-
for ( let accTypeEnumIndex = 0; accTypeEnumIndex < len; accTypeEnumIndex ++ )
|
|
1757
|
+
// We need to check for removed characteristic Strings in the config
|
|
1758
|
+
for ( let accTypeEnumIndex = 0; accTypeEnumIndex < CMD4_ACC_TYPE_ENUM.EOL; accTypeEnumIndex ++ )
|
|
1764
1759
|
{
|
|
1765
|
-
|
|
1766
|
-
if (
|
|
1760
|
+
let storedValue = this.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex );
|
|
1761
|
+
if ( storedValue != null )
|
|
1767
1762
|
{
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
let
|
|
1771
|
-
let
|
|
1772
|
-
if ( config[
|
|
1773
|
-
config[ lcCharacteristicString ] != undefined ||
|
|
1763
|
+
|
|
1764
|
+
// connect the accTypeEnumIndex to its characteristic string
|
|
1765
|
+
let lcCharacteristicString = CMD4_ACC_TYPE_ENUM.accEnumIndexToLC( accTypeEnumIndex );
|
|
1766
|
+
let ucCharacteristicString = CMD4_ACC_TYPE_ENUM.accEnumIndexToUC( accTypeEnumIndex );
|
|
1767
|
+
if ( config[ lcCharacteristicString ] != undefined ||
|
|
1774
1768
|
config[ ucCharacteristicString ] != undefined )
|
|
1775
1769
|
{
|
|
1776
1770
|
continue;
|
|
1777
|
-
} else
|
|
1778
|
-
|
|
1779
|
-
|
|
1771
|
+
} else
|
|
1772
|
+
{
|
|
1773
|
+
// There was a previously stored characteristic, if it was not initialized
|
|
1774
|
+
this.log.warn( `Removing previously configured characteristic: ${ lcCharacteristicString }` );
|
|
1775
|
+
this.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, null );
|
|
1780
1776
|
}
|
|
1781
1777
|
}
|
|
1782
1778
|
}
|
|
1783
1779
|
}
|
|
1784
|
-
|
|
1780
|
+
|
|
1781
|
+
// HV may change with polling characteristics
|
|
1782
|
+
lookupAccessoryHVForPollingCharacteristic( accessory, accTypeEnumIndex )
|
|
1785
1783
|
{
|
|
1786
1784
|
// Heirarchy is first the default
|
|
1787
|
-
let timeout =
|
|
1788
|
-
let interval =
|
|
1789
|
-
let stateChangeResponseTime =
|
|
1790
|
-
if ( ! accessory.stateChangeResponseTime )
|
|
1791
|
-
stateChangeResponseTime = CMD4_DEVICE_TYPE_ENUM.properties[ accessory.typeIndex ].devicesStateChangeDefaultTime;
|
|
1785
|
+
let timeout = accessory.hV.timeout;
|
|
1786
|
+
let interval = accessory.hV.interval;
|
|
1787
|
+
let stateChangeResponseTime = accessory.hV.stateChangeResponseTime;
|
|
1792
1788
|
|
|
1793
1789
|
// For testing purposes where there is no queue
|
|
1794
1790
|
let queueName = null;
|
|
1795
1791
|
if ( accessory.queue )
|
|
1796
1792
|
queueName = accessory.queue.queueName;
|
|
1797
1793
|
|
|
1798
|
-
// Secondly the accessories definition
|
|
1799
|
-
if ( accessory.timeout )
|
|
1800
|
-
timeout = accessory.timeout;
|
|
1801
1794
|
|
|
1802
|
-
if ( accessory.interval )
|
|
1803
|
-
interval = accessory.interval;
|
|
1804
|
-
|
|
1805
|
-
// Finally the polled setting
|
|
1806
1795
|
let pollingEntry = accessory.listOfPollingCharacteristics[ accTypeEnumIndex ];
|
|
1796
|
+
|
|
1807
1797
|
// There should only be one, if any
|
|
1808
1798
|
if ( pollingEntry != undefined )
|
|
1809
1799
|
{
|
|
@@ -1859,17 +1849,10 @@ class Cmd4Accessory
|
|
|
1859
1849
|
|
|
1860
1850
|
determineCharacteristicsToPollForAccessory( accessory )
|
|
1861
1851
|
{
|
|
1862
|
-
//
|
|
1863
|
-
|
|
1864
|
-
let
|
|
1865
|
-
|
|
1866
|
-
// The default interval is defined first by the accessory, and if not defined,
|
|
1867
|
-
// then the default 1 minute interval. Intervals are in seconds
|
|
1868
|
-
let interval = ( this.interval ) ? this.interval : constants.DEFAULT_INTERVAL;
|
|
1869
|
-
|
|
1870
|
-
// The default stateChangeResponseTime is defined first by the accessory, and if not defined,
|
|
1871
|
-
// then the default 3 seconds. stateChangeResponseTime is in seconds
|
|
1872
|
-
let stateChangeResponseTime = ( this.stateChangeResponseTime ) ? this.stateChangeResponseTime : constants.DEFAULT_STATE_CHANGE_RESPONSE_TIME;
|
|
1852
|
+
// Get the values based on their hierarchy.
|
|
1853
|
+
let timeout = accessory.hV.timeout;
|
|
1854
|
+
let interval = accessory.hV.interval;
|
|
1855
|
+
let stateChangeResponseTime = accessory.hV.stateChangeResponseTime;
|
|
1873
1856
|
|
|
1874
1857
|
|
|
1875
1858
|
// We need to create the listOfPollingCharacteristics, even in Demo mode because
|
|
@@ -1877,7 +1860,7 @@ class Cmd4Accessory
|
|
|
1877
1860
|
// which happens in the Demo mode without polling.
|
|
1878
1861
|
if ( typeof accessory.polling == "object" )
|
|
1879
1862
|
{
|
|
1880
|
-
if ( cmd4Dbg ) this.log.debug( `Characteristic polling for: ${ accessory.displayName }` );
|
|
1863
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Characteristic polling for: ${ accessory.displayName }` );
|
|
1881
1864
|
accessory.polling.forEach( ( jsonPollingConfig ) =>
|
|
1882
1865
|
{
|
|
1883
1866
|
// Characteristic polling is a json type
|
|
@@ -1886,18 +1869,34 @@ class Cmd4Accessory
|
|
|
1886
1869
|
|
|
1887
1870
|
let value;
|
|
1888
1871
|
let accTypeEnumIndex = -1;
|
|
1889
|
-
let characteristicString = "";
|
|
1890
1872
|
|
|
1891
1873
|
// All this code disappears in the next major release.
|
|
1892
1874
|
for ( let key in jsonPollingConfig )
|
|
1893
1875
|
{
|
|
1894
|
-
let ucKey = ucFirst( key );
|
|
1895
1876
|
value = jsonPollingConfig[ key ];
|
|
1896
1877
|
|
|
1897
|
-
|
|
1878
|
+
let rcDirective = isCmd4Directive( key );
|
|
1879
|
+
if ( rcDirective == null )
|
|
1880
|
+
{
|
|
1881
|
+
rcDirective = isCmd4Directive( key, true );
|
|
1882
|
+
if ( rcDirective != null )
|
|
1883
|
+
{
|
|
1884
|
+
this.log.warn( `The config.json Cmd4 Polling Directive: ${ key } is Capitalized. It should be: ${ rcDirective.key }. In the near future this will be an error for homebridge-ui integration.\nTo remove this Warning, Please fix your config.json.` );
|
|
1885
|
+
// create the proper lower case value
|
|
1886
|
+
jsonPollingConfig[ rcDirective.key ] = value;
|
|
1887
|
+
// delete the upper case value
|
|
1888
|
+
delete jsonPollingConfig[ key ];
|
|
1889
|
+
|
|
1890
|
+
//set the key
|
|
1891
|
+
key = rcDirective.key;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
// Not finding the key is not an error as it could be a Characteristic
|
|
1895
|
+
|
|
1896
|
+
switch ( key )
|
|
1898
1897
|
{
|
|
1899
1898
|
case constants.TIMEOUT:
|
|
1900
|
-
|
|
1899
|
+
// Timers are in milliseconds. A low value can result in failure to get/set values
|
|
1901
1900
|
timeout = parseInt( value, 10 );
|
|
1902
1901
|
if ( timeout < 500 )
|
|
1903
1902
|
this.log.warn( `Timeout for: ${ accessory.displayName } is in milliseconds. A value of: ${ timeout } seems pretty low.` );
|
|
@@ -1923,16 +1922,20 @@ class Cmd4Accessory
|
|
|
1923
1922
|
}
|
|
1924
1923
|
case constants.CHARACTERISTIC:
|
|
1925
1924
|
{
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1925
|
+
rcDirective = isAccDirective( value, false );
|
|
1926
|
+
if ( rcDirective.accTypeEnumIndex == null )
|
|
1927
|
+
{
|
|
1928
|
+
rcDirective = isAccDirective( value, true );
|
|
1929
|
+
if ( rcDirective.accTypeEnumIndex == null )
|
|
1930
|
+
throw new Error( `No such polling characteristic: "${ value }" for: "${ this.displayName }".` );
|
|
1931
|
+
|
|
1932
|
+
this.log.warn( `1. The config.json Polling characteristic: ${ value } is Capitalized it should be: ${ rcDirective.type }. In the near future this will be an Error so that Cmd4 can use homebridge-ui.\nTo remove this Warning, Please fix your config.json.` );
|
|
1933
|
+
}
|
|
1934
|
+
accTypeEnumIndex = rcDirective.accTypeEnumIndex;
|
|
1931
1935
|
|
|
1932
|
-
characteristicString = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type;
|
|
1933
1936
|
// We can do this as this is a new way to do things.
|
|
1934
|
-
if ( this.getStoredValueForIndex( accTypeEnumIndex ) == undefined )
|
|
1935
|
-
throw new Error( `Polling for: "${ value }" requested, but characteristic is not in your config.json file for: "${ this.displayName }".` );
|
|
1937
|
+
if ( this.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex ) == undefined )
|
|
1938
|
+
throw new Error( `CCC Polling for: "${ value }" requested, but characteristic is not in your config.json file for: "${ this.displayName }".` );
|
|
1936
1939
|
|
|
1937
1940
|
break;
|
|
1938
1941
|
}
|
|
@@ -1948,9 +1951,10 @@ class Cmd4Accessory
|
|
|
1948
1951
|
// The key must be a characteristic property
|
|
1949
1952
|
// but first check if one has already been defined as we can only handle one at a time.
|
|
1950
1953
|
if ( accTypeEnumIndex != -1 )
|
|
1951
|
-
throw new Error( `For charateristic polling, you can only define one characteristic per array item.\nCannot add "${
|
|
1954
|
+
throw new Error( `For charateristic polling, you can only define one characteristic per array item.\nCannot add "${ key }" as "${ characteristicString }" is already defined for: ${ accessory.displayName }` );
|
|
1952
1955
|
|
|
1953
|
-
|
|
1956
|
+
// This checks both upper and lower case
|
|
1957
|
+
accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.indexOfEnum( key );
|
|
1954
1958
|
if ( accTypeEnumIndex < 0 )
|
|
1955
1959
|
throw new Error( `No such polling characteristic: "${ key }" for: "${ accessory.displayName }".` );
|
|
1956
1960
|
|
|
@@ -1963,8 +1967,10 @@ class Cmd4Accessory
|
|
|
1963
1967
|
{
|
|
1964
1968
|
this.queue = addQueue( this.log, "Q:" + this.displayName, constants.QUEUETYPE_STANDARD );
|
|
1965
1969
|
}
|
|
1970
|
+
// This has to be UC as it gets passed to the getValue cmd string
|
|
1971
|
+
let characteristicString = CMD4_ACC_TYPE_ENUM.accEnumIndexToUC( accTypeEnumIndex );
|
|
1966
1972
|
|
|
1967
|
-
if ( cmd4Dbg ) this.log.debug( `Setting up accessory: ${ accessory.displayName } for polling of: ${ characteristicString } timeout: ${ timeout } interval: ${ interval } queueName: "${ this.queue.queueName }"` );
|
|
1973
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Setting up accessory: ${ accessory.displayName } for polling of: ${ characteristicString } timeout: ${ timeout } interval: ${ interval } queueName: "${ this.queue.queueName }"` );
|
|
1968
1974
|
|
|
1969
1975
|
let record = { [ constants.ACCESSORY_lv ]: accessory, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: accTypeEnumIndex, [ constants.CHARACTERISTIC_STRING_lv ]: characteristicString, [ constants.INTERVAL_lv ]: interval, [ constants.TIMEOUT_lv ]: timeout, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: stateChangeResponseTime, [ constants.QUEUE_NAME_lv ]: this.queue.queueName };
|
|
1970
1976
|
|
|
@@ -1996,8 +2002,9 @@ class Cmd4Accessory
|
|
|
1996
2002
|
CMD4_DEVICE_TYPE_ENUM.properties[ accessory.typeIndex ].defaultPollingCharacteristics.forEach( defaultPollingAccTypeEnumIndex =>
|
|
1997
2003
|
{
|
|
1998
2004
|
|
|
1999
|
-
|
|
2000
|
-
let
|
|
2005
|
+
// This has to be UC as it gets passed to the getValue cmd string
|
|
2006
|
+
let characteristicString = CMD4_ACC_TYPE_ENUM.accEnumIndexToUC( defaultPollingAccTypeEnumIndex );
|
|
2007
|
+
let record = { [ constants.ACCESSORY_lv ]: accessory, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: defaultPollingAccTypeEnumIndex, [ constants.CHARACTERISTIC_STRING_lv ]: characteristicString, [ constants.INTERVAL_lv ]: interval, [ constants.TIMEOUT_lv ]: timeout, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: stateChangeResponseTime, [ constants.QUEUE_NAME_lv ]: this.queue.queueName };
|
|
2001
2008
|
|
|
2002
2009
|
// Used to determine missing related characteristics and
|
|
2003
2010
|
// to determine if the related characteristic is also polled.
|
|
@@ -2007,7 +2014,7 @@ class Cmd4Accessory
|
|
|
2007
2014
|
if ( accessory.polling == true )
|
|
2008
2015
|
{
|
|
2009
2016
|
|
|
2010
|
-
if ( cmd4Dbg ) this.log.debug( `Adding ${ record.accessory.displayName } ${ CMD4_ACC_TYPE_ENUM.properties[ record.accTypeEnumIndex ].type } record.timeout: ${ record.timeout } record.interval: ${ record.interval } to Polled Queue ${ record.queueName }` );
|
|
2017
|
+
if ( settings.cmd4Dbg ) this.log.debug( `Adding ${ record.accessory.displayName } ${ CMD4_ACC_TYPE_ENUM.properties[ record.accTypeEnumIndex ].type } record.timeout: ${ record.timeout } record.interval: ${ record.interval } to Polled Queue ${ record.queueName }` );
|
|
2011
2018
|
|
|
2012
2019
|
this.queue.addLowPriorityGetPolledQueueEntry(
|
|
2013
2020
|
record.accessory,
|
|
@@ -2039,8 +2046,8 @@ class Cmd4Accessory
|
|
|
2039
2046
|
)
|
|
2040
2047
|
{
|
|
2041
2048
|
|
|
2042
|
-
let characteristicString = CMD4_ACC_TYPE_ENUM.
|
|
2043
|
-
let relatedCharacteristicString = CMD4_ACC_TYPE_ENUM.
|
|
2049
|
+
let characteristicString = CMD4_ACC_TYPE_ENUM.accEnumIndexToLC( accTypeEnumIndex );
|
|
2050
|
+
let relatedCharacteristicString = CMD4_ACC_TYPE_ENUM.accEnumIndexToLC( relatedTargetAccTypeEnumIndex );
|
|
2044
2051
|
this.log.warn( `Warning, With polling for "${ characteristicString }" requested, you also must do polling of "${ relatedCharacteristicString }" or things will not function properly` );
|
|
2045
2052
|
}
|
|
2046
2053
|
}
|
|
@@ -2050,14 +2057,14 @@ class Cmd4Accessory
|
|
|
2050
2057
|
}
|
|
2051
2058
|
|
|
2052
2059
|
// Compare accessory's UUID with those already created for possible duplicates
|
|
2053
|
-
function checkAccessoryForDuplicateUUID( accessory,
|
|
2060
|
+
function checkAccessoryForDuplicateUUID( accessory, uuid )
|
|
2054
2061
|
{
|
|
2055
2062
|
// check for UUID+subtype conflict
|
|
2056
|
-
if ( cmd4Dbg ) accessory.log.debug( `Checking ${ accessory.name } for Duplicate UUID: ${ accessory.
|
|
2063
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( `Checking ${ accessory.name } for Duplicate UUID: ${ accessory.uuid }` );
|
|
2057
2064
|
|
|
2058
2065
|
for ( let existingAccessory in accessory.createdCmd4Accessories )
|
|
2059
2066
|
{
|
|
2060
|
-
if (
|
|
2067
|
+
if ( uuid == existingAccessory.uuid )
|
|
2061
2068
|
{
|
|
2062
2069
|
// This is the same check as what is in
|
|
2063
2070
|
// hap-nodejs/dist/lib/Accessory.js
|
|
@@ -2076,7 +2083,7 @@ function checkAccessoryForDuplicateUUID( accessory, UUID )
|
|
|
2076
2083
|
{
|
|
2077
2084
|
accessory.accessories.forEach( ( addedAccessory ) =>
|
|
2078
2085
|
{
|
|
2079
|
-
checkAccessoryForDuplicateUUID( addedAccessory,
|
|
2086
|
+
checkAccessoryForDuplicateUUID( addedAccessory, uuid );
|
|
2080
2087
|
});
|
|
2081
2088
|
}
|
|
2082
2089
|
|
|
@@ -2085,12 +2092,12 @@ function checkAccessoryForDuplicateUUID( accessory, UUID )
|
|
|
2085
2092
|
{
|
|
2086
2093
|
accessory.linkedAccessories.forEach( ( linkedAccessory ) =>
|
|
2087
2094
|
{
|
|
2088
|
-
checkAccessoryForDuplicateUUID( linkedAccessory,
|
|
2095
|
+
checkAccessoryForDuplicateUUID( linkedAccessory, uuid );
|
|
2089
2096
|
});
|
|
2090
2097
|
}
|
|
2091
2098
|
}
|
|
2092
2099
|
|
|
2093
|
-
if ( cmd4Dbg ) accessory.log.debug( `No Duplicate UUID's for this Accessory - ` + chalk.green( `OK` ) + `. Using: ${ accessory.
|
|
2100
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( `No Duplicate UUID's for this Accessory - ` + chalk.green( `OK` ) + `. Using: ${ accessory.uuid }` );
|
|
2094
2101
|
}
|
|
2095
2102
|
|
|
2096
2103
|
exports.Cmd4Accessory = Cmd4Accessory;
|