@switchbot/homebridge-switchbot 5.0.0-beta.3 → 5.0.0-beta.30
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/config.schema.json +42 -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 +85 -6
- package/dist/platform-matter.d.ts.map +1 -1
- package/dist/platform-matter.js +1736 -84
- package/dist/platform-matter.js.map +1 -1
- package/dist/settings.d.ts +9 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/test/devices-matter/baseMatterAccessory.test.d.ts +2 -0
- package/dist/test/devices-matter/baseMatterAccessory.test.d.ts.map +1 -0
- package/dist/test/devices-matter/baseMatterAccessory.test.js +71 -0
- package/dist/test/devices-matter/baseMatterAccessory.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/platform-matter.additional.test.d.ts +2 -0
- package/dist/test/platform-matter.additional.test.d.ts.map +1 -0
- package/dist/test/platform-matter.additional.test.js +35 -0
- package/dist/test/platform-matter.additional.test.js.map +1 -0
- package/dist/test/platform-matter.bleparse.test.d.ts +2 -0
- package/dist/test/platform-matter.bleparse.test.d.ts.map +1 -0
- package/dist/test/platform-matter.bleparse.test.js +43 -0
- package/dist/test/platform-matter.bleparse.test.js.map +1 -0
- package/dist/test/platform-matter.cleanup.test.d.ts +2 -0
- package/dist/test/platform-matter.cleanup.test.d.ts.map +1 -0
- package/dist/test/platform-matter.cleanup.test.js +70 -0
- package/dist/test/platform-matter.cleanup.test.js.map +1 -0
- package/dist/test/platform-matter.keepstale.test.d.ts +2 -0
- package/dist/test/platform-matter.keepstale.test.d.ts.map +1 -0
- package/dist/test/platform-matter.keepstale.test.js +27 -0
- package/dist/test/platform-matter.keepstale.test.js.map +1 -0
- package/dist/test/platform-matter.mapping.test.d.ts +2 -0
- package/dist/test/platform-matter.mapping.test.d.ts.map +1 -0
- package/dist/test/platform-matter.mapping.test.js +43 -0
- package/dist/test/platform-matter.mapping.test.js.map +1 -0
- package/dist/test/platform-matter.openapi-mapping.test.d.ts +2 -0
- package/dist/test/platform-matter.openapi-mapping.test.d.ts.map +1 -0
- package/dist/test/platform-matter.openapi-mapping.test.js +84 -0
- package/dist/test/platform-matter.openapi-mapping.test.js.map +1 -0
- package/dist/test/platform-matter.test.d.ts +2 -0
- package/dist/test/platform-matter.test.d.ts.map +1 -0
- package/dist/test/platform-matter.test.js +117 -0
- package/dist/test/platform-matter.test.js.map +1 -0
- package/dist/test/platform-matter.unregister.test.d.ts +2 -0
- package/dist/test/platform-matter.unregister.test.d.ts.map +1 -0
- package/dist/test/platform-matter.unregister.test.js +30 -0
- package/dist/test/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 +380 -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 +2 -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 +1772 -87
- package/src/settings.ts +13 -0
- package/src/test/devices-matter/baseMatterAccessory.test.ts +88 -0
- package/src/test/helpers/platform-fixtures.ts +33 -0
- package/src/test/platform-matter.additional.test.ts +44 -0
- package/src/test/platform-matter.bleparse.test.ts +47 -0
- package/src/test/platform-matter.cleanup.test.ts +86 -0
- package/src/test/platform-matter.keepstale.test.ts +37 -0
- package/src/test/platform-matter.mapping.test.ts +57 -0
- package/src/test/platform-matter.openapi-mapping.test.ts +109 -0
- package/src/test/platform-matter.test.ts +144 -0
- package/src/test/platform-matter.unregister.test.ts +39 -0
- package/src/utils.test.ts +96 -0
- package/src/utils.ts +391 -3
- package/src/verifyconfig.test.ts +11 -10
package/src/irdevice/irdevice.ts
CHANGED
|
@@ -276,69 +276,108 @@ export abstract class irdeviceBase {
|
|
|
276
276
|
/**
|
|
277
277
|
* Logging for Device
|
|
278
278
|
*/
|
|
279
|
-
|
|
280
|
-
if (
|
|
281
|
-
|
|
279
|
+
infoLog(...log: any[]): void {
|
|
280
|
+
if (!this.enablingDeviceLogging()) {
|
|
281
|
+
return
|
|
282
282
|
}
|
|
283
|
+
// Delegate to a single helper that prefers platform-provided loggers.
|
|
284
|
+
this.logWith('info', `${this.device.remoteType}: ${this.accessory.displayName}`, undefined, String(...log))
|
|
283
285
|
}
|
|
284
286
|
|
|
285
|
-
|
|
286
|
-
if (
|
|
287
|
-
|
|
287
|
+
successLog(...log: any[]): void {
|
|
288
|
+
if (!this.enablingDeviceLogging()) {
|
|
289
|
+
return
|
|
288
290
|
}
|
|
291
|
+
this.logWith('success', `${this.device.remoteType}: ${this.accessory.displayName}`, undefined, String(...log))
|
|
289
292
|
}
|
|
290
293
|
|
|
291
|
-
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
294
|
+
debugSuccessLog(...log: any[]): void {
|
|
295
|
+
if (!this.enablingDeviceLogging()) {
|
|
296
|
+
return
|
|
297
|
+
}
|
|
298
|
+
if (!this.loggingIsDebug()) {
|
|
299
|
+
return
|
|
296
300
|
}
|
|
301
|
+
this.logWith('success', `[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, 'debugSuccessLog', String(...log))
|
|
297
302
|
}
|
|
298
303
|
|
|
299
|
-
|
|
300
|
-
if (
|
|
301
|
-
|
|
304
|
+
warnLog(...log: any[]): void {
|
|
305
|
+
if (!this.enablingDeviceLogging()) {
|
|
306
|
+
return
|
|
302
307
|
}
|
|
308
|
+
this.logWith('warn', `${this.device.remoteType}: ${this.accessory.displayName}`, undefined, String(...log))
|
|
303
309
|
}
|
|
304
310
|
|
|
305
|
-
|
|
306
|
-
if (
|
|
307
|
-
|
|
308
|
-
this.log.warn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
309
|
-
}
|
|
311
|
+
debugWarnLog(...log: any[]): void {
|
|
312
|
+
if (!this.enablingDeviceLogging() || !this.loggingIsDebug()) {
|
|
313
|
+
return
|
|
310
314
|
}
|
|
315
|
+
this.logWith('warn', `[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, 'debugWarnLog', String(...log))
|
|
311
316
|
}
|
|
312
317
|
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
|
|
318
|
+
errorLog(...log: any[]): void {
|
|
319
|
+
if (!this.enablingDeviceLogging()) {
|
|
320
|
+
return
|
|
316
321
|
}
|
|
322
|
+
this.logWith('error', `${this.device.remoteType}: ${this.accessory.displayName}`, undefined, String(...log))
|
|
317
323
|
}
|
|
318
324
|
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
this.log.error(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
|
|
323
|
-
}
|
|
325
|
+
debugErrorLog(...log: any[]): void {
|
|
326
|
+
if (!this.enablingDeviceLogging() || !this.loggingIsDebug()) {
|
|
327
|
+
return
|
|
324
328
|
}
|
|
329
|
+
this.logWith('error', `[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, 'debugErrorLog', String(...log))
|
|
325
330
|
}
|
|
326
331
|
|
|
327
|
-
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
332
|
+
debugLog(...log: any[]): void {
|
|
333
|
+
if (!this.enablingDeviceLogging()) {
|
|
334
|
+
return
|
|
335
|
+
}
|
|
336
|
+
if (this.deviceLogging === 'debug') {
|
|
337
|
+
this.logWith('debug', `[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, 'debugLog', String(...log))
|
|
338
|
+
} else if (this.deviceLogging === 'debugMode') {
|
|
339
|
+
this.logWith('debug', `${this.device.remoteType}: ${this.accessory.displayName}`, 'debugLog', String(...log))
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Generic platform/local logger delegate
|
|
344
|
+
protected logWith(level: string, message: string, platformMethodName?: string, payload?: string): void {
|
|
345
|
+
const method = platformMethodName ?? `${level}Log`
|
|
346
|
+
const pFn = (this.platform as any)?.[method]
|
|
347
|
+
if (typeof pFn === 'function') {
|
|
348
|
+
try {
|
|
349
|
+
if (payload !== undefined) {
|
|
350
|
+
pFn(message, payload)
|
|
351
|
+
} else {
|
|
352
|
+
pFn(message)
|
|
353
|
+
}
|
|
354
|
+
return
|
|
355
|
+
} catch (_err) {
|
|
356
|
+
// fallthrough to local logger
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const map: Record<string, string> = {
|
|
360
|
+
info: 'info',
|
|
361
|
+
success: 'success',
|
|
362
|
+
debug: 'debug',
|
|
363
|
+
warn: 'warn',
|
|
364
|
+
error: 'error',
|
|
365
|
+
}
|
|
366
|
+
const local = (this.log as any)[map[level] ?? level]
|
|
367
|
+
if (typeof local === 'function') {
|
|
368
|
+
if (payload !== undefined) {
|
|
369
|
+
local.call(this.log, message, payload)
|
|
370
|
+
} else {
|
|
371
|
+
local.call(this.log, message)
|
|
333
372
|
}
|
|
334
373
|
}
|
|
335
374
|
}
|
|
336
375
|
|
|
337
|
-
|
|
376
|
+
loggingIsDebug(): boolean {
|
|
338
377
|
return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug'
|
|
339
378
|
}
|
|
340
379
|
|
|
341
|
-
|
|
380
|
+
enablingDeviceLogging(): boolean {
|
|
342
381
|
return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug' || this.deviceLogging === 'standard'
|
|
343
382
|
}
|
|
344
383
|
}
|
package/src/platform-hap.ts
CHANGED
|
@@ -55,7 +55,7 @@ import { TV } from './irdevice/tv.js'
|
|
|
55
55
|
import { VacuumCleaner } from './irdevice/vacuumcleaner.js'
|
|
56
56
|
import { WaterHeater } from './irdevice/waterheater.js'
|
|
57
57
|
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'
|
|
58
|
-
import { cleanDeviceConfig, formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, safeStringify, sleep } from './utils.js'
|
|
58
|
+
import { ApiRequestTracker, cleanDeviceConfig, createPlatformLogger, formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, safeStringify, sleep } from './utils.js'
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* HomebridgePlatform
|
|
@@ -68,6 +68,18 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
|
|
|
68
68
|
public readonly api: API
|
|
69
69
|
public readonly log: Logging
|
|
70
70
|
|
|
71
|
+
// Logging helper functions (attached from utils.createPlatformLogger in constructor)
|
|
72
|
+
infoLog!: (...log: any[]) => Promise<void>
|
|
73
|
+
successLog!: (...log: any[]) => Promise<void>
|
|
74
|
+
debugSuccessLog!: (...log: any[]) => Promise<void>
|
|
75
|
+
warnLog!: (...log: any[]) => Promise<void>
|
|
76
|
+
debugWarnLog!: (...log: any[]) => Promise<void>
|
|
77
|
+
errorLog!: (...log: any[]) => Promise<void>
|
|
78
|
+
debugErrorLog!: (...log: any[]) => Promise<void>
|
|
79
|
+
debugLog!: (...log: any[]) => Promise<void>
|
|
80
|
+
loggingIsDebug!: () => Promise<boolean>
|
|
81
|
+
enablingPlatformLogging!: () => Promise<boolean>
|
|
82
|
+
|
|
71
83
|
// Configuration properties
|
|
72
84
|
platformConfig!: SwitchBotPlatformConfig
|
|
73
85
|
platformLogging!: options['logging']
|
|
@@ -88,6 +100,9 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
|
|
|
88
100
|
switchBotAPI!: SwitchBotOpenAPI
|
|
89
101
|
switchBotBLE!: SwitchBotBLE
|
|
90
102
|
|
|
103
|
+
// API request tracking
|
|
104
|
+
private apiTracker?: ApiRequestTracker
|
|
105
|
+
|
|
91
106
|
// External APIs
|
|
92
107
|
public readonly eve: any
|
|
93
108
|
public readonly fakegatoAPI: any
|
|
@@ -104,9 +119,22 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
|
|
|
104
119
|
this.api = api
|
|
105
120
|
this.log = log
|
|
106
121
|
|
|
122
|
+
// Attach shared platform logging helpers (moved to utils for reuse)
|
|
123
|
+
const _pl = createPlatformLogger(async () => this.platformLogging, this.log)
|
|
124
|
+
this.infoLog = _pl.infoLog
|
|
125
|
+
this.successLog = _pl.successLog
|
|
126
|
+
this.debugSuccessLog = _pl.debugSuccessLog
|
|
127
|
+
this.warnLog = _pl.warnLog
|
|
128
|
+
this.debugWarnLog = _pl.debugWarnLog
|
|
129
|
+
this.errorLog = _pl.errorLog
|
|
130
|
+
this.debugErrorLog = _pl.debugErrorLog
|
|
131
|
+
this.debugLog = _pl.debugLog
|
|
132
|
+
this.loggingIsDebug = _pl.loggingIsDebug
|
|
133
|
+
this.enablingPlatformLogging = _pl.enablingPlatformLogging
|
|
134
|
+
|
|
107
135
|
// only load if configured
|
|
108
136
|
if (!config) {
|
|
109
|
-
this.
|
|
137
|
+
this.errorLog('No configuration found for the plugin, please check your config.')
|
|
110
138
|
return
|
|
111
139
|
}
|
|
112
140
|
|
|
@@ -119,6 +147,20 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
|
|
|
119
147
|
devices: config.devices as { deviceId: string }[],
|
|
120
148
|
}
|
|
121
149
|
|
|
150
|
+
// Determine platform logging preference (match HAP behaviour as closely as
|
|
151
|
+
// possible using config values. We default to 'standard' when unspecified.)
|
|
152
|
+
this.platformLogging = (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none')
|
|
153
|
+
? this.config.options.logging
|
|
154
|
+
: 'standard'
|
|
155
|
+
|
|
156
|
+
// Unconditional diagnostic using the raw Homebridge `log` so it always
|
|
157
|
+
// appears regardless of the platform logging helpers' gating logic.
|
|
158
|
+
try {
|
|
159
|
+
this.log.debug?.(`[SwitchBot HAP] effective platformLogging=${String(this.platformLogging)}`)
|
|
160
|
+
} catch (e: any) {
|
|
161
|
+
// swallow any logging errors — diagnostics are best-effort
|
|
162
|
+
}
|
|
163
|
+
|
|
122
164
|
// Normalize deviceConfig to remove UI-inserted defaults (lots of false/empty values)
|
|
123
165
|
try {
|
|
124
166
|
if ((this.config as any).options) {
|
|
@@ -203,9 +245,29 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
|
|
|
203
245
|
// to start discovery of new accessories.
|
|
204
246
|
this.api.on('didFinishLaunching', async () => {
|
|
205
247
|
this.debugLog('Executed didFinishLaunching callback')
|
|
248
|
+
|
|
249
|
+
// Initialize API request tracking
|
|
250
|
+
try {
|
|
251
|
+
this.apiTracker = new ApiRequestTracker(this.api, this.log, 'SwitchBot HAP')
|
|
252
|
+
this.apiTracker.startHourlyLogging()
|
|
253
|
+
} catch (e: any) {
|
|
254
|
+
this.errorLog(`Failed to initialize API request tracking: ${e.message ?? e}`)
|
|
255
|
+
}
|
|
256
|
+
|
|
206
257
|
// run the method to discover / register your devices as accessories
|
|
207
258
|
try {
|
|
208
|
-
|
|
259
|
+
// Does the user have a version of Homebridge that is compatible with matter?
|
|
260
|
+
if (!this.api.isMatterAvailable?.()) {
|
|
261
|
+
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)'}`)
|
|
262
|
+
}
|
|
263
|
+
if (!this.api.isMatterEnabled?.()) {
|
|
264
|
+
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)'}`)
|
|
265
|
+
}
|
|
266
|
+
if (!this.api.isMatterAvailable?.() && !this.api.isMatterEnabled?.()) {
|
|
267
|
+
await this.discoverDevices()
|
|
268
|
+
} else {
|
|
269
|
+
this.infoLog('Matter is enabled in Homebridge. SwitchBot Matter devices will be handled by the Matter platform.')
|
|
270
|
+
}
|
|
209
271
|
} catch (e: any) {
|
|
210
272
|
this.errorLog(`Failed to Discover, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
|
|
211
273
|
this.debugErrorLog(`Failed to Discover, Error: ${e.message ?? e}`)
|
|
@@ -440,6 +502,7 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
|
|
|
440
502
|
|
|
441
503
|
while (retryCount < maxRetries) {
|
|
442
504
|
try {
|
|
505
|
+
this.apiTracker?.track()
|
|
443
506
|
const { response, statusCode } = await this.switchBotAPI.getDevices()
|
|
444
507
|
this.debugLog(`response: ${JSON.stringify(response)}`)
|
|
445
508
|
if (this.isSuccessfulResponse(statusCode)) {
|
|
@@ -2752,6 +2815,7 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
|
|
|
2752
2815
|
const delayBetweenRetries = deviceDelayBetweenRetries
|
|
2753
2816
|
while (retryCount < maxRetries) {
|
|
2754
2817
|
try {
|
|
2818
|
+
this.apiTracker?.track()
|
|
2755
2819
|
const { response, statusCode } = await this.switchBotAPI.getDeviceStatus(device.deviceId, this.config.credentials?.token, this.config.credentials?.secret)
|
|
2756
2820
|
this.debugLog(`response: ${JSON.stringify(response)}`)
|
|
2757
2821
|
return { response, statusCode }
|
|
@@ -2777,6 +2841,7 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
|
|
|
2777
2841
|
const delayBetweenRetries = deviceDelayBetweenRetries ?? 1000
|
|
2778
2842
|
while (retryCount < maxRetries) {
|
|
2779
2843
|
try {
|
|
2844
|
+
this.apiTracker?.track()
|
|
2780
2845
|
const { response, statusCode } = await this.switchBotAPI.controlDevice(
|
|
2781
2846
|
device.deviceId,
|
|
2782
2847
|
bodyChange.command,
|
|
@@ -2913,74 +2978,4 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
|
|
|
2913
2978
|
return value
|
|
2914
2979
|
}
|
|
2915
2980
|
}
|
|
2916
|
-
|
|
2917
|
-
/**
|
|
2918
|
-
* If device level logging is turned on, log to log.warn
|
|
2919
|
-
* Otherwise send debug logs to log.debug
|
|
2920
|
-
*/
|
|
2921
|
-
async infoLog(...log: any[]): Promise<void> {
|
|
2922
|
-
if (await this.enablingPlatformLogging()) {
|
|
2923
|
-
this.log.info(String(...log))
|
|
2924
|
-
}
|
|
2925
|
-
}
|
|
2926
|
-
|
|
2927
|
-
async successLog(...log: any[]): Promise<void> {
|
|
2928
|
-
if (await this.enablingPlatformLogging()) {
|
|
2929
|
-
this.log.success(String(...log))
|
|
2930
|
-
}
|
|
2931
|
-
}
|
|
2932
|
-
|
|
2933
|
-
async debugSuccessLog(...log: any[]): Promise<void> {
|
|
2934
|
-
if (await this.enablingPlatformLogging()) {
|
|
2935
|
-
if (await this.loggingIsDebug()) {
|
|
2936
|
-
this.log.success('[DEBUG]', String(...log))
|
|
2937
|
-
}
|
|
2938
|
-
}
|
|
2939
|
-
}
|
|
2940
|
-
|
|
2941
|
-
async warnLog(...log: any[]): Promise<void> {
|
|
2942
|
-
if (await this.enablingPlatformLogging()) {
|
|
2943
|
-
this.log.warn(String(...log))
|
|
2944
|
-
}
|
|
2945
|
-
}
|
|
2946
|
-
|
|
2947
|
-
async debugWarnLog(...log: any[]): Promise<void> {
|
|
2948
|
-
if (await this.enablingPlatformLogging()) {
|
|
2949
|
-
if (await this.loggingIsDebug()) {
|
|
2950
|
-
this.log.warn('[DEBUG]', String(...log))
|
|
2951
|
-
}
|
|
2952
|
-
}
|
|
2953
|
-
}
|
|
2954
|
-
|
|
2955
|
-
async errorLog(...log: any[]): Promise<void> {
|
|
2956
|
-
if (await this.enablingPlatformLogging()) {
|
|
2957
|
-
this.log.error(String(...log))
|
|
2958
|
-
}
|
|
2959
|
-
}
|
|
2960
|
-
|
|
2961
|
-
async debugErrorLog(...log: any[]): Promise<void> {
|
|
2962
|
-
if (await this.enablingPlatformLogging()) {
|
|
2963
|
-
if (await this.loggingIsDebug()) {
|
|
2964
|
-
this.log.error('[DEBUG]', String(...log))
|
|
2965
|
-
}
|
|
2966
|
-
}
|
|
2967
|
-
}
|
|
2968
|
-
|
|
2969
|
-
async debugLog(...log: any[]): Promise<void> {
|
|
2970
|
-
if (await this.enablingPlatformLogging()) {
|
|
2971
|
-
if (this.platformLogging === 'debug') {
|
|
2972
|
-
this.log.info('[DEBUG]', String(...log))
|
|
2973
|
-
} else if (this.platformLogging === 'debugMode') {
|
|
2974
|
-
this.log.debug(String(...log))
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
}
|
|
2978
|
-
|
|
2979
|
-
async loggingIsDebug(): Promise<boolean> {
|
|
2980
|
-
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug'
|
|
2981
|
-
}
|
|
2982
|
-
|
|
2983
|
-
async enablingPlatformLogging(): Promise<boolean> {
|
|
2984
|
-
return this.platformLogging === 'debugMode' || this.platformLogging === 'debug' || this.platformLogging === 'standard'
|
|
2985
|
-
}
|
|
2986
2981
|
}
|