Skip to content

Commit 18e3ac7

Browse files
committed
wrap sending device update fully in queue
1 parent 765373f commit 18e3ac7

File tree

5 files changed

+32
-37
lines changed

5 files changed

+32
-37
lines changed

config.schema.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@
8484
"functionBody": "return (!model.lanDisable);"
8585
}
8686
},
87-
"bleControlInterval": {
88-
"title": "BLE Control Interval",
87+
"controlInterval": {
88+
"title": "Control Interval",
8989
"type": "integer",
90-
"description": "A minimum delay (in seconds) between device updates being sent. Increasing this may help if you find device updates are not working or if you use HomeKit scenes/groupings. Must be 5 or more.",
91-
"placeholder": 5,
92-
"minimum": 5
90+
"description": "A minimum delay (in milliseconds) between device updates being sent. Increasing this may help if you find device updates are not working or if you use HomeKit scenes/groupings. Must be 0 or more.",
91+
"placeholder": 250,
92+
"minimum": 0
9393
},
9494
"colourSafeMode": {
9595
"type": "boolean",
@@ -1448,14 +1448,14 @@
14481448
"items": [
14491449
"ignoreMatter",
14501450
"disableDeviceLogging",
1451+
"controlInterval",
14511452
"httpRefreshTime",
14521453
"awsDisable",
14531454
"bleDisable",
14541455
"bleRefreshTime",
14551456
"lanDisable",
14561457
"lanRefreshTime",
14571458
"lanScanInterval",
1458-
"bleControlInterval",
14591459
"colourSafeMode"
14601460
]
14611461
},

lib/platform.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ export default class {
118118
Object.entries(config).forEach((entry) => {
119119
const [key, val] = entry
120120
switch (key) {
121-
case 'bleControlInterval':
122121
case 'bleRefreshTime':
122+
case 'controlInterval':
123123
case 'httpRefreshTime':
124124
case 'lanRefreshTime':
125125
case 'lanScanInterval': {
@@ -540,14 +540,9 @@ export default class {
540540
})
541541
}
542542

543-
// Config changed from milliseconds to seconds, so convert if needed
544-
this.config.bleControlInterval = this.config.bleControlInterval >= 500
545-
? this.config.bleControlInterval / 1000
546-
: this.config.bleControlInterval
547-
548543
this.queue = new PQueue({
549544
concurrency: 1,
550-
interval: this.config.bleControlInterval * 1000,
545+
interval: this.config.controlInterval,
551546
intervalCap: 1,
552547
timeout: 10000,
553548
throwOnTimeout: true,
@@ -1711,28 +1706,28 @@ export default class {
17111706
}
17121707
}
17131708

1714-
// *********************************** //
1715-
// ********* CONNECTION: AWS ********* //
1716-
// *********************************** //
1717-
// Check to see if we have the option to use AWS
1718-
if (accessory.context.useAwsControl && data.awsParams) {
1719-
try {
1720-
await this.awsClient.updateDevice(accessory, data.awsParams)
1721-
return true
1722-
} catch (err) {
1723-
// Print the reason to the log if in debug mode, it's not always necessarily an error
1724-
accessory.logWarn(`${platformLang.notAWSSent} ${parseError(err, [platformLang.notAWSConn])}`)
1709+
return this.queue.add(async () => {
1710+
// *********************************** //
1711+
// ********* CONNECTION: AWS ********* //
1712+
// *********************************** //
1713+
// Check to see if we have the option to use AWS
1714+
if (accessory.context.useAwsControl && data.awsParams) {
1715+
try {
1716+
await this.awsClient.updateDevice(accessory, data.awsParams)
1717+
return true
1718+
} catch (err) {
1719+
// Print the reason to the log if in debug mode, it's not always necessarily an error
1720+
accessory.logWarn(`${platformLang.notAWSSent} ${parseError(err, [platformLang.notAWSConn])}`)
1721+
}
17251722
}
1726-
}
17271723

1728-
// We can return now, if there is no option to use BLE
1729-
if (!data.bleParams) {
1730-
return true
1731-
}
1724+
// We can return now, if there is no option to use BLE
1725+
if (!data.bleParams) {
1726+
return true
1727+
}
17321728

1733-
// We use a queue for BLE connections for different reasons
1734-
// BLE: We don't want to send multiple commands at once, as it can cause issues
1735-
return this.queue.add(async () => {
1729+
// We use a queue for BLE connections for different reasons
1730+
// BLE: We don't want to send multiple commands at once, as it can cause issues
17361731
// *********************************** //
17371732
// ********* CONNECTION: BLE ********* //
17381733
// *********************************** //

lib/utils/constants.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export default {
66
ignoreMatter: false,
77
disableDeviceLogging: false,
88
httpRefreshTime: 30,
9+
controlInterval: 250,
910
awsDisable: false,
1011
bleDisable: false,
1112
bleRefreshTime: 300,
1213
lanDisable: false,
1314
lanRefreshTime: 30,
1415
lanScanInterval: 60,
15-
bleControlInterval: 5,
1616
colourSafeMode: false,
1717
lightDevices: [],
1818
switchDevices: [],
@@ -31,10 +31,10 @@ export default {
3131

3232
defaultValues: {
3333
adaptiveLightingShift: 0,
34-
bleControlInterval: 5,
3534
awsColourMode: 'default',
3635
bleRefreshTime: 300,
3736
brightnessStep: 1,
37+
controlInterval: 250,
3838
httpRefreshTime: 30,
3939
lanRefreshTime: 30,
4040
lanScanInterval: 60,
@@ -44,9 +44,9 @@ export default {
4444

4545
minValues: {
4646
adaptiveLightingShift: -1,
47-
bleControlInterval: 5,
4847
bleRefreshTime: 60,
4948
brightnessStep: 1,
49+
controlInterval: 0,
5050
httpRefreshTime: 30,
5151
lanRefreshTime: 10,
5252
lanScanInterval: 30,

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@
7070
"@stoprocent/noble": "^2.3.10"
7171
},
7272
"devDependencies": {
73-
"@antfu/eslint-config": "^6.7.1"
73+
"@antfu/eslint-config": "^6.7.3"
7474
}
7575
}

0 commit comments

Comments
 (0)