@switchbot/homebridge-switchbot 5.0.0-beta.13 → 5.0.0-beta.15

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.
@@ -1 +1 @@
1
- <!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>default | @switchbot/homebridge-switchbot</title><meta name="description" content="Documentation for @switchbot/homebridge-switchbot"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">@switchbot/homebridge-switchbot</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="" aria-current="page">default</a></li></ul><h1>Variable default</h1></div><div class="tsd-signature"><span class="tsd-kind-variable">default</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=&gt;</span> <span class="tsd-signature-type">void</span></div><div class="tsd-type-declaration"><h4>Type Declaration</h4><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures"><li class="tsd-signature" id="__type"><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">void</span></li><li class="tsd-description"><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">api</span>: <span class="tsd-signature-type">API</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/7d2adea2c154da7cd6b17ef4bdbd7afb31156c7a/src/index.ts#L13">index.ts:13</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">@switchbot/homebridge-switchbot</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
1
+ <!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>default | @switchbot/homebridge-switchbot</title><meta name="description" content="Documentation for @switchbot/homebridge-switchbot"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">@switchbot/homebridge-switchbot</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="" aria-current="page">default</a></li></ul><h1>Variable default</h1></div><div class="tsd-signature"><span class="tsd-kind-variable">default</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=&gt;</span> <span class="tsd-signature-type">void</span></div><div class="tsd-type-declaration"><h4>Type Declaration</h4><ul class="tsd-parameters"><li class="tsd-parameter-signature"><ul class="tsd-signatures"><li class="tsd-signature" id="__type"><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">api</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">API</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">void</span></li><li class="tsd-description"><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">api</span>: <span class="tsd-signature-type">API</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/df1de068624c3046af5b753ce3eb5602cea3aa35/src/index.ts#L13">index.ts:13</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">@switchbot/homebridge-switchbot</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@switchbot/homebridge-switchbot",
3
3
  "displayName": "SwitchBot",
4
4
  "type": "module",
5
- "version": "5.0.0-beta.13",
5
+ "version": "5.0.0-beta.15",
6
6
  "description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
7
7
  "author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
