@switchbot/homebridge-switchbot 5.0.0-beta.32 → 5.0.0-beta.34
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/dist/devices-hap/device.d.ts +17 -8
- package/dist/devices-hap/device.d.ts.map +1 -1
- package/dist/devices-hap/device.js +66 -53
- package/dist/devices-hap/device.js.map +1 -1
- package/dist/devices-matter/BaseMatterAccessory.d.ts +4 -0
- package/dist/devices-matter/BaseMatterAccessory.d.ts.map +1 -1
- package/dist/devices-matter/BaseMatterAccessory.js +13 -11
- package/dist/devices-matter/BaseMatterAccessory.js.map +1 -1
- package/dist/platform-hap.d.ts +9 -0
- package/dist/platform-hap.d.ts.map +1 -1
- package/dist/platform-hap.js +16 -39
- package/dist/platform-hap.js.map +1 -1
- package/dist/platform-matter.d.ts +2 -0
- package/dist/platform-matter.d.ts.map +1 -1
- package/dist/platform-matter.js +9 -19
- package/dist/platform-matter.js.map +1 -1
- package/dist/utils.d.ts +43 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +128 -0
- package/dist/utils.js.map +1 -1
- package/docs/variables/default.html +1 -1
- package/package.json +1 -1
- package/src/devices-hap/device.ts +76 -54
- package/src/devices-matter/BaseMatterAccessory.ts +19 -11
- package/src/platform-hap.ts +16 -40
- package/src/platform-matter.ts +9 -18
- package/src/utils.ts +155 -0
package/dist/platform-hap.js
CHANGED
|
@@ -36,7 +36,7 @@ import { TV } from './irdevice/tv.js';
|
|
|
36
36
|
import { VacuumCleaner } from './irdevice/vacuumcleaner.js';
|
|
37
37
|
import { WaterHeater } from './irdevice/waterheater.js';
|
|
38
38
|
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
|
|
39
|
-
import { ApiRequestTracker, cleanDeviceConfig, createPlatformLogger, formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, safeStringify, sleep } from './utils.js';
|
|
39
|
+
import { ApiRequestTracker, cleanDeviceConfig, createPlatformLogger, formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, isSuccessfulStatusCode, logStatusCode, mergeByDeviceId, safeStringify, sleep } from './utils.js';
|
|
40
40
|
/**
|
|
41
41
|
* HomebridgePlatform
|
|
42
42
|
* This class is the main constructor for your plugin, this is where you should
|
|
@@ -507,8 +507,12 @@ export class SwitchBotHAPPlatform {
|
|
|
507
507
|
this.errorLog('Neither SwitchBot Token or Device Config are set.');
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
|
+
/**
|
|
511
|
+
* Check if an API status code indicates success
|
|
512
|
+
* @deprecated Use shared isSuccessfulStatusCode from utils.js instead
|
|
513
|
+
*/
|
|
510
514
|
isSuccessfulResponse(apiStatusCode) {
|
|
511
|
-
return (apiStatusCode
|
|
515
|
+
return isSuccessfulStatusCode(apiStatusCode);
|
|
512
516
|
}
|
|
513
517
|
async handleDevices(deviceLists) {
|
|
514
518
|
if (!this.config.options?.devices && !this.config.options?.deviceConfig) {
|
|
@@ -593,12 +597,12 @@ export class SwitchBotHAPPlatform {
|
|
|
593
597
|
}
|
|
594
598
|
}
|
|
595
599
|
}
|
|
600
|
+
/**
|
|
601
|
+
* Merge two arrays by deviceId
|
|
602
|
+
* @deprecated Use shared mergeByDeviceId from utils.js instead
|
|
603
|
+
*/
|
|
596
604
|
mergeByDeviceId(a1, a2) {
|
|
597
|
-
|
|
598
|
-
return a1.map((itm) => {
|
|
599
|
-
const matchingItem = a2.find(item => normalizeDeviceId(item.deviceId) === normalizeDeviceId(itm.deviceId));
|
|
600
|
-
return { ...matchingItem, ...itm };
|
|
601
|
-
});
|
|
605
|
+
return mergeByDeviceId(a1, a2, false);
|
|
602
606
|
}
|
|
603
607
|
async handleErrorResponse(apiStatusCode, retryCount, maxRetries, delayBetweenRetries) {
|
|
604
608
|
await this.statusCode(apiStatusCode);
|
|
@@ -2655,40 +2659,13 @@ export class SwitchBotHAPPlatform {
|
|
|
2655
2659
|
*
|
|
2656
2660
|
* @param statusCode - The status code returned by the device.
|
|
2657
2661
|
* @returns A promise that resolves when the logging is complete.
|
|
2662
|
+
* @deprecated Use shared logStatusCode from utils.js instead
|
|
2658
2663
|
*/
|
|
2659
2664
|
async statusCode(statusCode) {
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
160: `Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`,
|
|
2665
|
-
161: `Device is offline, statusCode: ${statusCode}`,
|
|
2666
|
-
171: `is offline, statusCode: ${statusCode}`,
|
|
2667
|
-
190: `Requests reached the daily limit, statusCode: ${statusCode}`,
|
|
2668
|
-
100: `Command successfully sent, statusCode: ${statusCode}`,
|
|
2669
|
-
200: `Request successful, statusCode: ${statusCode}`,
|
|
2670
|
-
400: `Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request payload,
|
|
2671
|
-
statusCode: ${statusCode}`,
|
|
2672
|
-
401: `Unauthorized, Authorization for the API is required, but the request has not been authenticated, statusCode: ${statusCode}`,
|
|
2673
|
-
403: `Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not found,
|
|
2674
|
-
statusCode: ${statusCode}`,
|
|
2675
|
-
404: `Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`,
|
|
2676
|
-
406: `Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server,
|
|
2677
|
-
statusCode: ${statusCode}`,
|
|
2678
|
-
415: `Unsupported Media Type, The client has defined a contentType header that is not supported by the server, statusCode: ${statusCode}`,
|
|
2679
|
-
422: `Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for APIs for which
|
|
2680
|
-
certain limits have been exceeded, statusCode: ${statusCode}`,
|
|
2681
|
-
429: `Too Many Requests, The client has exceeded the number of requests allowed for a given time window, statusCode: ${statusCode}`,
|
|
2682
|
-
500: `Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare,
|
|
2683
|
-
statusCode: ${statusCode}`,
|
|
2684
|
-
};
|
|
2685
|
-
const message = messages[statusCode] ?? `Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`;
|
|
2686
|
-
if ([100, 200].includes(statusCode)) {
|
|
2687
|
-
this.debugLog(message);
|
|
2688
|
-
}
|
|
2689
|
-
else {
|
|
2690
|
-
this.errorLog(message);
|
|
2691
|
-
}
|
|
2665
|
+
await logStatusCode(statusCode, {
|
|
2666
|
+
debugLog: this.debugLog.bind(this),
|
|
2667
|
+
errorLog: this.errorLog.bind(this),
|
|
2668
|
+
});
|
|
2692
2669
|
}
|
|
2693
2670
|
async retryRequest(device, deviceMaxRetries, deviceDelayBetweenRetries) {
|
|
2694
2671
|
let retryCount = 0;
|