homebridge-cmd4 6.3.0 → 7.0.0
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 +31 -32
- package/Cmd4Accessory.js +19 -86
- package/Cmd4Platform.js +0 -55
- package/Cmd4PriorityPollingQueue.js +226 -75
- package/RUNNING_CHANGELOG.md +38 -0
- package/cmd4Constants.js +56 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
# Homebridges-cmd4 - CMD4 Plugin for Homebridge - Supports ~All Accessory Types and now all Characteristics too!!
|
|
2
|
-
|
|
2
|
+
#### 7.0.0 (2023-03-05)
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
* The reason for the major version numbering update was to for deprecation warnings to throw an error.
|
|
5
|
+
These warnings were there for many major versions and are finally removed.
|
|
6
|
+
|
|
7
|
+
"queueInterval" - Never put into production and will now throw an error.
|
|
8
|
+
"queueMsg" - Never put into production and will now throw an error.
|
|
9
|
+
"queueStatMsgInterval" - Never put into production and will now throw an error.
|
|
10
|
+
"cmd4_Mode" - Obsolete for many versions and will now throw an error.
|
|
11
|
+
"storage" - Obsolete outside of fakegato definition.
|
|
12
|
+
"storagePath" - Obsolete outside of fakegato definition.
|
|
13
|
+
"folder" - Obsolete outside of fakegato definition.
|
|
14
|
+
"keyPath" - Obsolete outside of fakegato definition.
|
|
15
|
+
"queueTypes" - Obsolete inside accessory definition.
|
|
5
16
|
|
|
6
|
-
* Bug [#130](https://github.com/ztalbot2000/homebridge-cmd4/pull/130), linked accessories not accesible after restart ([aeab5a40](https://github.com/ztalbot2000/homebridge-cmd4/commit/aeab5a40340631910ae6ac19f9af8453f46faa55))
|
|
7
17
|
|
|
8
18
|
##### New Features
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Assistant
|
|
28
|
-
AudioStreamManagement
|
|
29
|
-
Battery
|
|
30
|
-
CameraRecordingManagement
|
|
31
|
-
CloudRelay
|
|
32
|
-
DataStreamTransportManagement
|
|
33
|
-
NFCAccess
|
|
34
|
-
SiriEndpoint
|
|
35
|
-
ThreadTransport
|
|
36
|
-
|
|
37
|
-
Note: While these are now available to use. Some may not be suitable for Cmd4 depending on their complexity.
|
|
19
|
+
|
|
20
|
+
* add retries. Also formatting issues ([b8ddf9ce](https://github.com/ztalbot2000/homebridge-cmd4/commit/b8ddf9ceda8ace3a6e820bfad0c4a03c656cf419))
|
|
21
|
+
|
|
22
|
+
##### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* retry logging starts from zero, but for user count starts from 1 ([38cdf417](https://github.com/ztalbot2000/homebridge-cmd4/commit/38cdf417feebeef2b75dcfec247e6bdfd4739604))
|
|
25
|
+
* By nature retryCount should start from zero ([b8e82ffe](https://github.com/ztalbot2000/homebridge-cmd4/commit/b8e82ffe262c092a301636993544be828a7a34a4))
|
|
26
|
+
* log message in wrong quotes ([6fc555b0](https://github.com/ztalbot2000/homebridge-cmd4/commit/6fc555b0d7bdc20bfc3a38310e3d4f66b968d55d))
|
|
27
|
+
* retries for WoRm should be zero. Can be overriden ([11351633](https://github.com/ztalbot2000/homebridge-cmd4/commit/1135163319c8d16e3886dbf0a0443ba5ed6c4b99))
|
|
28
|
+
* Accessory needs to go unresponsive via updateValue with error object ([cdfee1b2](https://github.com/ztalbot2000/homebridge-cmd4/commit/cdfee1b22ea21dc56edc320768ec6ebea1156cb8))
|
|
29
|
+
|
|
30
|
+
##### Tests
|
|
31
|
+
|
|
32
|
+
* put back skipped tests ([0b0781fa](https://github.com/ztalbot2000/homebridge-cmd4/commit/0b0781faec7f94e43d67068e15e9505cc7c96414))
|
|
33
|
+
* Remove excess debug messages for commit with verify to work ([ea108470](https://github.com/ztalbot2000/homebridge-cmd4/commit/ea108470631f4abe3377f6d582c962dab141be0f))
|
|
34
|
+
* Don't know why HomeKit does not cause Cmd4 to generate a log that it is trying to reconnect after unavailable ([d45d7c09](https://github.com/ztalbot2000/homebridge-cmd4/commit/d45d7c095d0989c05b88c161a418402711e26677))
|
|
35
|
+
* Add unit testing to prove fix of bug[#130](https://github.com/ztalbot2000/homebridge-cmd4/pull/130) ([e9a902fc](https://github.com/ztalbot2000/homebridge-cmd4/commit/e9a902fcb01fb2ee7c7cb9f2b60e036d0fd5c0d6))
|
|
36
|
+
|
|
38
37
|
|
package/Cmd4Accessory.js
CHANGED
|
@@ -10,7 +10,7 @@ let Logger = require( "./utils/Logger" );
|
|
|
10
10
|
const { getAccessoryName, getAccessoryDisplayName
|
|
11
11
|
} = require( "./utils/getAccessoryNameFunctions" );
|
|
12
12
|
let getAccessoryUUID = require( "./utils/getAccessoryUUID" );
|
|
13
|
-
const { addQueue,
|
|
13
|
+
const { addQueue, queueExists } = require( "./Cmd4PriorityPollingQueue" );
|
|
14
14
|
|
|
15
15
|
// Hierarchy variables
|
|
16
16
|
let HV = require( "./utils/HV" );
|
|
@@ -127,6 +127,10 @@ class Cmd4Accessory
|
|
|
127
127
|
this.listOfVariables = { };
|
|
128
128
|
this.listOfConstants = { };
|
|
129
129
|
|
|
130
|
+
// Determines if the accessory is communicable
|
|
131
|
+
this.errorValue = 0;
|
|
132
|
+
this.errorString = "init";
|
|
133
|
+
|
|
130
134
|
// Used to determine missing related characteristics and
|
|
131
135
|
// to determine if the related characteristic is also polled.
|
|
132
136
|
this.listOfPollingCharacteristics = { };
|
|
@@ -1549,21 +1553,6 @@ class Cmd4Accessory
|
|
|
1549
1553
|
else
|
|
1550
1554
|
this.statusMsg = "FALSE";
|
|
1551
1555
|
|
|
1552
|
-
break;
|
|
1553
|
-
case "QueueStatMsgInterval":
|
|
1554
|
-
case "QueueMsg":
|
|
1555
|
-
|
|
1556
|
-
// Never put into production
|
|
1557
|
-
this.log.warn( `Warning: ${ key } has been deprecated. It was never even used.` );
|
|
1558
|
-
this.log.warn( `To remove this message, just remove ${ key } from your config.json` );
|
|
1559
|
-
|
|
1560
|
-
break;
|
|
1561
|
-
case constants.QUEUETYPES:
|
|
1562
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the accessory level. Please move it to where "Platform: "Cmd4" is located in your config.json.` );
|
|
1563
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
1564
|
-
|
|
1565
|
-
parseAddQueueTypes( this.log, value );
|
|
1566
|
-
|
|
1567
1556
|
break;
|
|
1568
1557
|
case constants.QUEUE:
|
|
1569
1558
|
{
|
|
@@ -1588,12 +1577,6 @@ class Cmd4Accessory
|
|
|
1588
1577
|
// Do not parse it yet as characteristics must be set first.
|
|
1589
1578
|
this.polling = value;
|
|
1590
1579
|
|
|
1591
|
-
break;
|
|
1592
|
-
case "Cmd4_Mode":
|
|
1593
|
-
case "cmd4_Mode":
|
|
1594
|
-
this.log.warn( `Warning: ${ key } has been deprecated.` );
|
|
1595
|
-
cmd4Mode = value;
|
|
1596
|
-
|
|
1597
1580
|
break;
|
|
1598
1581
|
case constants.INTERVAL:
|
|
1599
1582
|
// Intervals are in seconds
|
|
@@ -1621,34 +1604,6 @@ class Cmd4Accessory
|
|
|
1621
1604
|
// What this plugin is all about
|
|
1622
1605
|
this.state_cmd = value;
|
|
1623
1606
|
|
|
1624
|
-
break;
|
|
1625
|
-
case constants.STORAGE:
|
|
1626
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the Platform level. It was always meant to just be a fakegato config option only.` );
|
|
1627
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
1628
|
-
|
|
1629
|
-
this.storage = value;
|
|
1630
|
-
|
|
1631
|
-
break;
|
|
1632
|
-
case constants.STORAGEPATH:
|
|
1633
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the Platform level. It was always meant to just be a fakegato config option only.` );
|
|
1634
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
1635
|
-
|
|
1636
|
-
this.storagePath = value
|
|
1637
|
-
|
|
1638
|
-
break;
|
|
1639
|
-
case constants.FOLDER:
|
|
1640
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the Platform level. It was always meant to just be a fakegato config option only.` );
|
|
1641
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
1642
|
-
|
|
1643
|
-
this.folder = value
|
|
1644
|
-
|
|
1645
|
-
break;
|
|
1646
|
-
case constants.KEYPATH:
|
|
1647
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the Platform level. It was always meant to just be a fakegato config option only.` );
|
|
1648
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
1649
|
-
|
|
1650
|
-
this.keyPath = value
|
|
1651
|
-
|
|
1652
1607
|
break;
|
|
1653
1608
|
case constants.FAKEGATO:
|
|
1654
1609
|
// Do not parse it yet as characteristics must be set first.
|
|
@@ -1891,7 +1846,6 @@ class Cmd4Accessory
|
|
|
1891
1846
|
let interval = accessory.hV.interval;
|
|
1892
1847
|
let stateChangeResponseTime = accessory.hV.stateChangeResponseTime;
|
|
1893
1848
|
|
|
1894
|
-
|
|
1895
1849
|
// We need to create the listOfPollingCharacteristics, even in Demo mode because
|
|
1896
1850
|
// this list is also used to determine if the related characteristic should be set
|
|
1897
1851
|
// which happens in the Demo mode without polling.
|
|
@@ -1948,20 +1902,13 @@ class Cmd4Accessory
|
|
|
1948
1902
|
stateChangeResponseTime = value * 1000;
|
|
1949
1903
|
|
|
1950
1904
|
break;
|
|
1951
|
-
case constants.QUEUE:
|
|
1952
|
-
{
|
|
1953
|
-
if ( this.queue && this.queue.queueName != value )
|
|
1954
|
-
throw new Error( chalk.red( `Already defined Priority Polling Queue "${ this.queue.queueName }" for ${ this.displayName } cannot be redefined.` ) );
|
|
1955
|
-
|
|
1956
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the polling level. Please define it for the accessory: ${ this.displayName } as "queue": "${ value }"` );
|
|
1957
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
1958
|
-
|
|
1959
|
-
this.queue = addQueue( this.log, value, constants.QUEUETYPE_WORM );
|
|
1960
|
-
|
|
1961
|
-
break;
|
|
1962
|
-
}
|
|
1963
1905
|
case constants.CHARACTERISTIC:
|
|
1964
1906
|
{
|
|
1907
|
+
// The key must be a characteristic property
|
|
1908
|
+
// but first check if one has already been defined as we can only handle one at a time.
|
|
1909
|
+
if ( accTypeEnumIndex != -1 )
|
|
1910
|
+
throw new Error( `For charateristic polling, you can only define one characteristic per array item.\nCannot add "${ key }" as "${ value }" is already defined for: ${ accessory.displayName } ${accTypeEnumIndex}` );
|
|
1911
|
+
|
|
1965
1912
|
rcDirective = isAccDirective( value, false );
|
|
1966
1913
|
if ( rcDirective.accTypeEnumIndex == null )
|
|
1967
1914
|
{
|
|
@@ -1979,29 +1926,10 @@ class Cmd4Accessory
|
|
|
1979
1926
|
|
|
1980
1927
|
break;
|
|
1981
1928
|
}
|
|
1982
|
-
|
|
1983
|
-
{
|
|
1984
|
-
// WHY IS THIS HERE AT ALL ??????????
|
|
1985
|
-
|
|
1986
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the accessory level. Please move it to where "Platform: "Cmd4" is located in your config.json.` );
|
|
1987
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
1988
|
-
|
|
1989
|
-
parseAddQueueTypes( this.log, value );
|
|
1990
|
-
// This whole record is not a characteristic polling entry
|
|
1991
|
-
// continue to next ( via return )
|
|
1992
|
-
return;
|
|
1993
|
-
}
|
|
1994
|
-
default:
|
|
1929
|
+
default: // Switching polling key but key is unknown
|
|
1995
1930
|
{
|
|
1996
|
-
// The key must be a characteristic property
|
|
1997
|
-
// but first check if one has already been defined as we can only handle one at a time.
|
|
1998
|
-
if ( accTypeEnumIndex != -1 )
|
|
1999
|
-
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 }` );
|
|
2000
1931
|
|
|
2001
|
-
|
|
2002
|
-
accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.indexOfEnum( key );
|
|
2003
|
-
if ( accTypeEnumIndex < 0 )
|
|
2004
|
-
throw new Error( `No such polling characteristic: "${ key }" for: "${ accessory.displayName }".` );
|
|
1932
|
+
throw new Error( `No such polling characteristic: "${ key }" for: "${ accessory.displayName }".` );
|
|
2005
1933
|
|
|
2006
1934
|
}
|
|
2007
1935
|
}
|
|
@@ -2010,13 +1938,17 @@ class Cmd4Accessory
|
|
|
2010
1938
|
// Everything now goes through the queue
|
|
2011
1939
|
if ( this.queue == null )
|
|
2012
1940
|
{
|
|
2013
|
-
this.queue = addQueue( this.log, "Q:" + this.displayName, constants.QUEUETYPE_STANDARD );
|
|
1941
|
+
this.queue = addQueue( this.log, "Q:" + this.displayName, constants.QUEUETYPE_STANDARD, constants.DEFAULT_STANDARD_QUEUE_RETRY_COUNT );
|
|
2014
1942
|
}
|
|
2015
1943
|
// This has to be UC as it gets passed to the getValue cmd string
|
|
2016
1944
|
let characteristicString = CMD4_ACC_TYPE_ENUM.accEnumIndexToUC( accTypeEnumIndex );
|
|
2017
1945
|
|
|
2018
1946
|
if ( settings.cmd4Dbg ) this.log.debug( `Setting up accessory: ${ accessory.displayName } for polling of: ${ characteristicString } timeout: ${ timeout } interval: ${ interval } queueName: "${ this.queue.queueName }"` );
|
|
2019
1947
|
|
|
1948
|
+
if ( timeout == undefined )
|
|
1949
|
+
throw new Error( `determineCharacteristicsToPollForAccessory Timeout is undefined ` );
|
|
1950
|
+
|
|
1951
|
+
|
|
2020
1952
|
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 };
|
|
2021
1953
|
|
|
2022
1954
|
// Used to determine missing related characteristics and
|
|
@@ -2040,7 +1972,7 @@ class Cmd4Accessory
|
|
|
2040
1972
|
// which happens in the Demo mode without polling.
|
|
2041
1973
|
if ( this.queue == null )
|
|
2042
1974
|
{
|
|
2043
|
-
this.queue = addQueue( this.log, "Q:" + this.displayName, constants.QUEUETYPE_STANDARD );
|
|
1975
|
+
this.queue = addQueue( this.log, "Q:" + this.displayName, constants.QUEUETYPE_STANDARD, constants.DEFAULT_STANDARD_QUEUE_RETRY_COUNT );
|
|
2044
1976
|
}
|
|
2045
1977
|
|
|
2046
1978
|
// Make sure the defined characteristics will be polled
|
|
@@ -2049,6 +1981,7 @@ class Cmd4Accessory
|
|
|
2049
1981
|
|
|
2050
1982
|
// This has to be UC as it gets passed to the getValue cmd string
|
|
2051
1983
|
let characteristicString = CMD4_ACC_TYPE_ENUM.accEnumIndexToUC( defaultPollingAccTypeEnumIndex );
|
|
1984
|
+
|
|
2052
1985
|
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 };
|
|
2053
1986
|
|
|
2054
1987
|
// Used to determine missing related characteristics and
|
package/Cmd4Platform.js
CHANGED
|
@@ -237,70 +237,15 @@ class Cmd4Platform
|
|
|
237
237
|
case constants.OUTPUTCONSTANTS:
|
|
238
238
|
this.outputConstants = value;
|
|
239
239
|
|
|
240
|
-
break;
|
|
241
|
-
case "RestartRecover":
|
|
242
|
-
this.log.warn( `Warning: ${ key } has been deprecated. Not having restart recovery could mean your device would turn on/off over a restart; Therefore ${ key } is now always enabled.` );
|
|
243
|
-
this.log.warn( `To remove this message, just remove ${ key } from your config.json` );
|
|
244
240
|
break;
|
|
245
241
|
case constants.STATUSMSG:
|
|
246
242
|
if ( value === false )
|
|
247
243
|
this.statusMsg = "FALSE";
|
|
248
244
|
|
|
249
|
-
break;
|
|
250
|
-
case "QueueStatMsgInterval":
|
|
251
|
-
case "QueueMsg":
|
|
252
|
-
|
|
253
|
-
// Never put into production
|
|
254
|
-
this.log.warn( `Warning: ${ key } has been deprecated. It was never even used.` );
|
|
255
|
-
this.log.warn( `To remove this message, just remove ${ key } from your config.json` );
|
|
256
|
-
|
|
257
245
|
break;
|
|
258
246
|
case constants.QUEUETYPES:
|
|
259
247
|
parseAddQueueTypes( this.log, value );
|
|
260
248
|
|
|
261
|
-
break;
|
|
262
|
-
case "Cmd4_Mode":
|
|
263
|
-
case "cmd4_Mode":
|
|
264
|
-
this.log.warn( `Warning: ${ key } has been deprecated.` );
|
|
265
|
-
if ( value == "Demo" )
|
|
266
|
-
{
|
|
267
|
-
this.log.warn( `Demo mode is achieved when there is not any polling entries in your config.json.` );
|
|
268
|
-
} else
|
|
269
|
-
{
|
|
270
|
-
this.log.warn( `Cmd4 has been simplified and optimized as per: https://git.io/JtMGR.` );
|
|
271
|
-
}
|
|
272
|
-
this.log.warn( `To remove this message, just remove "${ key }" from your config.json` );
|
|
273
|
-
break;
|
|
274
|
-
case constants.STORAGE:
|
|
275
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the Platform level. It was always meant to just be a fakegato config option only.` );
|
|
276
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
277
|
-
|
|
278
|
-
if ( value == constants.FS || value == constants.GOOGLEDRIVEl )
|
|
279
|
-
this.storage = value;
|
|
280
|
-
else
|
|
281
|
-
this.log.warn( chalk.yellow( `WARNING` ) + `: Cmd4 Unknown platform.config.storage:{ this.storage } Expected:${ constants.FS } or ${ constants.GOOGLEDRIVE }` );
|
|
282
|
-
|
|
283
|
-
break;
|
|
284
|
-
case constants.STORAGEPATH:
|
|
285
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the Platform level. It was always meant to just be a fakegato config option only.` );
|
|
286
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
287
|
-
|
|
288
|
-
this.storagePath = value;
|
|
289
|
-
|
|
290
|
-
break;
|
|
291
|
-
case constants.FOLDER:
|
|
292
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the Platform level. It was always meant to just be a fakegato config option only.` );
|
|
293
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
294
|
-
|
|
295
|
-
this.folder = value;
|
|
296
|
-
|
|
297
|
-
break;
|
|
298
|
-
case constants.KEYPATH:
|
|
299
|
-
this.log.warn( `Warning: ${ key } will soon been deprecated at the Platform level. It was always meant to just be a fakegato config option only.` );
|
|
300
|
-
this.log.warn( `This message will disappear when you have done so.` );
|
|
301
|
-
|
|
302
|
-
this.keyPath = value;
|
|
303
|
-
|
|
304
249
|
break;
|
|
305
250
|
case constants.DEFINITIONS:
|
|
306
251
|
this.definitions = value;
|
|
@@ -31,7 +31,7 @@ let LOW_PRIORITY_GET = 2;
|
|
|
31
31
|
|
|
32
32
|
class Cmd4PriorityPollingQueue
|
|
33
33
|
{
|
|
34
|
-
constructor( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE )
|
|
34
|
+
constructor( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT )
|
|
35
35
|
{
|
|
36
36
|
this.log = log;
|
|
37
37
|
|
|
@@ -40,6 +40,7 @@ class Cmd4PriorityPollingQueue
|
|
|
40
40
|
|
|
41
41
|
this.queueName = queueName;
|
|
42
42
|
this.queueType = queueType;
|
|
43
|
+
this.queueRetryCount = queueRetryCount;
|
|
43
44
|
this.queueStarted = false;
|
|
44
45
|
this.highPriorityQueue = [ ];
|
|
45
46
|
this.lowPriorityQueue = [ ];
|
|
@@ -64,73 +65,121 @@ class Cmd4PriorityPollingQueue
|
|
|
64
65
|
// The WoRm queue needs error messages to be silenced as
|
|
65
66
|
// they are inevitable, but are handled through retries
|
|
66
67
|
// By default non WoRm queues are allowed to echo errors
|
|
67
|
-
|
|
68
|
+
|
|
69
|
+
if ( this.queueRetryCount == 0 || settings.debug )
|
|
70
|
+
this.echoE = true;
|
|
71
|
+
else
|
|
72
|
+
this.echoE = true;
|
|
68
73
|
|
|
69
74
|
this.changeQueueType( this, queueType );
|
|
70
75
|
}
|
|
71
76
|
|
|
72
|
-
|
|
77
|
+
echoRetryErrors( currentRetryCount )
|
|
78
|
+
{
|
|
79
|
+
// If debug then the default is true
|
|
80
|
+
if ( settings.cmd4Debug )
|
|
81
|
+
return true;
|
|
82
|
+
|
|
83
|
+
// Since this is the last retry, echo the error
|
|
84
|
+
if ( currentRetryCount == this.queueRetryCount )
|
|
85
|
+
return true;
|
|
86
|
+
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// This function is called by homebridge to *PUT AN ENTRY INTO THE HIGHEST PRIORITY SET QUEUE*.
|
|
91
|
+
// We immediately return success if the device is accessible. Either way the Set is attempted
|
|
92
|
+
// above everything else except other SetValue requests.
|
|
93
|
+
prioritySetValue( accTypeEnumIndex, characteristicString, timeout, stateChangeResponseTime, value, homebridgeCallback )
|
|
73
94
|
{
|
|
74
|
-
|
|
95
|
+
// this is Accessory
|
|
96
|
+
//
|
|
97
|
+
//if ( settings.cmd4Dbg ) this.log.debug(`prioritySetValue, asked to set: ${ characteristicString } to ${ value }`);
|
|
75
98
|
|
|
76
99
|
// Save the value to cache. The set will come later
|
|
77
|
-
|
|
78
|
-
callback( 0 );
|
|
100
|
+
// this.cmd4Storage.setStoredValueForIndex( accTypeEnumIndex, value );
|
|
79
101
|
|
|
80
|
-
|
|
102
|
+
if ( this.errorValue != 0 )
|
|
103
|
+
{
|
|
104
|
+
if ( settings.cmd4Dbg ) this.log.debug(`prioritySetValue for ${ this.displayName }, homebridgeCallback returning error ${ this.errorValue } ${ this.errorString }`);
|
|
105
|
+
homebridgeCallback( this.errorValue );
|
|
106
|
+
} else
|
|
107
|
+
{
|
|
108
|
+
if ( settings.cmd4Dbg ) this.log.debug(`prioritySetValue for ${ this.displayName }, homebridgeCallback returning default success 0`);
|
|
109
|
+
homebridgeCallback( 0 );
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let newEntry = { [ constants.IS_SET_lv ]: true, [ constants.ACCESSORY_lv ]: this, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: accTypeEnumIndex, [ constants.CHARACTERISTIC_STRING_lv ]: characteristicString, [ constants.TIMEOUT_lv ]: timeout, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: stateChangeResponseTime, [ constants.CALLBACK_lv ]: homebridgeCallback, [ constants.VALUE_lv ]: value };
|
|
81
113
|
|
|
82
114
|
// Determine where to put the entry in the queue
|
|
83
|
-
if (
|
|
115
|
+
if ( this.queue.highPriorityQueue.length == 0 )
|
|
84
116
|
{
|
|
85
117
|
// No entries, then it goes on top
|
|
86
|
-
|
|
118
|
+
this.queue.highPriorityQueue.push( newEntry );
|
|
87
119
|
|
|
88
120
|
} else {
|
|
89
121
|
|
|
90
122
|
// Make sure that this is the latest "Set" of this entry
|
|
91
|
-
let index =
|
|
123
|
+
let index = this.queue.highPriorityQueue.findIndex( ( entry ) => entry.accessory.uuid == this.uuid && entry.isSet == true && entry.accTypeEnumIndex == accTypeEnumIndex );
|
|
92
124
|
|
|
93
125
|
if ( index == -1 )
|
|
94
126
|
{
|
|
95
127
|
// It doesn't exist in the queue, It needs to be placed after any "Sets".
|
|
96
128
|
// First Determine the first "Get"
|
|
97
|
-
let getIndex =
|
|
129
|
+
let getIndex = this.queue.highPriorityQueue.findIndex( ( entry ) => entry.isSet == false );
|
|
98
130
|
|
|
99
131
|
if ( getIndex == -1 )
|
|
100
132
|
{
|
|
101
133
|
// No "Get" entrys, it goes at the end after everything.
|
|
102
|
-
|
|
134
|
+
this.queue.highPriorityQueue.push( newEntry );
|
|
103
135
|
|
|
104
136
|
} else
|
|
105
137
|
{
|
|
106
138
|
// Insert before the first "Get" entry
|
|
107
|
-
|
|
139
|
+
this.queue.highPriorityQueue.splice( getIndex, 0, newEntry );
|
|
108
140
|
}
|
|
109
141
|
} else
|
|
110
142
|
{
|
|
111
|
-
|
|
143
|
+
this.queue.highPriorityQueue[ index ] = newEntry;
|
|
112
144
|
}
|
|
113
145
|
}
|
|
114
|
-
|
|
146
|
+
this.queue.processQueueFunc( HIGH_PRIORITY_SET, this.queue );
|
|
115
147
|
}
|
|
116
148
|
|
|
117
|
-
|
|
149
|
+
// This function is called by homebridge to *PUT AN ENTRY INTO THE HIGHEST PRIORITY GET QUEUE*.
|
|
150
|
+
// We immediately return with success and the last known value if the device is accessible, otherwise
|
|
151
|
+
// the last failure error code.
|
|
152
|
+
// The Get is attempted no matter the devices availability. This is done after every Set
|
|
153
|
+
// request and at the bottom of the hightPrioritySetValue queue, but above any polling.
|
|
154
|
+
priorityGetValue( accTypeEnumIndex, characteristicString, timeout, homebridgeCallback )
|
|
118
155
|
{
|
|
119
|
-
|
|
156
|
+
// this is Accessory
|
|
157
|
+
|
|
158
|
+
// if ( settings.cmd4Dbg ) this.log.debug(`priorityGetValue for ${ this.displayName }, asked to Get: ${ characteristicString }`);
|
|
159
|
+
|
|
160
|
+
if ( this.errorValue != 0 )
|
|
161
|
+
{
|
|
162
|
+
// if ( settings.cmd4Dbg ) this.log.debug(`priorityGetValue for ${ this.displayName }, homebridgeCallback returning error ${ this.errorValue } ${ this.errorString}`);
|
|
163
|
+
homebridgeCallback( this.errorValue );
|
|
164
|
+
} else
|
|
165
|
+
{
|
|
166
|
+
// return the cached value
|
|
167
|
+
let storedValue = this.cmd4Storage.getStoredValueForIndex( accTypeEnumIndex );
|
|
120
168
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
169
|
+
// if ( settings.cmd4Dbg ) this.log.debug(`priorityGetValue for ${ this.displayName }, homebridgeCallback returning storedValue: ${ storedValue }`);
|
|
170
|
+
homebridgeCallback( 0, storedValue );
|
|
171
|
+
}
|
|
124
172
|
|
|
125
|
-
if (
|
|
173
|
+
if ( this.queue.queueType != constants.QUEUETYPE_WORM2 )
|
|
126
174
|
{
|
|
127
175
|
// When the value is returned, it will update homebridge
|
|
128
|
-
|
|
176
|
+
this.queue.highPriorityQueue.push( { [ constants.IS_SET_lv ]: false, [ constants.QUEUE_GET_IS_UPDATE_lv ]: true, [ constants.ACCESSORY_lv ]: this, [ constants.ACC_TYPE_ENUM_INDEX_lv ]: accTypeEnumIndex, [ constants.CHARACTERISTIC_STRING_lv ]: characteristicString, [ constants.TIMEOUT_lv ]: timeout, [ constants.STATE_CHANGE_RESPONSE_TIME_lv ]: null, [ constants.VALUE_lv ]: null, [ constants.CALLBACK_lv ]: homebridgeCallback } );
|
|
129
177
|
|
|
130
|
-
|
|
178
|
+
this.queue.processQueueFunc( HIGH_PRIORITY_GET, this.queue );
|
|
131
179
|
}
|
|
132
180
|
}
|
|
133
181
|
|
|
182
|
+
// This function is called by polling to *PUT AN ENTRY INTO THE LOW PRIORITY POLLING QUEUE*.
|
|
134
183
|
addLowPriorityGetPolledQueueEntry( accessory, accTypeEnumIndex, characteristicString, interval, timeout )
|
|
135
184
|
{
|
|
136
185
|
// These are all gets from polling
|
|
@@ -148,8 +197,14 @@ class Cmd4PriorityPollingQueue
|
|
|
148
197
|
|
|
149
198
|
let queue = entry.accessory.queue;
|
|
150
199
|
|
|
200
|
+
// Save the error code - Pass or fail
|
|
201
|
+
entry.accessory.errorValue = error;
|
|
202
|
+
|
|
151
203
|
if ( error == 0 )
|
|
152
204
|
{
|
|
205
|
+
// Now that the set was successful, store the value
|
|
206
|
+
entry.accessory.cmd4Storage.setStoredValueForIndex( entry.accTypeEnumIndex, entry.value );
|
|
207
|
+
|
|
153
208
|
// Since the "Set" passed, do the stateChangeResponseTime
|
|
154
209
|
setTimeout( ( ) =>
|
|
155
210
|
{
|
|
@@ -183,18 +238,37 @@ class Cmd4PriorityPollingQueue
|
|
|
183
238
|
|
|
184
239
|
} else // setValue failed
|
|
185
240
|
{
|
|
186
|
-
|
|
187
241
|
// The "Set" is complete, even if it failed.
|
|
188
242
|
queue.inProgressSets --;
|
|
189
243
|
|
|
190
|
-
|
|
191
|
-
queue.highPriorityQueue.push( entry );
|
|
244
|
+
let currentRetryCount = queue.errorCountSinceLastGoodTransaction;
|
|
192
245
|
|
|
193
|
-
queue.
|
|
194
|
-
|
|
246
|
+
if ( currentRetryCount >= queue.queueRetryCount )
|
|
247
|
+
{
|
|
248
|
+
if ( queue.echoRetryErrors( currentRetryCount ) )
|
|
249
|
+
{
|
|
250
|
+
// Counting starts from zero, i.e queueRetries = 0, so add 1
|
|
251
|
+
queue.log.warn( `*${ currentRetryCount + 1 }* error(s) were encountered for "${ entry.accessory.displayName }" getValue. Last error found Getting: "${ entry.characteristicString}". Perhaps you should run in debug mode to find out what the problem might be.` );
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Convert the errorValue into an errorString
|
|
255
|
+
entry.accessory.errorString = new Error( constants.errorString( error ) );
|
|
256
|
+
|
|
257
|
+
// This does not work - Nothing happens to HomeKit !
|
|
258
|
+
// queue.log.warn( `START processHighPrioritySetQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue} errorString: ${ entry.accessory.errorString }`);
|
|
259
|
+
// entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( entry.accessory.errorString );
|
|
260
|
+
// queue.log.warn( `END processHighPrioritySetQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue} errorString: ${ entry.accessory.errorString }`);
|
|
195
261
|
|
|
196
|
-
|
|
197
|
-
|
|
262
|
+
|
|
263
|
+
} else
|
|
264
|
+
{
|
|
265
|
+
// Increment the errorCount/currentRetryCount
|
|
266
|
+
queue.errorCountSinceLastGoodTransaction++;
|
|
267
|
+
|
|
268
|
+
// Set failed. We need to keep trying
|
|
269
|
+
queue.highPriorityQueue.push( entry );
|
|
270
|
+
|
|
271
|
+
}
|
|
198
272
|
|
|
199
273
|
entry.accessory.queue.pauseQueue( entry.accessory.queue );
|
|
200
274
|
}
|
|
@@ -204,7 +278,7 @@ class Cmd4PriorityPollingQueue
|
|
|
204
278
|
// created.
|
|
205
279
|
|
|
206
280
|
// Note 2.
|
|
207
|
-
// We cannot release the queue for further processing as the
|
|
281
|
+
// We cannot release the queue for further processing as the
|
|
208
282
|
// statechangeResponseTime has not completed. This must be
|
|
209
283
|
// done first or any next "Get" or "Set" would interfere
|
|
210
284
|
// with the device
|
|
@@ -222,28 +296,50 @@ class Cmd4PriorityPollingQueue
|
|
|
222
296
|
{
|
|
223
297
|
let queue = entry.accessory.queue;
|
|
224
298
|
|
|
299
|
+
// Save the error code - Pass or fail
|
|
300
|
+
entry.accessory.errorValue = error;
|
|
301
|
+
|
|
225
302
|
// Nothing special was done for casing on errors, so omit it.
|
|
226
303
|
if ( error == 0 )
|
|
227
304
|
{
|
|
228
|
-
|
|
305
|
+
// Save the new returned value
|
|
306
|
+
entry.accessory.cmd4Storage.setStoredValueForIndex( entry.accTypeEnumIndex, properValue );
|
|
307
|
+
|
|
308
|
+
// hmmm if ( entry.queueGetIsUpdate == true )
|
|
229
309
|
entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( properValue );
|
|
230
310
|
|
|
231
311
|
// A good anything, updates the lastGoodTransactionTime
|
|
232
312
|
queue.lastGoodTransactionTime = Date.now( );
|
|
233
313
|
queue.errorCountSinceLastGoodTransaction = 0;
|
|
234
314
|
|
|
235
|
-
} else // getValue failed
|
|
315
|
+
} else // highPriority getValue failed
|
|
236
316
|
{
|
|
237
|
-
// High Priority Get failed. We need to keep trying (WoRm queue only )
|
|
238
|
-
if ( queue.queueType == constants.QUEUETYPE_WORM ||
|
|
239
|
-
queue.queueType == constants.QUEUETYPE_WORM2
|
|
240
|
-
)
|
|
241
|
-
queue.highPriorityQueue.push( entry );
|
|
242
317
|
|
|
243
|
-
queue.errorCountSinceLastGoodTransaction
|
|
244
|
-
|
|
245
|
-
if (
|
|
246
|
-
|
|
318
|
+
let currentRetryCount = queue.errorCountSinceLastGoodTransaction;
|
|
319
|
+
|
|
320
|
+
if ( currentRetryCount >= queue.queueRetryCount )
|
|
321
|
+
{
|
|
322
|
+
if ( queue.echoRetryErrors( currentRetryCount ) )
|
|
323
|
+
queue.log.warn( `*${ currentRetryCount + 1}* error(s) were encountered for "${ entry.accessory.displayName }" getValue. Last error found Getting: "${ entry.characteristicString}". Perhaps you should run in debug mode to find out what the problem might be.` );
|
|
324
|
+
|
|
325
|
+
// Convert the errorValue into an errorString
|
|
326
|
+
entry.accessory.errorString = new Error( constants.errorString( error ) );
|
|
327
|
+
|
|
328
|
+
// This does not work - Nothing happens to HomeKit !
|
|
329
|
+
// queue.log.warn( `START processHighPriorityGetQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue} errorString: ${ entry.accessory.errorString }`);
|
|
330
|
+
// entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( entry.accessory.errorString );
|
|
331
|
+
// queue.log.warn( `END processHighPriorityGetQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue} errorString: ${ entry.accessory.errorString }`);
|
|
332
|
+
|
|
333
|
+
} else
|
|
334
|
+
{
|
|
335
|
+
// Increment the errorCount/currentRetryCount
|
|
336
|
+
queue.errorCountSinceLastGoodTransaction++;
|
|
337
|
+
|
|
338
|
+
// High Priority Get failed. We keep retrying until the mod of
|
|
339
|
+
// queueRetryCount reaches zero, which is WoRm only as it has more than 1
|
|
340
|
+
// default retry count.
|
|
341
|
+
queue.highPriorityQueue.push( entry );
|
|
342
|
+
}
|
|
247
343
|
|
|
248
344
|
entry.accessory.queue.pauseQueue( entry.accessory.queue );
|
|
249
345
|
}
|
|
@@ -254,6 +350,7 @@ class Cmd4PriorityPollingQueue
|
|
|
254
350
|
});
|
|
255
351
|
}
|
|
256
352
|
|
|
353
|
+
// This is called from polling
|
|
257
354
|
processEntryFromLowPriorityQueue( entry )
|
|
258
355
|
{
|
|
259
356
|
if ( settings.cmd4Dbg ) this.log.debug( `Processing low priority queue entry: ${ entry.accTypeEnumIndex }` );
|
|
@@ -268,20 +365,39 @@ class Cmd4PriorityPollingQueue
|
|
|
268
365
|
// For the next one
|
|
269
366
|
queue.inProgressGets --;
|
|
270
367
|
|
|
368
|
+
// Save the error code - Pass or fail
|
|
369
|
+
entry.accessory.errorValue = error;
|
|
370
|
+
|
|
271
371
|
// Nothing special was done for casing on errors, so omit it.
|
|
272
372
|
if ( error == 0 )
|
|
273
373
|
{
|
|
374
|
+
// Save the new value
|
|
375
|
+
entry.accessory.cmd4Storage.setStoredValueForIndex( entry.accTypeEnumIndex, properValue );
|
|
376
|
+
|
|
377
|
+
// Update the new value in homebridge
|
|
378
|
+
entry.accessory.log.warn( `processEntryFromLowPriorityQueue calling updateValue properValue: ${ properValue }`);
|
|
274
379
|
entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( properValue );
|
|
275
380
|
|
|
276
381
|
// A good anything, updates the lastGoodTransactionTime
|
|
277
382
|
queue.lastGoodTransactionTime = Date.now( );
|
|
278
383
|
queue.errorCountSinceLastGoodTransaction = 0;
|
|
279
384
|
|
|
280
|
-
} else {
|
|
385
|
+
} else { // LowPriority getValue failed
|
|
386
|
+
queue.errorCountSinceLastGoodTransaction++;
|
|
387
|
+
|
|
388
|
+
// Convert the errorValue into an errorString
|
|
389
|
+
entry.accessory.errorString = new Error( constants.errorString( error ));
|
|
390
|
+
|
|
391
|
+
// This does not work - Nothing happens to HomeKit !
|
|
392
|
+
// Call updateValue with new Error so device will become unavailable
|
|
393
|
+
// queue.log.warn( `START processEntryFromLowPriorityQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue } errorString: ${ entry.accessory.errorString }`);
|
|
394
|
+
// entry.accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ entry.accTypeEnumIndex ].characteristic ).updateValue( entry.accessory.errorString );
|
|
395
|
+
// queue.log.warn( `END processEntryFromLowPriorityQueue calling updateCharacteristic errorValue: ${ entry.accessory.errorValue } errorString: ${ entry.accessory.errorString }`);
|
|
396
|
+
|
|
281
397
|
queue.pauseQueue( entry.accessory.queue );
|
|
282
398
|
}
|
|
283
399
|
|
|
284
|
-
// Now that this one has been processed, schedule it again
|
|
400
|
+
// Now that this one has been processed, schedule it again for next time
|
|
285
401
|
queue.scheduleLowPriorityEntry( entry )
|
|
286
402
|
|
|
287
403
|
});
|
|
@@ -477,7 +593,7 @@ class Cmd4PriorityPollingQueue
|
|
|
477
593
|
//
|
|
478
594
|
// - Where he value in <> is an one of CMD4_ACC_TYPE_ENUM
|
|
479
595
|
// ***********************************************
|
|
480
|
-
qSetValue( accessory, accTypeEnumIndex, characteristicString, timeout, value,
|
|
596
|
+
qSetValue( accessory, accTypeEnumIndex, characteristicString, timeout, value, queueCallback )
|
|
481
597
|
{
|
|
482
598
|
let self = accessory;
|
|
483
599
|
let queue = accessory.queue;
|
|
@@ -515,17 +631,17 @@ class Cmd4PriorityPollingQueue
|
|
|
515
631
|
{
|
|
516
632
|
if ( queue.echoE ) self.log.error( chalk.red( `setValue ${ characteristicString } function failed for ${ self.displayName } cmd: ${ cmd } Failed. Error: ${ code } ${ constants.DBUSY }` ) );
|
|
517
633
|
|
|
518
|
-
|
|
634
|
+
queueCallback( constants.ERROR_TIMER_EXPIRED );
|
|
519
635
|
|
|
520
636
|
return;
|
|
521
637
|
}
|
|
522
638
|
|
|
523
|
-
|
|
639
|
+
queueCallback( code );
|
|
524
640
|
|
|
525
641
|
return;
|
|
526
642
|
}
|
|
527
643
|
|
|
528
|
-
|
|
644
|
+
queueCallback( code );
|
|
529
645
|
|
|
530
646
|
});
|
|
531
647
|
}
|
|
@@ -537,13 +653,21 @@ class Cmd4PriorityPollingQueue
|
|
|
537
653
|
{
|
|
538
654
|
// "WoRm", No matter what, only one "Set" allowed
|
|
539
655
|
if ( queue.inProgressSets > 0 )
|
|
656
|
+
{
|
|
657
|
+
// if ( settings.cmd4Dbg ) queue.log.debug(`processWormQueue queue.inProgressSets > 0 : ${queue.inProgressSets}`);
|
|
658
|
+
|
|
540
659
|
// We are *NOT* processing the low prioirity queue entry
|
|
541
660
|
return false;
|
|
661
|
+
}
|
|
542
662
|
|
|
543
663
|
// It is not a good time to do a anything, so skip it
|
|
544
664
|
if ( queue.lastGoodTransactionTime == 0 )
|
|
665
|
+
{
|
|
666
|
+
// if ( settings.cmd4Dbg ) queue.log.debug(`processWormQueue queue.lastGoodTransactionTime == 0`);
|
|
667
|
+
|
|
545
668
|
// We are *NOT* processing the low prioirity queue entry
|
|
546
669
|
return false;
|
|
670
|
+
}
|
|
547
671
|
|
|
548
672
|
if ( queue.highPriorityQueue.length > 0 )
|
|
549
673
|
{
|
|
@@ -556,9 +680,13 @@ class Cmd4PriorityPollingQueue
|
|
|
556
680
|
// cannot be run with an entry already in progress.
|
|
557
681
|
if ( nextEntry.accessory.queue.inProgressSets > 0 ||
|
|
558
682
|
nextEntry.accessory.queue.inProgressGets > 0 )
|
|
683
|
+
{
|
|
559
684
|
// Return as queue is busy.
|
|
560
685
|
// Return false as we are *NOT* processing the low prioirity queue entry
|
|
686
|
+
// if ( settings.cmd4Dbg ) queue.log.debug(`processWormQueue queue.inProgressSets> 0 ${ nextEntry.accessory.queue.inProgressSets } ${ nextEntry.accessory.queue.inProgressGets }`);
|
|
687
|
+
|
|
561
688
|
return false;
|
|
689
|
+
}
|
|
562
690
|
|
|
563
691
|
queue.processHighPrioritySetQueue( queue.highPriorityQueue.shift( ) );
|
|
564
692
|
|
|
@@ -695,7 +823,9 @@ class Cmd4PriorityPollingQueue
|
|
|
695
823
|
if ( lastTransactionType == LOW_PRIORITY_GET &&
|
|
696
824
|
lowPriorityEntry != null &&
|
|
697
825
|
queue.queueStarted == true )
|
|
826
|
+
{
|
|
698
827
|
queue.processEntryFromLowPriorityQueue( lowPriorityEntry );
|
|
828
|
+
}
|
|
699
829
|
|
|
700
830
|
if ( queue.highPriorityQueue.length > 0 )
|
|
701
831
|
{
|
|
@@ -711,22 +841,22 @@ class Cmd4PriorityPollingQueue
|
|
|
711
841
|
|
|
712
842
|
scheduleLowPriorityEntry( entry )
|
|
713
843
|
{
|
|
714
|
-
let
|
|
844
|
+
let accessory = entry.accessory;
|
|
715
845
|
let queue = entry.accessory.queue;
|
|
716
846
|
|
|
717
|
-
if ( settings.cmd4Dbg )
|
|
847
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( `Scheduling Poll of index: ${ entry.accTypeEnumIndex } characteristic: ${ entry.characteristicString } for: ${ accessory.displayName } timeout: ${ entry.timeout } interval: ${ entry.interval }` );
|
|
718
848
|
|
|
719
849
|
// Clear polling
|
|
720
850
|
if ( queue.listOfRunningPolls &&
|
|
721
|
-
queue.listOfRunningPolls[
|
|
722
|
-
clearTimeout( queue.listOfRunningPolls[
|
|
851
|
+
queue.listOfRunningPolls[ accessory.displayName + entry.accTypeEnumIndex ] == undefined )
|
|
852
|
+
clearTimeout( queue.listOfRunningPolls[ accessory.displayName + entry.accTypeEnumIndex ] );
|
|
723
853
|
|
|
724
|
-
queue.listOfRunningPolls[
|
|
854
|
+
queue.listOfRunningPolls[ accessory.displayName + entry.accTypeEnumIndex ] = setTimeout( ( ) =>
|
|
725
855
|
{
|
|
726
856
|
// If the queue was busy/not available, schedule the entry at a later time
|
|
727
857
|
if ( queue.processQueueFunc( LOW_PRIORITY_GET, queue, entry ) == false )
|
|
728
858
|
{
|
|
729
|
-
if ( settings.cmd4Dbg )
|
|
859
|
+
if ( settings.cmd4Dbg ) accessory.log.debug( `processsQueue returned false` );
|
|
730
860
|
|
|
731
861
|
queue.scheduleLowPriorityEntry( entry );
|
|
732
862
|
}
|
|
@@ -803,12 +933,17 @@ class Cmd4PriorityPollingQueue
|
|
|
803
933
|
setTimeout( ( ) =>
|
|
804
934
|
{
|
|
805
935
|
if ( entryIndex == 0 && settings.cmd4Dbg )
|
|
936
|
+
{
|
|
806
937
|
if ( queue.queueType == constants.QUEUETYPE_WORM ||
|
|
807
938
|
queue.queueType == constants.QUEUETYPE_WORM2
|
|
808
939
|
)
|
|
940
|
+
{
|
|
809
941
|
entry.accessory.log.debug( `Started staggered kick off of ${ queue.lowPriorityQueue.length } polled characteristics for queue: "${ entry.accessory.queue.queueName }"` );
|
|
810
|
-
else
|
|
942
|
+
} else
|
|
943
|
+
{
|
|
811
944
|
entry.accessory.log.debug( `Started staggered kick off of ${ queue.lowPriorityQueue.length } polled characteristics for "${ entry.accessory.displayName }"` );
|
|
945
|
+
}
|
|
946
|
+
}
|
|
812
947
|
|
|
813
948
|
if ( settings.cmd4Dbg ) entry.accessory.log.debug( `Kicking off polling for: ${ entry.accessory.displayName } ${ entry.characteristicString } interval:${ entry.interval }, staggered:${ staggeredDelays[ staggeredDelayIndex ] }` );
|
|
814
949
|
|
|
@@ -817,12 +952,18 @@ class Cmd4PriorityPollingQueue
|
|
|
817
952
|
if ( entryIndex == queue.lowPriorityQueue.length -1 )
|
|
818
953
|
{
|
|
819
954
|
if ( settings.cmd4Dbg )
|
|
955
|
+
{
|
|
820
956
|
if ( queue.queueType == constants.QUEUETYPE_WORM ||
|
|
821
957
|
queue.queueType == constants.QUEUETYPE_WORM2
|
|
822
958
|
)
|
|
959
|
+
{
|
|
823
960
|
entry.accessory.log.debug( `All characteristics are now being polled for queue: "${ queue.queueName }"` );
|
|
961
|
+
}
|
|
824
962
|
else
|
|
963
|
+
{
|
|
825
964
|
entry.accessory.log.debug( `All characteristics are now being polled for "${ entry.accessory.displayName }"` );
|
|
965
|
+
}
|
|
966
|
+
}
|
|
826
967
|
allDoneCallback( allDoneCount );
|
|
827
968
|
}
|
|
828
969
|
|
|
@@ -901,15 +1042,15 @@ var queueExists = function( queueName )
|
|
|
901
1042
|
return settings.listOfCreatedPriorityQueues[ queueName ];
|
|
902
1043
|
}
|
|
903
1044
|
|
|
904
|
-
var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE )
|
|
1045
|
+
var addQueue = function( log, queueName, queueType = constants.DEFAULT_QUEUE_TYPE, queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT )
|
|
905
1046
|
{
|
|
906
1047
|
let queue = queueExists( queueName );
|
|
907
1048
|
if ( queue != undefined )
|
|
908
1049
|
return queue;
|
|
909
1050
|
|
|
910
|
-
log.debug( `Creating new Priority Polled Queue "${ queueName }" with QueueType of: "${ queueType }"` );
|
|
1051
|
+
log.debug( `Creating new Priority Polled Queue "${ queueName }" with QueueType of: "${ queueType }" retryCount: ${queueRetryCount}` );
|
|
911
1052
|
|
|
912
|
-
queue = new Cmd4PriorityPollingQueue( log, queueName, queueType );
|
|
1053
|
+
queue = new Cmd4PriorityPollingQueue( log, queueName, queueType, queueRetryCount );
|
|
913
1054
|
settings.listOfCreatedPriorityQueues[ queueName ] = queue;
|
|
914
1055
|
|
|
915
1056
|
return queue;
|
|
@@ -927,6 +1068,7 @@ var parseAddQueueTypes = function ( log, entrys )
|
|
|
927
1068
|
{
|
|
928
1069
|
let queueName = null;
|
|
929
1070
|
let queueType = constants.DEFAULT_QUEUE_TYPE;
|
|
1071
|
+
let queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT;
|
|
930
1072
|
|
|
931
1073
|
for ( let key in entry )
|
|
932
1074
|
{
|
|
@@ -950,25 +1092,33 @@ var parseAddQueueTypes = function ( log, entrys )
|
|
|
950
1092
|
|
|
951
1093
|
break;
|
|
952
1094
|
case constants.QUEUETYPE:
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
value != constants.QUEUETYPE_SEQUENTIAL )
|
|
1095
|
+
// Set the default Queue Retry Count based on QueueType
|
|
1096
|
+
switch ( value )
|
|
956
1097
|
{
|
|
957
|
-
|
|
1098
|
+
case constants.QUEUETYPE_WORM:
|
|
1099
|
+
queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT;
|
|
1100
|
+
queueType = value;
|
|
1101
|
+
break;
|
|
1102
|
+
case constants.QUEUETYPE_WORM2:
|
|
1103
|
+
queueRetryCount = constants.DEFAULT_WORM_QUEUE_RETRY_COUNT;
|
|
1104
|
+
queueType = value;
|
|
1105
|
+
break;
|
|
1106
|
+
case constants.QUEUETYPE_SEQUENTIAL:
|
|
1107
|
+
queueRetryCount = constants.DEFAULT_STANDARD_QUEUE_RETRY_COUNT;
|
|
1108
|
+
queueType = value;
|
|
1109
|
+
break;
|
|
1110
|
+
case constants.QUEUETYPE_STANDARD:
|
|
1111
|
+
queueRetryCount = constants.DEFAULT_STANDARD_QUEUE_RETRY_COUNT;
|
|
1112
|
+
queueType = value;
|
|
1113
|
+
break;
|
|
1114
|
+
default:
|
|
1115
|
+
throw new Error( `QueueType: ${ entry.queueType } is not valid at index: ${ entryIndex }. Expected: ${ constants.QUEUETYPE_WORM }, ${ constants.QUEUETYPE_WORM2 } or ${ constants.QUEUETYPE_SEQUENTIAL }` );
|
|
958
1116
|
}
|
|
959
1117
|
|
|
960
|
-
queueType = value;
|
|
961
|
-
|
|
962
1118
|
break;
|
|
963
|
-
case
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
// Never put into production
|
|
968
|
-
log.warn( `Warning: ${ key } has been deprecated. It was never really used anyway.` );
|
|
969
|
-
log.warn( `To remove this message, just remove ${ key } from your config.json` );
|
|
970
|
-
|
|
971
|
-
break;
|
|
1119
|
+
case constants.QUEUE_RETRIES:
|
|
1120
|
+
queueRetryCount = value;
|
|
1121
|
+
break;
|
|
972
1122
|
default:
|
|
973
1123
|
throw new Error( `Unknown Queue option"${ key } not provided at index ${ entryIndex }` );
|
|
974
1124
|
}
|
|
@@ -978,8 +1128,9 @@ var parseAddQueueTypes = function ( log, entrys )
|
|
|
978
1128
|
if ( queueName == null )
|
|
979
1129
|
throw new Error( `"${ constants.QUEUE }" not provided at index ${ entryIndex }` );
|
|
980
1130
|
|
|
981
|
-
if ( settings.cmd4Dbg ) log.debug( `calling addQueue: ${ queueName } type: ${ queueType }` );
|
|
982
|
-
|
|
1131
|
+
if ( settings.cmd4Dbg ) log.debug( `calling addQueue: ${ queueName } type: ${ queueType } retryCount: ${ queueRetryCount }` );
|
|
1132
|
+
|
|
1133
|
+
addQueue( log, queueName, queueType, queueRetryCount );
|
|
983
1134
|
} );
|
|
984
1135
|
}
|
|
985
1136
|
|
package/RUNNING_CHANGELOG.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
## Homebridge UI User. Do not click on any inline links. Homebridge UI does not supprt them. Bug#1098
|
|
4
4
|
|
|
5
5
|
## ChangeLog
|
|
6
|
+
* <a href="#Whats-new-in-6-3-1">**Whats new in 7.0.0**</a>
|
|
6
7
|
* <a href="#Whats-new-in-6-3-0">**Whats new in 6.3.0**</a>
|
|
7
8
|
* <a href="#Whats-new-in-6-2-0">**Whats new in 6.2.0**</a>
|
|
8
9
|
* <a href="#Whats-new-in-6-1-2">**Whats new in 6.1.2**</a>
|
|
@@ -84,6 +85,43 @@
|
|
|
84
85
|
* <a href="#Whats-new-in-2-1">**Whats new in 2.1**</a>
|
|
85
86
|
* <a href="#Whats-new-in-2-0">**Whats new in 2.0**</a>
|
|
86
87
|
|
|
88
|
+
<a name="Whats-new-in-6-3-1">## Whats new in 6.3.1</a>
|
|
89
|
+
#### 7.0.0 (2023-03-05)
|
|
90
|
+
|
|
91
|
+
* The reason for the major version numbering update was to for deprecation warnings to throw an error.
|
|
92
|
+
These warnings were there for many major versions and are finally removed.
|
|
93
|
+
|
|
94
|
+
"queueInterval" - Never put into production and will now throw an error.
|
|
95
|
+
"queueMsg" - Never put into production and will now throw an error.
|
|
96
|
+
"queueStatMsgInterval" - Never put into production and will now throw an error.
|
|
97
|
+
"cmd4_Mode" - Obsolete for many versions and will now throw an error.
|
|
98
|
+
"storage" - Obsolete outside of fakegato definition.
|
|
99
|
+
"storagePath" - Obsolete outside of fakegato definition.
|
|
100
|
+
"folder" - Obsolete outside of fakegato definition.
|
|
101
|
+
"keyPath" - Obsolete outside of fakegato definition.
|
|
102
|
+
"queueTypes" - Obsolete inside accessory definition.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
##### New Features
|
|
106
|
+
|
|
107
|
+
* add retries. Also formatting issues ([b8ddf9ce](https://github.com/ztalbot2000/homebridge-cmd4/commit/b8ddf9ceda8ace3a6e820bfad0c4a03c656cf419))
|
|
108
|
+
|
|
109
|
+
##### Bug Fixes
|
|
110
|
+
|
|
111
|
+
* retry logging starts from zero, but for user count starts from 1 ([38cdf417](https://github.com/ztalbot2000/homebridge-cmd4/commit/38cdf417feebeef2b75dcfec247e6bdfd4739604))
|
|
112
|
+
* By nature retryCount should start from zero ([b8e82ffe](https://github.com/ztalbot2000/homebridge-cmd4/commit/b8e82ffe262c092a301636993544be828a7a34a4))
|
|
113
|
+
* log message in wrong quotes ([6fc555b0](https://github.com/ztalbot2000/homebridge-cmd4/commit/6fc555b0d7bdc20bfc3a38310e3d4f66b968d55d))
|
|
114
|
+
* retries for WoRm should be zero. Can be overriden ([11351633](https://github.com/ztalbot2000/homebridge-cmd4/commit/1135163319c8d16e3886dbf0a0443ba5ed6c4b99))
|
|
115
|
+
* Accessory needs to go unresponsive via updateValue with error object ([cdfee1b2](https://github.com/ztalbot2000/homebridge-cmd4/commit/cdfee1b22ea21dc56edc320768ec6ebea1156cb8))
|
|
116
|
+
|
|
117
|
+
##### Tests
|
|
118
|
+
|
|
119
|
+
* put back skipped tests ([0b0781fa](https://github.com/ztalbot2000/homebridge-cmd4/commit/0b0781faec7f94e43d67068e15e9505cc7c96414))
|
|
120
|
+
* Remove excess debug messages for commit with verify to work ([ea108470](https://github.com/ztalbot2000/homebridge-cmd4/commit/ea108470631f4abe3377f6d582c962dab141be0f))
|
|
121
|
+
* Don't know why HomeKit does not cause Cmd4 to generate a log that it is trying to reconnect after unavailable ([d45d7c09](https://github.com/ztalbot2000/homebridge-cmd4/commit/d45d7c095d0989c05b88c161a418402711e26677))
|
|
122
|
+
* Add unit testing to prove fix of bug[#130](https://github.com/ztalbot2000/homebridge-cmd4/pull/130) ([e9a902fc](https://github.com/ztalbot2000/homebridge-cmd4/commit/e9a902fcb01fb2ee7c7cb9f2b60e036d0fd5c0d6))
|
|
123
|
+
|
|
124
|
+
|
|
87
125
|
<a name="Whats-new-in-6-3-0">## Whats new in 6.3.0</a>
|
|
88
126
|
### 6.3.0 (2022-04-12)
|
|
89
127
|
|
package/cmd4Constants.js
CHANGED
|
@@ -86,6 +86,10 @@ var cmd4Constants = {
|
|
|
86
86
|
QUEUETYPE_STANDARD: "StandarD",
|
|
87
87
|
// Used internally to mean entries go straight through the queue
|
|
88
88
|
QUEUETYPE_PASSTHRU: "None",
|
|
89
|
+
DEFAULT_STANDARD_QUEUE_RETRY_COUNT: 0,
|
|
90
|
+
DEFAULT_WORM_QUEUE_RETRY_COUNT: 0,
|
|
91
|
+
QUEUE_RETRIES: "retries",
|
|
92
|
+
|
|
89
93
|
|
|
90
94
|
|
|
91
95
|
// Platform/Accessory Config Constants
|
|
@@ -137,18 +141,68 @@ var cmd4Constants = {
|
|
|
137
141
|
VALUE_lv: "value",
|
|
138
142
|
CMD4_STORAGE_lv: "cmd4Storage",
|
|
139
143
|
|
|
144
|
+
ERROR_STRING_MIN: -151,
|
|
140
145
|
ERROR_TIMER_EXPIRED: -151,
|
|
141
|
-
//
|
|
146
|
+
// ERROR_CMD_FAILED_REPLY: -152,
|
|
142
147
|
ERROR_NULL_REPLY: -153,
|
|
143
148
|
ERROR_NULL_STRING_REPLY: -154,
|
|
144
149
|
ERROR_EMPTY_STRING_REPLY: -155,
|
|
145
150
|
ERROR_2ND_NULL_STRING_REPLY: -156,
|
|
146
151
|
ERROR_NON_CONVERTABLE_REPLY: -157,
|
|
147
152
|
ERROR_NO_DATA_REPLY: -158,
|
|
153
|
+
ERROR_STRING_MAX: -158,
|
|
154
|
+
ERROR_STRINGS:
|
|
155
|
+
[ // cmd4Constants.ERROR_TIMER_EXPIRED -151
|
|
156
|
+
"Timer expired contacting accessory",
|
|
157
|
+
// cmd4Constants.ERROR_CMD_FAILED_REPLY -152
|
|
158
|
+
"Command failed",
|
|
159
|
+
// cmd4Constants.ERROR_NULL_REPLY -153
|
|
160
|
+
"Reply is NULL",
|
|
161
|
+
// cmd4Constants.ERROR_NULL_STRING_REPLY -154
|
|
162
|
+
"Reply is NULL string",
|
|
163
|
+
// cmd4Constants.ERROR_EMPTY_STRING_REPLY -155
|
|
164
|
+
"Reply is an empty string",
|
|
165
|
+
// cmd4Constants.ERROR_2ND_NULL_STRING_REPLY -156
|
|
166
|
+
"Reply is still NULL",
|
|
167
|
+
// cmd4Constants.ERROR_NON_CONVERTABLE_REPLY -157
|
|
168
|
+
"Cannot convert characteristic string",
|
|
169
|
+
// cmd4Constants.ERROR_NO_DATA_REPLY -158
|
|
170
|
+
"No data returned from accessory"
|
|
171
|
+
],
|
|
172
|
+
|
|
173
|
+
// Convert our known Error Codes to strings
|
|
174
|
+
errorString: function( index )
|
|
175
|
+
{
|
|
176
|
+
let offset = - index + cmd4Constants.ERROR_STRING_MIN ;
|
|
177
|
+
let max = cmd4Constants.ERROR_STRING_MIN - cmd4Constants.ERROR_STRING_MAX;
|
|
178
|
+
|
|
179
|
+
//console.log(" index is " + index );
|
|
180
|
+
//console.log(" offset is " + offset );
|
|
181
|
+
//console.log(" max is " + max );
|
|
182
|
+
// i.e 0-7
|
|
183
|
+
if ( index == 0 )
|
|
184
|
+
return "Device returned SUCCESS; " + index;
|
|
185
|
+
|
|
186
|
+
//if ( offset < 0 || offset > max )
|
|
187
|
+
if ( index > cmd4Constants.ERROR_STRING_MIN )
|
|
188
|
+
return "Device returned its own error; " + index;
|
|
189
|
+
if ( index < cmd4Constants.ERROR_STRING_MAX )
|
|
190
|
+
return "Device returned its own error; " + index;
|
|
191
|
+
|
|
192
|
+
// Should not happen because of the above checks
|
|
193
|
+
if ( offset < 0 )
|
|
194
|
+
return "Invalid Error min index: " + index;
|
|
195
|
+
|
|
196
|
+
// Should not happen because of the above checks
|
|
197
|
+
if ( offset > max )
|
|
198
|
+
return "Invalid Error max index: " + index;
|
|
199
|
+
|
|
200
|
+
return cmd4Constants.ERROR_STRINGS[ offset ];
|
|
201
|
+
},
|
|
148
202
|
|
|
149
203
|
|
|
150
204
|
|
|
151
205
|
// Static Messages
|
|
152
|
-
DBUSY: "Perhaps your device is busy?"
|
|
206
|
+
DBUSY: "Perhaps your device is busy or unavailable?"
|
|
153
207
|
};
|
|
154
208
|
module.exports = cmd4Constants;
|