@switchbot/homebridge-switchbot 4.1.1-beta.9 → 4.1.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 +2 -2
- package/config.schema.json +2 -2
- package/dist/device/device.d.ts +1 -2
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +16 -16
- package/dist/device/device.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +1 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +6 -18
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/platform.d.ts +21 -9
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +66 -90
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +0 -3
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/docs/functions/default.html +1 -1
- package/package.json +6 -6
- package/src/device/device.ts +16 -17
- package/src/irdevice/irdevice.ts +6 -15
- package/src/platform.ts +69 -104
- package/src/settings.ts +0 -1
- package/.github/npm-version-script.cjs +0 -81
package/dist/platform.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import
|
|
2
|
+
import { argv } from 'node:process';
|
|
3
3
|
import asyncmqtt from 'async-mqtt';
|
|
4
4
|
import fakegato from 'fakegato-history';
|
|
5
5
|
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
|
|
@@ -46,14 +46,16 @@ export class SwitchBotPlatform {
|
|
|
46
46
|
api;
|
|
47
47
|
log;
|
|
48
48
|
// Configuration properties
|
|
49
|
-
version;
|
|
50
|
-
Logging;
|
|
51
|
-
debugMode;
|
|
52
|
-
maxRetries;
|
|
53
|
-
delayBetweenRetries;
|
|
54
49
|
platformConfig;
|
|
55
50
|
platformLogging;
|
|
51
|
+
platformRefreshRate;
|
|
52
|
+
platformPushRate;
|
|
53
|
+
platformUpdateRate;
|
|
54
|
+
platformMaxRetries;
|
|
55
|
+
platformDelayBetweenRetries;
|
|
56
56
|
config;
|
|
57
|
+
debugMode;
|
|
58
|
+
version;
|
|
57
59
|
// MQTT and Webhook properties
|
|
58
60
|
mqttClient = null;
|
|
59
61
|
webhookEventListener = null;
|
|
@@ -81,10 +83,10 @@ export class SwitchBotPlatform {
|
|
|
81
83
|
credentials: config.credentials,
|
|
82
84
|
options: config.options,
|
|
83
85
|
devices: config.devices,
|
|
84
|
-
deviceConfig: config.deviceConfig,
|
|
85
86
|
};
|
|
86
87
|
// Plugin Configuration
|
|
87
88
|
this.getPlatformLogSettings();
|
|
89
|
+
this.getPlatformRateSettings();
|
|
88
90
|
this.getPlatformConfigSettings();
|
|
89
91
|
this.getVersion();
|
|
90
92
|
// Finish initializing the platform
|
|
@@ -329,19 +331,6 @@ export class SwitchBotPlatform {
|
|
|
329
331
|
this.debugLog('Verifying Config');
|
|
330
332
|
this.config = this.config || {};
|
|
331
333
|
this.config.options = this.config.options || {};
|
|
332
|
-
const platformConfig = {};
|
|
333
|
-
if (this.config.options.logging) {
|
|
334
|
-
platformConfig.logging = this.config.options.logging;
|
|
335
|
-
}
|
|
336
|
-
if (this.config.options.logging && this.config.options.refreshRate) {
|
|
337
|
-
platformConfig.refreshRate = this.config.options.refreshRate;
|
|
338
|
-
}
|
|
339
|
-
if (this.config.options.logging && this.config.options.pushRate) {
|
|
340
|
-
platformConfig.pushRate = this.config.options.pushRate;
|
|
341
|
-
}
|
|
342
|
-
if (Object.entries(platformConfig).length !== 0) {
|
|
343
|
-
this.debugWarnLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
344
|
-
}
|
|
345
334
|
if (this.config.options) {
|
|
346
335
|
// Device Config
|
|
347
336
|
if (this.config.options.devices) {
|
|
@@ -370,34 +359,6 @@ export class SwitchBotPlatform {
|
|
|
370
359
|
}
|
|
371
360
|
}
|
|
372
361
|
}
|
|
373
|
-
if (this.config.options.refreshRate < 5) {
|
|
374
|
-
throw new Error('Refresh Rate must be above 5 (5 seconds).');
|
|
375
|
-
}
|
|
376
|
-
if (!this.config.options.refreshRate) {
|
|
377
|
-
// default 120 seconds (2 minutes)
|
|
378
|
-
this.config.options.refreshRate = 120;
|
|
379
|
-
this.debugWarnLog('Using Default Refresh Rate (2 minutes).');
|
|
380
|
-
}
|
|
381
|
-
if (!this.config.options.pushRate) {
|
|
382
|
-
// default 100 milliseconds
|
|
383
|
-
this.config.options.pushRate = 0.1;
|
|
384
|
-
this.debugWarnLog('Using Default Push Rate.');
|
|
385
|
-
}
|
|
386
|
-
if (!this.config.options.maxRetries) {
|
|
387
|
-
this.config.options.maxRetries = 5;
|
|
388
|
-
this.debugWarnLog('Using Default Max Retries.');
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
this.maxRetries = this.config.options.maxRetries;
|
|
392
|
-
}
|
|
393
|
-
if (!this.config.options.delayBetweenRetries) {
|
|
394
|
-
// default 3 seconds
|
|
395
|
-
this.config.options.delayBetweenRetries = 3000;
|
|
396
|
-
this.debugWarnLog('Using Default Delay Between Retries.');
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
this.delayBetweenRetries = this.config.options.delayBetweenRetries * 1000;
|
|
400
|
-
}
|
|
401
362
|
if (!this.config.credentials && !this.config.options) {
|
|
402
363
|
this.debugWarnLog('Missing Credentials');
|
|
403
364
|
}
|
|
@@ -419,11 +380,11 @@ export class SwitchBotPlatform {
|
|
|
419
380
|
return this.handleManualConfig();
|
|
420
381
|
}
|
|
421
382
|
let retryCount = 0;
|
|
422
|
-
const maxRetries = this.
|
|
423
|
-
const delayBetweenRetries = this.
|
|
383
|
+
const maxRetries = this.platformMaxRetries ?? 5;
|
|
384
|
+
const delayBetweenRetries = this.platformDelayBetweenRetries || 5000;
|
|
424
385
|
this.debugWarnLog(`Retry Count: ${retryCount}`);
|
|
425
|
-
this.debugWarnLog(`Max Retries: ${
|
|
426
|
-
this.debugWarnLog(`Delay Between Retries: ${
|
|
386
|
+
this.debugWarnLog(`Max Retries: ${this.platformMaxRetries}`);
|
|
387
|
+
this.debugWarnLog(`Delay Between Retries: ${this.platformDelayBetweenRetries}`);
|
|
427
388
|
while (retryCount < maxRetries) {
|
|
428
389
|
try {
|
|
429
390
|
const { response, statusCode } = await this.switchBotAPI.getDevices();
|
|
@@ -2563,50 +2524,65 @@ export class SwitchBotPlatform {
|
|
|
2563
2524
|
return false;
|
|
2564
2525
|
}
|
|
2565
2526
|
}
|
|
2566
|
-
async getVersion() {
|
|
2567
|
-
const json = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
2568
|
-
this.debugLog(`Plugin Version: ${json.version}`);
|
|
2569
|
-
this.version = json.version;
|
|
2570
|
-
return json.version;
|
|
2571
|
-
}
|
|
2572
2527
|
async getPlatformConfigSettings() {
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
platformConfig.
|
|
2578
|
-
platformConfig.
|
|
2579
|
-
platformConfig.
|
|
2580
|
-
|
|
2581
|
-
platformConfig.maxRetries = this.maxRetries;
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
this.delayBetweenRetries = (options.delayBetweenRetries || 3) * 1000;
|
|
2586
|
-
platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
|
|
2587
|
-
if (!options.delayBetweenRetries) {
|
|
2588
|
-
this.debugWarnLog('Using Default Delay Between Retries');
|
|
2589
|
-
}
|
|
2590
|
-
if (Object.keys(platformConfig).length) {
|
|
2591
|
-
this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2528
|
+
if (this.config.options) {
|
|
2529
|
+
const platformConfig = {
|
|
2530
|
+
platform: 'Resideo',
|
|
2531
|
+
};
|
|
2532
|
+
platformConfig.logging = this.config.options.logging ? this.config.options.logging : undefined;
|
|
2533
|
+
platformConfig.refreshRate = this.config.options.refreshRate ? this.config.options.refreshRate : undefined;
|
|
2534
|
+
platformConfig.updateRate = this.config.options.updateRate ? this.config.options.updateRate : undefined;
|
|
2535
|
+
platformConfig.pushRate = this.config.options.pushRate ? this.config.options.pushRate : undefined;
|
|
2536
|
+
platformConfig.maxRetries = this.config.options.maxRetries ? this.config.options.maxRetries : undefined;
|
|
2537
|
+
platformConfig.delayBetweenRetries = this.config.options.delayBetweenRetries ? this.config.options.delayBetweenRetries : undefined;
|
|
2538
|
+
if (Object.entries(platformConfig).length !== 0) {
|
|
2539
|
+
await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
|
|
2592
2540
|
}
|
|
2593
2541
|
this.platformConfig = platformConfig;
|
|
2594
2542
|
}
|
|
2595
2543
|
}
|
|
2544
|
+
async getPlatformRateSettings() {
|
|
2545
|
+
this.platformRefreshRate = this.config.options?.refreshRate ?? 120;
|
|
2546
|
+
if (this.platformRefreshRate < 5) {
|
|
2547
|
+
this.platformRefreshRate = 5;
|
|
2548
|
+
}
|
|
2549
|
+
const refreshRate = this.config.options?.refreshRate ? 'Using Platform Config refreshRate' : 'refreshRate Disabled by Default';
|
|
2550
|
+
await this.debugLog(`${refreshRate}: ${this.platformRefreshRate}`);
|
|
2551
|
+
this.platformUpdateRate = this.config.options?.updateRate ? this.config.options.updateRate : 1;
|
|
2552
|
+
const updateRate = this.config.options?.updateRate ? 'Using Platform Config updateRate' : 'Using Default updateRate';
|
|
2553
|
+
await this.debugLog(`${updateRate}: ${this.platformUpdateRate}`);
|
|
2554
|
+
this.platformPushRate = this.config.options?.pushRate ? this.config.options.pushRate : 0.1;
|
|
2555
|
+
const pushRate = this.config.options?.pushRate ? 'Using Platform Config pushRate' : 'Using Default pushRate';
|
|
2556
|
+
await this.debugLog(`${pushRate}: ${this.platformPushRate}`);
|
|
2557
|
+
this.platformMaxRetries = this.config.options?.maxRetries ? this.config.options.maxRetries : 3;
|
|
2558
|
+
const maxRetries = this.config.options?.maxRetries ? 'Using Platform Config maxRetries' : 'Using Default maxRetries';
|
|
2559
|
+
await this.debugLog(`${maxRetries}: ${this.platformMaxRetries}`);
|
|
2560
|
+
this.platformDelayBetweenRetries = this.config.options?.delayBetweenRetries ? this.config.options.delayBetweenRetries * 1000 : 3000;
|
|
2561
|
+
const delayBetweenRetries = this.config.options?.delayBetweenRetries ? 'Using Platform Config delayBetweenRetries' : 'Using Default delayBetweenRetries';
|
|
2562
|
+
await this.debugLog(`${delayBetweenRetries}: ${this.platformDelayBetweenRetries / 1000}`);
|
|
2563
|
+
}
|
|
2596
2564
|
async getPlatformLogSettings() {
|
|
2597
|
-
this.debugMode =
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2565
|
+
this.debugMode = argv.includes('-D') ?? argv.includes('--debug');
|
|
2566
|
+
this.platformLogging = (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard'
|
|
2567
|
+
|| this.config.options?.logging === 'none')
|
|
2568
|
+
? this.config.options.logging
|
|
2569
|
+
: this.debugMode ? 'debugMode' : 'standard';
|
|
2570
|
+
const logging = this.config.options?.logging ? 'Platform Config' : this.debugMode ? 'debugMode' : 'Default';
|
|
2571
|
+
await this.debugLog(`Using ${logging} Logging: ${this.platformLogging}`);
|
|
2572
|
+
}
|
|
2573
|
+
/**
|
|
2574
|
+
* Asynchronously retrieves the version of the plugin from the package.json file.
|
|
2575
|
+
*
|
|
2576
|
+
* This method reads the package.json file located in the parent directory,
|
|
2577
|
+
* parses its content to extract the version, and logs the version using the debug logger.
|
|
2578
|
+
* The extracted version is then assigned to the `version` property of the class.
|
|
2579
|
+
*
|
|
2580
|
+
* @returns {Promise<void>} A promise that resolves when the version has been retrieved and logged.
|
|
2581
|
+
*/
|
|
2582
|
+
async getVersion() {
|
|
2583
|
+
const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
2584
|
+
this.debugLog(`Plugin Version: ${version}`);
|
|
2585
|
+
this.version = version;
|
|
2610
2586
|
}
|
|
2611
2587
|
/**
|
|
2612
2588
|
* Validate and clean a string value for a Name Characteristic.
|