@switchbot/homebridge-switchbot 5.0.0-beta.3 → 5.0.0-beta.31
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 +13 -0
- package/README.md +23 -3
- package/config.schema.json +70 -4
- package/dist/devices-hap/device.d.ts +1 -0
- package/dist/devices-hap/device.d.ts.map +1 -1
- package/dist/devices-hap/device.js +70 -30
- package/dist/devices-hap/device.js.map +1 -1
- package/dist/devices-matter/BaseMatterAccessory.d.ts +23 -0
- package/dist/devices-matter/BaseMatterAccessory.d.ts.map +1 -1
- package/dist/devices-matter/BaseMatterAccessory.js +167 -5
- package/dist/devices-matter/BaseMatterAccessory.js.map +1 -1
- package/dist/devices-matter/ColorLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ColorLightAccessory.js +12 -12
- package/dist/devices-matter/ColorLightAccessory.js.map +1 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ColorTemperatureLightAccessory.js +5 -7
- package/dist/devices-matter/ColorTemperatureLightAccessory.js.map +1 -1
- package/dist/devices-matter/DimmableLightAccessory.js +9 -9
- package/dist/devices-matter/DimmableLightAccessory.js.map +1 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/ExtendedColorLightAccessory.js +14 -15
- package/dist/devices-matter/ExtendedColorLightAccessory.js.map +1 -1
- package/dist/devices-matter/OnOffLightAccessory.d.ts.map +1 -1
- package/dist/devices-matter/OnOffLightAccessory.js +8 -16
- package/dist/devices-matter/OnOffLightAccessory.js.map +1 -1
- package/dist/devices-matter/OnOffOutletAccessory.d.ts +2 -0
- package/dist/devices-matter/OnOffOutletAccessory.d.ts.map +1 -1
- package/dist/devices-matter/OnOffOutletAccessory.js +10 -7
- package/dist/devices-matter/OnOffOutletAccessory.js.map +1 -1
- package/dist/devices-matter/OnOffSwitchAccessory.js +2 -2
- package/dist/devices-matter/OnOffSwitchAccessory.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +48 -1
- package/dist/homebridge-ui/server.js +35 -0
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +7 -2
- package/dist/index.test.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -10
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +76 -35
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/platform-hap.d.ts +11 -14
- package/dist/platform-hap.d.ts.map +1 -1
- package/dist/platform-hap.js +64 -64
- package/dist/platform-hap.js.map +1 -1
- package/dist/platform-matter.d.ts +87 -6
- package/dist/platform-matter.d.ts.map +1 -1
- package/dist/platform-matter.js +1845 -84
- package/dist/platform-matter.js.map +1 -1
- package/dist/settings.d.ts +11 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/test/hap/platform-hap.logging.test.d.ts +2 -0
- package/dist/test/hap/platform-hap.logging.test.d.ts.map +1 -0
- package/dist/test/hap/platform-hap.logging.test.js +33 -0
- package/dist/test/hap/platform-hap.logging.test.js.map +1 -0
- package/dist/test/hap/platform-hap.test.d.ts +2 -0
- package/dist/test/hap/platform-hap.test.d.ts.map +1 -0
- package/dist/test/hap/platform-hap.test.js +62 -0
- package/dist/test/hap/platform-hap.test.js.map +1 -0
- package/dist/test/helpers/platform-fixtures.d.ts +9 -0
- package/dist/test/helpers/platform-fixtures.d.ts.map +1 -0
- package/dist/test/helpers/platform-fixtures.js +30 -0
- package/dist/test/helpers/platform-fixtures.js.map +1 -0
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.d.ts +2 -0
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.d.ts.map +1 -0
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.js +71 -0
- package/dist/test/matter/devices-matter/baseMatterAccessory.test.js.map +1 -0
- package/dist/test/matter/platform-matter.additional.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.additional.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.additional.test.js +35 -0
- package/dist/test/matter/platform-matter.additional.test.js.map +1 -0
- package/dist/test/matter/platform-matter.bleparse.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.bleparse.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.bleparse.test.js +43 -0
- package/dist/test/matter/platform-matter.bleparse.test.js.map +1 -0
- package/dist/test/matter/platform-matter.cleanup.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.cleanup.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.cleanup.test.js +70 -0
- package/dist/test/matter/platform-matter.cleanup.test.js.map +1 -0
- package/dist/test/matter/platform-matter.keepstale.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.keepstale.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.keepstale.test.js +27 -0
- package/dist/test/matter/platform-matter.keepstale.test.js.map +1 -0
- package/dist/test/matter/platform-matter.logging.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.logging.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.logging.test.js +29 -0
- package/dist/test/matter/platform-matter.logging.test.js.map +1 -0
- package/dist/test/matter/platform-matter.mapping.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.mapping.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.mapping.test.js +43 -0
- package/dist/test/matter/platform-matter.mapping.test.js.map +1 -0
- package/dist/test/matter/platform-matter.openapi-mapping.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.openapi-mapping.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.openapi-mapping.test.js +84 -0
- package/dist/test/matter/platform-matter.openapi-mapping.test.js.map +1 -0
- package/dist/test/matter/platform-matter.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.test.js +117 -0
- package/dist/test/matter/platform-matter.test.js.map +1 -0
- package/dist/test/matter/platform-matter.unregister.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.unregister.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.unregister.test.js +30 -0
- package/dist/test/matter/platform-matter.unregister.test.js.map +1 -0
- package/dist/utils.d.ts +127 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +405 -0
- package/dist/utils.js.map +1 -1
- package/dist/utils.test.d.ts +2 -0
- package/dist/utils.test.d.ts.map +1 -0
- package/dist/utils.test.js +95 -0
- package/dist/utils.test.js.map +1 -0
- package/dist/verifyconfig.test.js +2 -2
- package/dist/verifyconfig.test.js.map +1 -1
- package/docs/assets/main.js +2 -2
- package/docs/index.html +20 -2
- package/docs/variables/default.html +1 -1
- package/package.json +14 -14
- package/src/devices-hap/device.ts +68 -30
- package/src/devices-matter/BaseMatterAccessory.ts +168 -5
- package/src/devices-matter/ColorLightAccessory.ts +12 -12
- package/src/devices-matter/ColorTemperatureLightAccessory.ts +5 -7
- package/src/devices-matter/DimmableLightAccessory.ts +9 -9
- package/src/devices-matter/ExtendedColorLightAccessory.ts +14 -15
- package/src/devices-matter/OnOffLightAccessory.ts +8 -16
- package/src/devices-matter/OnOffOutletAccessory.ts +12 -7
- package/src/devices-matter/OnOffSwitchAccessory.ts +2 -2
- package/src/homebridge-ui/public/index.html +48 -1
- package/src/homebridge-ui/server.ts +37 -0
- package/src/index.test.ts +7 -2
- package/src/index.ts +4 -5
- package/src/irdevice/irdevice.ts +74 -35
- package/src/platform-hap.ts +68 -73
- package/src/platform-matter.ts +1879 -87
- package/src/settings.ts +15 -0
- package/src/test/hap/platform-hap.logging.test.ts +36 -0
- package/src/test/hap/platform-hap.test.ts +70 -0
- package/src/test/helpers/platform-fixtures.ts +33 -0
- package/src/test/matter/devices-matter/baseMatterAccessory.test.ts +88 -0
- package/src/test/matter/platform-matter.additional.test.ts +44 -0
- package/src/test/matter/platform-matter.bleparse.test.ts +47 -0
- package/src/test/matter/platform-matter.cleanup.test.ts +86 -0
- package/src/test/matter/platform-matter.keepstale.test.ts +37 -0
- package/src/test/matter/platform-matter.logging.test.ts +33 -0
- package/src/test/matter/platform-matter.mapping.test.ts +57 -0
- package/src/test/matter/platform-matter.openapi-mapping.test.ts +109 -0
- package/src/test/matter/platform-matter.test.ts +144 -0
- package/src/test/matter/platform-matter.unregister.test.ts +39 -0
- package/src/utils.test.ts +96 -0
- package/src/utils.ts +419 -3
- package/src/verifyconfig.test.ts +11 -10
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 { cleanDeviceConfig, formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, safeStringify, sleep } from './utils.js';
|
|
39
|
+
import { ApiRequestTracker, cleanDeviceConfig, createPlatformLogger, formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, 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
|
|
@@ -47,6 +47,17 @@ export class SwitchBotHAPPlatform {
|
|
|
47
47
|
accessories = [];
|
|
48
48
|
api;
|
|
49
49
|
log;
|
|
50
|
+
// Logging helper functions (attached from utils.createPlatformLogger in constructor)
|
|
51
|
+
infoLog;
|
|
52
|
+
successLog;
|
|
53
|
+
debugSuccessLog;
|
|
54
|
+
warnLog;
|
|
55
|
+
debugWarnLog;
|
|
56
|
+
errorLog;
|
|
57
|
+
debugErrorLog;
|
|
58
|
+
debugLog;
|
|
59
|
+
loggingIsDebug;
|
|
60
|
+
enablingPlatformLogging;
|
|
50
61
|
// Configuration properties
|
|
51
62
|
platformConfig;
|
|
52
63
|
platformLogging;
|
|
@@ -64,6 +75,8 @@ export class SwitchBotHAPPlatform {
|
|
|
64
75
|
// SwitchBot APIs
|
|
65
76
|
switchBotAPI;
|
|
66
77
|
switchBotBLE;
|
|
78
|
+
// API request tracking
|
|
79
|
+
apiTracker;
|
|
67
80
|
// External APIs
|
|
68
81
|
eve;
|
|
69
82
|
fakegatoAPI;
|
|
@@ -73,9 +86,21 @@ export class SwitchBotHAPPlatform {
|
|
|
73
86
|
constructor(log, config, api) {
|
|
74
87
|
this.api = api;
|
|
75
88
|
this.log = log;
|
|
89
|
+
// Attach shared platform logging helpers (moved to utils for reuse)
|
|
90
|
+
const _pl = createPlatformLogger(async () => this.platformLogging, this.log);
|
|
91
|
+
this.infoLog = _pl.infoLog;
|
|
92
|
+
this.successLog = _pl.successLog;
|
|
93
|
+
this.debugSuccessLog = _pl.debugSuccessLog;
|
|
94
|
+
this.warnLog = _pl.warnLog;
|
|
95
|
+
this.debugWarnLog = _pl.debugWarnLog;
|
|
96
|
+
this.errorLog = _pl.errorLog;
|
|
97
|
+
this.debugErrorLog = _pl.debugErrorLog;
|
|
98
|
+
this.debugLog = _pl.debugLog;
|
|
99
|
+
this.loggingIsDebug = _pl.loggingIsDebug;
|
|
100
|
+
this.enablingPlatformLogging = _pl.enablingPlatformLogging;
|
|
76
101
|
// only load if configured
|
|
77
102
|
if (!config) {
|
|
78
|
-
this.
|
|
103
|
+
this.errorLog('No configuration found for the plugin, please check your config.');
|
|
79
104
|
return;
|
|
80
105
|
}
|
|
81
106
|
// Plugin options into our config variables.
|
|
@@ -86,6 +111,19 @@ export class SwitchBotHAPPlatform {
|
|
|
86
111
|
options: config.options,
|
|
87
112
|
devices: config.devices,
|
|
88
113
|
};
|
|
114
|
+
// Determine platform logging preference (match HAP behaviour as closely as
|
|
115
|
+
// possible using config values. We default to 'standard' when unspecified.)
|
|
116
|
+
this.platformLogging = (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none')
|
|
117
|
+
? this.config.options.logging
|
|
118
|
+
: 'standard';
|
|
119
|
+
// Unconditional diagnostic using the raw Homebridge `log` so it always
|
|
120
|
+
// appears regardless of the platform logging helpers' gating logic.
|
|
121
|
+
try {
|
|
122
|
+
this.log.debug?.(`[SwitchBot HAP] effective platformLogging=${String(this.platformLogging)}`);
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
// swallow any logging errors — diagnostics are best-effort
|
|
126
|
+
}
|
|
89
127
|
// Normalize deviceConfig to remove UI-inserted defaults (lots of false/empty values)
|
|
90
128
|
try {
|
|
91
129
|
if (this.config.options) {
|
|
@@ -171,9 +209,29 @@ export class SwitchBotHAPPlatform {
|
|
|
171
209
|
// to start discovery of new accessories.
|
|
172
210
|
this.api.on('didFinishLaunching', async () => {
|
|
173
211
|
this.debugLog('Executed didFinishLaunching callback');
|
|
212
|
+
// Initialize API request tracking
|
|
213
|
+
try {
|
|
214
|
+
this.apiTracker = new ApiRequestTracker(this.api, this.log, 'SwitchBot HAP');
|
|
215
|
+
this.apiTracker.startHourlyLogging();
|
|
216
|
+
}
|
|
217
|
+
catch (e) {
|
|
218
|
+
this.errorLog(`Failed to initialize API request tracking: ${e.message ?? e}`);
|
|
219
|
+
}
|
|
174
220
|
// run the method to discover / register your devices as accessories
|
|
175
221
|
try {
|
|
176
|
-
|
|
222
|
+
// Does the user have a version of Homebridge that is compatible with matter?
|
|
223
|
+
if (!this.api.isMatterAvailable?.()) {
|
|
224
|
+
this.debugLog(`Matter is not available in this version of Homebridge. Please update Homebridge to use this plugin, ${this.api.isMatterAvailable?.() ? '' : ' (Matter is not available in this version of Homebridge)'}`);
|
|
225
|
+
}
|
|
226
|
+
if (!this.api.isMatterEnabled?.()) {
|
|
227
|
+
this.debugLog(`Matter is not enabled in Homebridge. Please enable Matter in the Homebridge settings to use this plugin, ${this.api.isMatterEnabled?.() ? '' : ' (Matter is not enabled in Homebridge)'}`);
|
|
228
|
+
}
|
|
229
|
+
if (!this.api.isMatterAvailable?.() && !this.api.isMatterEnabled?.()) {
|
|
230
|
+
await this.discoverDevices();
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
this.infoLog('Matter is enabled in Homebridge. SwitchBot Matter devices will be handled by the Matter platform.');
|
|
234
|
+
}
|
|
177
235
|
}
|
|
178
236
|
catch (e) {
|
|
179
237
|
this.errorLog(`Failed to Discover, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
|
|
@@ -406,6 +464,7 @@ export class SwitchBotHAPPlatform {
|
|
|
406
464
|
this.debugWarnLog(`Delay Between Retries: ${this.platformDelayBetweenRetries}`);
|
|
407
465
|
while (retryCount < maxRetries) {
|
|
408
466
|
try {
|
|
467
|
+
this.apiTracker?.track();
|
|
409
468
|
const { response, statusCode } = await this.switchBotAPI.getDevices();
|
|
410
469
|
this.debugLog(`response: ${JSON.stringify(response)}`);
|
|
411
470
|
if (this.isSuccessfulResponse(statusCode)) {
|
|
@@ -2637,6 +2696,7 @@ export class SwitchBotHAPPlatform {
|
|
|
2637
2696
|
const delayBetweenRetries = deviceDelayBetweenRetries;
|
|
2638
2697
|
while (retryCount < maxRetries) {
|
|
2639
2698
|
try {
|
|
2699
|
+
this.apiTracker?.track();
|
|
2640
2700
|
const { response, statusCode } = await this.switchBotAPI.getDeviceStatus(device.deviceId, this.config.credentials?.token, this.config.credentials?.secret);
|
|
2641
2701
|
this.debugLog(`response: ${JSON.stringify(response)}`);
|
|
2642
2702
|
return { response, statusCode };
|
|
@@ -2662,6 +2722,7 @@ export class SwitchBotHAPPlatform {
|
|
|
2662
2722
|
const delayBetweenRetries = deviceDelayBetweenRetries ?? 1000;
|
|
2663
2723
|
while (retryCount < maxRetries) {
|
|
2664
2724
|
try {
|
|
2725
|
+
this.apiTracker?.track();
|
|
2665
2726
|
const { response, statusCode } = await this.switchBotAPI.controlDevice(device.deviceId, bodyChange.command, bodyChange.parameter, bodyChange.commandType, this.config.credentials?.token, this.config.credentials?.secret);
|
|
2666
2727
|
this.debugLog(`response: ${JSON.stringify(response)}`);
|
|
2667
2728
|
return { response, statusCode };
|
|
@@ -2784,66 +2845,5 @@ export class SwitchBotHAPPlatform {
|
|
|
2784
2845
|
return value;
|
|
2785
2846
|
}
|
|
2786
2847
|
}
|
|
2787
|
-
/**
|
|
2788
|
-
* If device level logging is turned on, log to log.warn
|
|
2789
|
-
* Otherwise send debug logs to log.debug
|
|
2790
|
-
*/
|
|
2791
|
-
async infoLog(...log) {
|
|
2792
|
-
if (await this.enablingPlatformLogging()) {
|
|
2793
|
-
this.log.info(String(...log));
|
|
2794
|
-
}
|
|
2795
|
-
}
|
|
2796
|
-
async successLog(...log) {
|
|
2797
|
-
if (await this.enablingPlatformLogging()) {
|
|
2798
|
-
this.log.success(String(...log));
|
|
2799
|
-
}
|
|
2800
|
-
}
|
|
2801
|
-
async debugSuccessLog(...log) {
|
|
2802
|
-
if (await this.enablingPlatformLogging()) {
|
|
2803
|
-
if (await this.loggingIsDebug()) {
|
|
2804
|
-
this.log.success('[DEBUG]', String(...log));
|
|
2805
|
-
}
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
async warnLog(...log) {
|
|
2809
|
-
if (await this.enablingPlatformLogging()) {
|
|
2810
|
-
this.log.warn(String(...log));
|
|
2811
|
-
}
|
|
2812
|
-
}
|
|
2813
|
-
async debugWarnLog(...log) {
|
|
2814
|
-
if (await this.enablingPlatformLogging()) {
|
|
2815
|
-
if (await this.loggingIsDebug()) {
|
|
2816
|
-
this.log.warn('[DEBUG]', String(...log));
|
|
2817
|
-
}
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
async errorLog(...log) {
|
|
2821
|
-
if (await this.enablingPlatformLogging()) {
|
|
2822
|
-
this.log.error(String(...log));
|
|
2823
|
-
}
|
|
2824
|
-
}
|
|
2825
|
-
async debugErrorLog(...log) {
|
|
2826
|
-
if (await this.enablingPlatformLogging()) {
|
|
2827
|
-
if (await this.loggingIsDebug()) {
|
|
2828
|
-
this.log.error('[DEBUG]', String(...log));
|
|
2829
|
-
}
|
|
2830
|
-
}
|
|
2831
|
-
}
|
|
2832
|
-
async debugLog(...log) {
|
|
2833
|
-
if (await this.enablingPlatformLogging()) {
|
|
2834
|
-
if (this.platformLogging === 'debug') {
|
|
2835
|
-
this.log.info('[DEBUG]', String(...log));
|
|
2836
|
-
}
|
|
2837
|
-
else if (this.platformLogging === 'debugMode') {
|
|
2838
|
-
this.log.debug(String(...log));
|
|
2839
|
-
}
|
|
2840
|
-
}
|
|
2841
|
-
}
|
|
2842
|
-
async loggingIsDebug() {
|
|
2843
|
-
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug';
|
|
2844
|
-
}
|
|
2845
|
-
async enablingPlatformLogging() {
|
|
2846
|
-
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug' || this.platformLogging === 'standard';
|
|
2847
|
-
}
|
|
2848
2848
|
}
|
|
2849
2849
|
//# sourceMappingURL=platform-hap.js.map
|