8
8
  "contributors": [
@@ -744,60 +744,133 @@ export abstract class deviceBase {
744
744
  * Logging for Device
745
745
  */
746
746
  infoLog(...log: any[]): void {
747
- if (this.enablingDeviceLogging()) {
748
- this.log.info(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
747
+ if (!this.enablingDeviceLogging()) {
748
+ return
749
749
  }
750
+ const pInfo = (this.platform as any)?.infoLog
751
+ if (typeof pInfo === 'function') {
752
+ try {
753
+ pInfo(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
754
+ return
755
+ } catch (_) {
756
+ // fallthrough to local logger
757
+ }
758
+ }
759
+ this.log.info(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
750
760
  }
751
761
 
752
762
  successLog(...log: any[]): void {
753
- if (this.enablingDeviceLogging()) {
754
- this.log.success(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
763
+ if (!this.enablingDeviceLogging()) {
764
+ return
765
+ }
766
+ const pSuccess = (this.platform as any)?.successLog
767
+ if (typeof pSuccess === 'function') {
768
+ try {
769
+ pSuccess(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
770
+ return
771
+ } catch (_) {}
755
772
  }
773
+ this.log.success(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
756
774
  }
757
775
 
758
776
  debugSuccessLog(...log: any[]): void {
759
- if (this.enablingDeviceLogging()) {
760
- if (this.loggingIsDebug()) {
761
- this.log.success(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
762
- }
777
+ if (!this.enablingDeviceLogging()) {
778
+ return
779
+ }
780
+ if (!this.loggingIsDebug()) {
781
+ return
763
782
  }
783
+ const pDbgSuccess = (this.platform as any)?.debugSuccessLog
784
+ if (typeof pDbgSuccess === 'function') {
785
+ try {
786
+ pDbgSuccess(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
787
+ return
788
+ } catch (_) {}
789
+ }
790
+ this.log.success(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
764
791
  }
765
792
 
766
793
  warnLog(...log: any[]): void {
767
- if (this.enablingDeviceLogging()) {
768
- this.log.warn(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
794
+ if (!this.enablingDeviceLogging()) {
795
+ return
796
+ }
797
+ const pWarn = (this.platform as any)?.warnLog
798
+ if (typeof pWarn === 'function') {
799
+ try {
800
+ pWarn(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
801
+ return
802
+ } catch (_) {}
769
803
  }
804
+ this.log.warn(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
770
805
  }
771
806
 
772
807
  debugWarnLog(...log: any[]): void {
773
- if (this.enablingDeviceLogging()) {
774
- if (this.loggingIsDebug()) {
775
- this.log.warn(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
776
- }
808
+ if (!this.enablingDeviceLogging() || !this.loggingIsDebug()) {
809
+ return
810
+ }
811
+ const pDbgWarn = (this.platform as any)?.debugWarnLog
812
+ if (typeof pDbgWarn === 'function') {
813
+ try {
814
+ pDbgWarn(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
815
+ return
816
+ } catch (_) {}
777
817
  }
818
+ this.log.warn(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
778
819
  }
779
820
 
780
821
  errorLog(...log: any[]): void {
781
- if (this.enablingDeviceLogging()) {
782
- this.log.error(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
822
+ if (!this.enablingDeviceLogging()) {
823
+ return
783
824
  }
825
+ const pErr = (this.platform as any)?.errorLog
826
+ if (typeof pErr === 'function') {
827
+ try {
828
+ pErr(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
829
+ return
830
+ } catch (_) {}
831
+ }
832
+ this.log.error(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
784
833
  }
785
834
 
786
835
  debugErrorLog(...log: any[]): void {
787
- if (this.enablingDeviceLogging()) {
788
- if (this.loggingIsDebug()) {
789
- this.log.error(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
790
- }
836
+ if (!this.enablingDeviceLogging() || !this.loggingIsDebug()) {
837
+ return
838
+ }
839
+ const pDbgErr = (this.platform as any)?.debugErrorLog
840
+ if (typeof pDbgErr === 'function') {
841
+ try {
842
+ pDbgErr(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
843
+ return
844
+ } catch (_) {}
791
845
  }
846
+ this.log.error(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
792
847
  }
793
848
 
794
849
  debugLog(...log: any[]): void {
795
- if (this.enablingDeviceLogging()) {
796
- if (this.deviceLogging === 'debug') {
797
- this.log.info(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
798
- } else if (this.deviceLogging === 'debugMode') {
799
- this.log.debug(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
850
+ if (!this.enablingDeviceLogging()) {
851
+ return
852
+ }
853
+ const pDbg = (this.platform as any)?.debugLog
854
+ if (this.deviceLogging === 'debug') {
855
+ if (typeof pDbg === 'function') {
856
+ try {
857
+ pDbg(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
858
+ return
859
+ } catch (_err) {
860
+ // fallthrough to local logger
861
+ }
862
+ }
863
+ this.log.info(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
864
+ } else if (this.deviceLogging === 'debugMode') {
865
+ if (typeof pDbg === 'function') {
866
+ try {
867
+ pDbg(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
868
+ return
869
+ } catch (_err) {
870
+ // fallthrough to local logger
871
+ }
800
872
  }
873
+ this.log.debug(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
801
874
  }
802
875
  }
803
876
 
@@ -88,25 +88,49 @@ export abstract class BaseMatterAccessory implements MatterAccessory {
88
88
  */
89
89
  protected async updateState(cluster: string, attributes: Record<string, unknown>): Promise<void> {
90
90
  await this.api.matter.updateAccessoryState(this.uuid, cluster, attributes)
91
- this.log.debug(`[${this.displayName}] Updated ${cluster} state:`, attributes)
91
+ this.logDebug(`Updated ${cluster} state:`, attributes)
92
92
  }
93
93
 
94
94
  /**
95
95
  * Log helper methods
96
96
  */
97
97
  protected logInfo(message: string, ...args: unknown[]): void {
98
+ const ctx: any = this.context as any
99
+ const pInfo = ctx?.infoLog
100
+ if (typeof pInfo === 'function') {
101
+ pInfo(`[${this.displayName}] ${message}`, ...args)
102
+ return
103
+ }
98
104
  this.log.info(`[${this.displayName}] ${message}`, ...args)
99
105
  }
100
106
 
101
107
  protected logError(message: string, ...args: unknown[]): void {
108
+ const ctx: any = this.context as any
109
+ const pErr = ctx?.errorLog
110
+ if (typeof pErr === 'function') {
111
+ pErr(`[${this.displayName}] ${message}`, ...args)
112
+ return
113
+ }
102
114
  this.log.error(`[${this.displayName}] ${message}`, ...args)
103
115
  }
104
116
 
105
117
  protected logDebug(message: string, ...args: unknown[]): void {
118
+ const ctx: any = this.context as any
119
+ const pDbg = ctx?.debugLog
120
+ if (typeof pDbg === 'function') {
121
+ pDbg(`[${this.displayName}] ${message}`, ...args)
122
+ return
123
+ }
106
124
  this.log.debug(`[${this.displayName}] ${message}`, ...args)
107
125
  }
108
126
 
109
127
  protected logWarn(message: string, ...args: unknown[]): void {
128
+ const ctx: any = this.context as any
129
+ const pWarn = ctx?.warnLog
130
+ if (typeof pWarn === 'function') {
131
+ pWarn(`[${this.displayName}] ${message}`, ...args)
132
+ return
133
+ }
110
134
  this.log.warn(`[${this.displayName}] ${message}`, ...args)
111
135
  }
112
136
 
@@ -277,60 +277,151 @@ export abstract class irdeviceBase {
277
277
  * Logging for Device
278
278
  */
279
279
  async infoLog(...log: any[]): Promise<void> {
280
- if (await this.enablingDeviceLogging()) {
281
- this.log.info(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
280
+ if (!(await this.enablingDeviceLogging())) {
281
+ return
282
282
  }
283
+ const pInfo = (this.platform as any)?.infoLog
284
+ if (typeof pInfo === 'function') {
285
+ try {
286
+ pInfo(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
287
+ return
288
+ } catch (_err) {
289
+ // fallthrough
290
+ }
291
+ }
292
+ this.log.info(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
283
293
  }
284
294
 
285
295
  async successLog(...log: any[]): Promise<void> {
286
- if (await this.enablingDeviceLogging()) {
287
- this.log.success(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
296
+ if (!(await this.enablingDeviceLogging())) {
297
+ return
298
+ }
299
+ const pSuccess = (this.platform as any)?.successLog
300
+ if (typeof pSuccess === 'function') {
301
+ try {
302
+ pSuccess(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
303
+ return
304
+ } catch (_err) {
305
+ // fallthrough
306
+ }
288
307
  }
308
+ this.log.success(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
289
309
  }
290
310
 
291
311
  async debugSuccessLog(...log: any[]): Promise<void> {
292
- if (await this.enablingDeviceLogging()) {
293
- if (await this.loggingIsDebug()) {
294
- this.log.success(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
312
+ if (!(await this.enablingDeviceLogging())) {
313
+ return
314
+ }
315
+ if (!(await this.loggingIsDebug())) {
316
+ return
317
+ }
318
+ const pDbgSuccess = (this.platform as any)?.debugSuccessLog
319
+ if (typeof pDbgSuccess === 'function') {
320
+ try {
321
+ pDbgSuccess(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
322
+ return
323
+ } catch (_err) {
324
+ // fallthrough
295
325
  }
296
326
  }
327
+ this.log.success(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
297
328
  }
298
329
 
299
330
  async warnLog(...log: any[]): Promise<void> {
300
- if (await this.enablingDeviceLogging()) {
301
- this.log.warn(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
331
+ if (!(await this.enablingDeviceLogging())) {
332
+ return
333
+ }
334
+ const pWarn = (this.platform as any)?.warnLog
335
+ if (typeof pWarn === 'function') {
336
+ try {
337
+ pWarn(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
338
+ return
339
+ } catch (_err) {
340
+ // fallthrough
341
+ }
302
342
  }
343
+ this.log.warn(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
303
344
  }
304
345
 
305
346
  async debugWarnLog(...log: any[]): Promise<void> {
306
- if (await this.enablingDeviceLogging()) {
307
- if (await this.loggingIsDebug()) {
308
- this.log.warn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
347
+ if (!(await this.enablingDeviceLogging())) {
348
+ return
349
+ }
350
+ if (!(await this.loggingIsDebug())) {
351
+ return
352
+ }
353
+ const pDbgWarn = (this.platform as any)?.debugWarnLog
354
+ if (typeof pDbgWarn === 'function') {
355
+ try {
356
+ pDbgWarn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
357
+ return
358
+ } catch (_err) {
359
+ // fallthrough
309
360
  }
310
361
  }
362
+ this.log.warn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
311
363
  }
312
364
 
313
365
  async errorLog(...log: any[]): Promise<void> {
314
- if (await this.enablingDeviceLogging()) {
315
- this.log.error(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
366
+ if (!(await this.enablingDeviceLogging())) {
367
+ return
368
+ }
369
+ const pErr = (this.platform as any)?.errorLog
370
+ if (typeof pErr === 'function') {
371
+ try {
372
+ pErr(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
373
+ return
374
+ } catch (_err) {
375
+ // fallthrough
376
+ }
316
377
  }
378
+ this.log.error(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
317
379
  }
318
380
 
319
381
  async debugErrorLog(...log: any[]): Promise<void> {
320
- if (await this.enablingDeviceLogging()) {
321
- if (await this.loggingIsDebug()) {
322
- this.log.error(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
382
+ if (!(await this.enablingDeviceLogging())) {
383
+ return
384
+ }
385
+ if (!(await this.loggingIsDebug())) {
386
+ return
387
+ }
388
+ const pDbgErr = (this.platform as any)?.debugErrorLog
389
+ if (typeof pDbgErr === 'function') {
390
+ try {
391
+ pDbgErr(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
392
+ return
393
+ } catch (_err) {
394
+ // fallthrough
323
395
  }
324
396
  }
397
+ this.log.error(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
325
398
  }
326
399
 
327
400
  async debugLog(...log: any[]): Promise<void> {
328
- if (await this.enablingDeviceLogging()) {
329
- if (this.deviceLogging === 'debug') {
330
- this.log.info(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
331
- } else if (this.deviceLogging === 'debugMode') {
332
- this.log.debug(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
401
+ if (!(await this.enablingDeviceLogging())) {
402
+ return
403
+ }
404
+ const pDbg = (this.platform as any)?.debugLog
405
+ if (this.deviceLogging === 'debug') {
406
+ if (typeof pDbg === 'function') {
407
+ try {
408
+ pDbg(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
409
+ return
410
+ } catch (_err) {
411
+ // fallthrough
412
+ }
413
+ }
414
+ this.log.info(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
415
+ } else if (this.deviceLogging === 'debugMode') {
416
+ if (typeof pDbg === 'function') {
417
+ try {
418
+ pDbg(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
419
+ return
420
+ } catch (_err) {
421
+ // fallthrough
422
+ }
333
423
  }
424
+ this.log.debug(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log))
334
425
  }
335
426
  }
336
427
 
@@ -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 { 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']
@@ -104,9 +116,22 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
104
116
  this.api = api
105
117
  this.log = log
106
118
 
119
+ // Attach shared platform logging helpers (moved to utils for reuse)
120
+ const _pl = createPlatformLogger(async () => this.platformLogging, this.log)
121
+ this.infoLog = _pl.infoLog
122
+ this.successLog = _pl.successLog
123
+ this.debugSuccessLog = _pl.debugSuccessLog
124
+ this.warnLog = _pl.warnLog
125
+ this.debugWarnLog = _pl.debugWarnLog
126
+ this.errorLog = _pl.errorLog
127
+ this.debugErrorLog = _pl.debugErrorLog
128
+ this.debugLog = _pl.debugLog
129
+ this.loggingIsDebug = _pl.loggingIsDebug
130
+ this.enablingPlatformLogging = _pl.enablingPlatformLogging
131
+
107
132
  // only load if configured
108
133
  if (!config) {
109
- this.log.error('No configuration found for the plugin, please check your config.')
134
+ this.errorLog('No configuration found for the plugin, please check your config.')
110
135
  return
111
136
  }
112
137
 
@@ -207,15 +232,15 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
207
232
  try {
208
233
  // Does the user have a version of Homebridge that is compatible with matter?
209
234
  if (!this.api.isMatterAvailable?.()) {
210
- this.log.debug(`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)'}`)
235
+ 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)'}`)
211
236
  }
212
237
  if (!this.api.isMatterEnabled?.()) {
213
- this.log.debug(`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)'}`)
238
+ 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)'}`)
214
239
  }
215
240
  if (!this.api.isMatterAvailable?.() && !this.api.isMatterEnabled?.()) {
216
241
  await this.discoverDevices()
217
242
  } else {
218
- this.log.info('Matter is enabled in Homebridge. SwitchBot Matter devices will be handled by the Matter platform.')
243
+ this.infoLog('Matter is enabled in Homebridge. SwitchBot Matter devices will be handled by the Matter platform.')
219
244
  }
220
245
  } catch (e: any) {
221
246
  this.errorLog(`Failed to Discover, Error Message: ${e.message ?? e}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug')
@@ -2924,74 +2949,4 @@ export class SwitchBotHAPPlatform implements DynamicPlatformPlugin {
2924
2949
  return value
2925
2950
  }
2926
2951
  }
2927
-
2928
- /**
2929
- * If device level logging is turned on, log to log.warn
2930
- * Otherwise send debug logs to log.debug
2931
- */
2932
- async infoLog(...log: any[]): Promise<void> {
2933
- if (await this.enablingPlatformLogging()) {
2934
- this.log.info(String(...log))
2935
- }
2936
- }
2937
-
2938
- async successLog(...log: any[]): Promise<void> {
2939
- if (await this.enablingPlatformLogging()) {
2940
- this.log.success(String(...log))
2941
- }
2942
- }
2943
-
2944
- async debugSuccessLog(...log: any[]): Promise<void> {
2945
- if (await this.enablingPlatformLogging()) {
2946
- if (await this.loggingIsDebug()) {
2947
- this.log.success('[DEBUG]', String(...log))
2948
- }
2949
- }
2950
- }
2951
-
2952
- async warnLog(...log: any[]): Promise<void> {
2953
- if (await this.enablingPlatformLogging()) {
2954
- this.log.warn(String(...log))
2955
- }
2956
- }
2957
-
2958
- async debugWarnLog(...log: any[]): Promise<void> {
2959
- if (await this.enablingPlatformLogging()) {
2960
- if (await this.loggingIsDebug()) {
2961
- this.log.warn('[DEBUG]', String(...log))
2962
- }
2963
- }
2964
- }
2965
-
2966
- async errorLog(...log: any[]): Promise<void> {
2967
- if (await this.enablingPlatformLogging()) {
2968
- this.log.error(String(...log))
2969
- }
2970
- }
2971
-
2972
- async debugErrorLog(...log: any[]): Promise<void> {
2973
- if (await this.enablingPlatformLogging()) {
2974
- if (await this.loggingIsDebug()) {
2975
- this.log.error('[DEBUG]', String(...log))
2976
- }
2977
- }
2978
- }
2979
-
2980
- async debugLog(...log: any[]): Promise<void> {
2981
- if (await this.enablingPlatformLogging()) {
2982
- if (this.platformLogging === 'debug') {
2983
- this.log.info('[DEBUG]', String(...log))
2984
- } else if (this.platformLogging === 'debugMode') {
2985
- this.log.debug(String(...log))
2986
- }
2987
- }
2988
- }
2989
-
2990
- async loggingIsDebug(): Promise<boolean> {
2991
- return this.platformLogging === 'debugMode' || this.platformLogging === 'debug'
2992
- }
2993
-
2994
- async enablingPlatformLogging(): Promise<boolean> {
2995
- return this.platformLogging === 'debugMode' || this.platformLogging === 'debug' || this.platformLogging === 'standard'
2996
- }
2997
2952
  }