@switchbot/homebridge-switchbot 5.0.0-beta.7 → 5.0.0-beta.70
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 +15 -0
- package/README.md +45 -3
- package/config.schema.json +871 -13754
- package/dist/devices-hap/airpurifier.d.ts.map +1 -1
- package/dist/devices-hap/airpurifier.js +12 -6
- package/dist/devices-hap/airpurifier.js.map +1 -1
- package/dist/devices-hap/blindtilt.js +3 -3
- package/dist/devices-hap/bot.d.ts.map +1 -1
- package/dist/devices-hap/bot.js +16 -5
- package/dist/devices-hap/bot.js.map +1 -1
- package/dist/devices-hap/ceilinglight.d.ts.map +1 -1
- package/dist/devices-hap/ceilinglight.js +13 -7
- package/dist/devices-hap/ceilinglight.js.map +1 -1
- package/dist/devices-hap/colorbulb.d.ts.map +1 -1
- package/dist/devices-hap/colorbulb.js +49 -9
- package/dist/devices-hap/colorbulb.js.map +1 -1
- package/dist/devices-hap/contact.js +3 -3
- package/dist/devices-hap/curtain.js +2 -2
- package/dist/devices-hap/curtain.js.map +1 -1
- package/dist/devices-hap/device.d.ts +18 -8
- package/dist/devices-hap/device.d.ts.map +1 -1
- package/dist/devices-hap/device.js +141 -69
- package/dist/devices-hap/device.js.map +1 -1
- package/dist/devices-hap/fan.d.ts.map +1 -1
- package/dist/devices-hap/fan.js +12 -6
- package/dist/devices-hap/fan.js.map +1 -1
- package/dist/devices-hap/hub.d.ts.map +1 -1
- package/dist/devices-hap/hub.js +6 -5
- package/dist/devices-hap/hub.js.map +1 -1
- package/dist/devices-hap/humidifier.d.ts +5 -0
- package/dist/devices-hap/humidifier.d.ts.map +1 -1
- package/dist/devices-hap/humidifier.js +92 -4
- package/dist/devices-hap/humidifier.js.map +1 -1
- package/dist/devices-hap/iosensor.d.ts.map +1 -1
- package/dist/devices-hap/iosensor.js +36 -21
- package/dist/devices-hap/iosensor.js.map +1 -1
- package/dist/devices-hap/lightstrip.d.ts.map +1 -1
- package/dist/devices-hap/lightstrip.js +38 -8
- package/dist/devices-hap/lightstrip.js.map +1 -1
- package/dist/devices-hap/lock.d.ts.map +1 -1
- package/dist/devices-hap/lock.js +14 -6
- package/dist/devices-hap/lock.js.map +1 -1
- package/dist/devices-hap/meter.d.ts.map +1 -1
- package/dist/devices-hap/meter.js +6 -5
- package/dist/devices-hap/meter.js.map +1 -1
- package/dist/devices-hap/meterplus.d.ts.map +1 -1
- package/dist/devices-hap/meterplus.js +6 -5
- package/dist/devices-hap/meterplus.js.map +1 -1
- package/dist/devices-hap/meterpro.d.ts.map +1 -1
- package/dist/devices-hap/meterpro.js +7 -6
- package/dist/devices-hap/meterpro.js.map +1 -1
- package/dist/devices-hap/motion.js +3 -3
- package/dist/devices-hap/plug.d.ts.map +1 -1
- package/dist/devices-hap/plug.js +11 -6
- package/dist/devices-hap/plug.js.map +1 -1
- package/dist/devices-hap/relayswitch.js +3 -3
- package/dist/devices-hap/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/devices-hap/robotvacuumcleaner.js +13 -6
- package/dist/devices-hap/robotvacuumcleaner.js.map +1 -1
- package/dist/devices-hap/waterdetector.js +3 -3
- package/dist/devices-matter/BaseMatterAccessory.d.ts +27 -0
- package/dist/devices-matter/BaseMatterAccessory.d.ts.map +1 -1
- package/dist/devices-matter/BaseMatterAccessory.js +169 -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/devices-matter/RoboticVacuumAccessory.d.ts +36 -43
- package/dist/devices-matter/RoboticVacuumAccessory.d.ts.map +1 -1
- package/dist/devices-matter/RoboticVacuumAccessory.js +478 -268
- package/dist/devices-matter/RoboticVacuumAccessory.js.map +1 -1
- package/dist/devices-matter/VenetianBlindAccessory.d.ts +6 -6
- package/dist/devices-matter/VenetianBlindAccessory.d.ts.map +1 -1
- package/dist/devices-matter/VenetianBlindAccessory.js.map +1 -1
- package/dist/devices-matter/WindowBlindAccessory.d.ts +5 -5
- package/dist/devices-matter/WindowBlindAccessory.d.ts.map +1 -1
- package/dist/devices-matter/WindowBlindAccessory.js +57 -6
- package/dist/devices-matter/WindowBlindAccessory.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +219 -19
- package/dist/homebridge-ui/server.js +0 -31
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -9
- package/dist/index.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 +26 -15
- package/dist/platform-hap.d.ts.map +1 -1
- package/dist/platform-hap.js +333 -153
- package/dist/platform-hap.js.map +1 -1
- package/dist/platform-matter.d.ts +93 -6
- package/dist/platform-matter.d.ts.map +1 -1
- package/dist/platform-matter.js +1878 -229
- package/dist/platform-matter.js.map +1 -1
- package/dist/settings.d.ts +75 -7
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/test/apiRequestTracker.test.d.ts +2 -0
- package/dist/test/apiRequestTracker.test.d.ts.map +1 -0
- package/dist/test/apiRequestTracker.test.js +392 -0
- package/dist/test/apiRequestTracker.test.js.map +1 -0
- package/dist/test/hap/device-webhook-context.test.d.ts +2 -0
- package/dist/test/hap/device-webhook-context.test.d.ts.map +1 -0
- package/dist/test/hap/device-webhook-context.test.js +128 -0
- package/dist/test/hap/device-webhook-context.test.js.map +1 -0
- 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/homebridge-ui/server.test.d.ts +2 -0
- package/dist/test/homebridge-ui/server.test.d.ts.map +1 -0
- package/dist/test/homebridge-ui/server.test.js +445 -0
- package/dist/test/homebridge-ui/server.test.js.map +1 -0
- package/dist/{index.test.d.ts.map → test/index.test.d.ts.map} +1 -1
- package/dist/test/index.test.js +19 -0
- package/dist/test/index.test.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/test/matter/platform-matter.webhook.test.d.ts +2 -0
- package/dist/test/matter/platform-matter.webhook.test.d.ts.map +1 -0
- package/dist/test/matter/platform-matter.webhook.test.js +46 -0
- package/dist/test/matter/platform-matter.webhook.test.js.map +1 -0
- package/dist/test/utils.test.d.ts +2 -0
- package/dist/test/utils.test.d.ts.map +1 -0
- package/dist/test/utils.test.js +95 -0
- package/dist/test/utils.test.js.map +1 -0
- package/dist/test/verifyconfig.test.d.ts.map +1 -0
- package/dist/{verifyconfig.test.js → test/verifyconfig.test.js} +2 -2
- package/dist/test/verifyconfig.test.js.map +1 -0
- package/dist/utils.d.ts +204 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +713 -33
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +14 -0
- package/docs/assets/main.js +2 -2
- package/docs/index.html +31 -2
- package/docs/variables/default.html +1 -1
- package/package.json +15 -15
- package/src/devices-hap/airpurifier.ts +11 -6
- package/src/devices-hap/blindtilt.ts +3 -3
- package/src/devices-hap/bot.ts +15 -5
- package/src/devices-hap/ceilinglight.ts +12 -7
- package/src/devices-hap/colorbulb.ts +46 -10
- package/src/devices-hap/contact.ts +3 -3
- package/src/devices-hap/curtain.ts +2 -2
- package/src/devices-hap/device.ts +149 -70
- package/src/devices-hap/fan.ts +11 -6
- package/src/devices-hap/hub.ts +6 -5
- package/src/devices-hap/humidifier.ts +97 -4
- package/src/devices-hap/iosensor.ts +36 -21
- package/src/devices-hap/lightstrip.ts +35 -8
- package/src/devices-hap/lock.ts +13 -6
- package/src/devices-hap/meter.ts +6 -5
- package/src/devices-hap/meterplus.ts +6 -5
- package/src/devices-hap/meterpro.ts +7 -6
- package/src/devices-hap/motion.ts +3 -3
- package/src/devices-hap/plug.ts +10 -6
- package/src/devices-hap/relayswitch.ts +3 -3
- package/src/devices-hap/robotvacuumcleaner.ts +12 -6
- package/src/devices-hap/waterdetector.ts +3 -3
- package/src/devices-matter/BaseMatterAccessory.ts +176 -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/devices-matter/RoboticVacuumAccessory.ts +529 -315
- package/src/devices-matter/VenetianBlindAccessory.ts +5 -5
- package/src/devices-matter/WindowBlindAccessory.ts +53 -10
- package/src/homebridge-ui/public/index.html +219 -19
- package/src/homebridge-ui/server.ts +0 -34
- package/src/index.ts +4 -10
- package/src/irdevice/irdevice.ts +74 -35
- package/src/platform-hap.ts +365 -169
- package/src/platform-matter.ts +1923 -230
- package/src/settings.ts +78 -3
- package/src/test/apiRequestTracker.test.ts +417 -0
- package/src/test/hap/device-webhook-context.test.ts +136 -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/homebridge-ui/server.test.ts +486 -0
- package/src/test/index.test.ts +24 -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/test/matter/platform-matter.webhook.test.ts +54 -0
- package/src/test/utils.test.ts +96 -0
- package/src/{verifyconfig.test.ts → test/verifyconfig.test.ts} +12 -11
- package/src/utils.ts +777 -36
- package/dist/index.test.js +0 -14
- package/dist/index.test.js.map +0 -1
- package/dist/verifyconfig.test.d.ts.map +0 -1
- package/dist/verifyconfig.test.js.map +0 -1
- package/src/index.test.ts +0 -19
- /package/dist/{index.test.d.ts → test/index.test.d.ts} +0 -0
- /package/dist/{verifyconfig.test.d.ts → test/verifyconfig.test.d.ts} +0 -0
|
@@ -58,7 +58,7 @@ export class VenetianBlindAccessory extends BaseMatterAccessory {
|
|
|
58
58
|
this.logInfo('initialized.')
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
public async handleGoToLift(request: MatterRequests.GoToLiftPercentage): Promise<void> {
|
|
62
62
|
this.logInfo(`GoToLiftPercentage request: ${JSON.stringify(request)}`)
|
|
63
63
|
|
|
64
64
|
// Matter uses 0=open, 10000=closed, so invert to get open percentage
|
|
@@ -68,7 +68,7 @@ export class VenetianBlindAccessory extends BaseMatterAccessory {
|
|
|
68
68
|
// TODO: await myBlindAPI.setPosition(openPercent)
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
public async handleGoToTilt(request: MatterRequests.GoToTiltPercentage): Promise<void> {
|
|
72
72
|
this.logInfo(`GoToTiltPercentage request: ${JSON.stringify(request)}`)
|
|
73
73
|
|
|
74
74
|
// Matter tilt: 0=horizontal/open (0deg), 10000=vertical/closed (90deg)
|
|
@@ -77,17 +77,17 @@ export class VenetianBlindAccessory extends BaseMatterAccessory {
|
|
|
77
77
|
// TODO: await myBlindAPI.setTiltAngle(degrees)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
public async handleUpOrOpen(): Promise<void> {
|
|
81
81
|
this.logInfo('opened blind.')
|
|
82
82
|
// TODO: await myBlindAPI.open()
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
public async handleDownOrClose(): Promise<void> {
|
|
86
86
|
this.logInfo('closed blind.')
|
|
87
87
|
// TODO: await myBlindAPI.close()
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
public async handleStop(): Promise<void> {
|
|
91
91
|
this.logInfo('stopped blind.')
|
|
92
92
|
// TODO: await myBlindAPI.stop()
|
|
93
93
|
}
|
|
@@ -55,28 +55,71 @@ export class WindowBlindAccessory extends BaseMatterAccessory {
|
|
|
55
55
|
this.logInfo('initialized.')
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
public async handleGoToLift(request: MatterRequests.GoToLiftPercentage): Promise<void> {
|
|
59
59
|
this.logInfo(`GoToLiftPercentage request: ${JSON.stringify(request)}`)
|
|
60
60
|
// Matter uses 0=open, 10000=closed, so invert to get open percentage
|
|
61
61
|
const closedPercent = request.liftPercent100thsValue / 100
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//
|
|
62
|
+
// SwitchBot API expects position: 0=open, 100=closed
|
|
63
|
+
const position = Math.max(0, Math.min(100, closedPercent))
|
|
64
|
+
// Default to performance mode (ff), index is always 0
|
|
65
|
+
const mode = 'ff' // or '01' for silent mode if needed
|
|
66
|
+
const parameter = `0,${mode},${position}`
|
|
67
|
+
this.logInfo(`Sending setPosition to OpenAPI: parameter=${parameter}`)
|
|
68
|
+
try {
|
|
69
|
+
if (this.context?.sendOpenAPI) {
|
|
70
|
+
await this.sendOpenAPICommand('setPosition', parameter)
|
|
71
|
+
this.logInfo('OpenAPI setPosition command sent.')
|
|
72
|
+
} else {
|
|
73
|
+
this.logWarn('OpenAPI sender not available in context.')
|
|
74
|
+
}
|
|
75
|
+
} catch (e: any) {
|
|
76
|
+
this.logWarn(`OpenAPI setPosition failed: ${String(e?.message ?? e)}`)
|
|
77
|
+
}
|
|
65
78
|
}
|
|
66
79
|
|
|
67
|
-
|
|
80
|
+
public async handleUpOrOpen(): Promise<void> {
|
|
68
81
|
this.logInfo('opened blind.')
|
|
69
|
-
|
|
82
|
+
try {
|
|
83
|
+
// Send open command to SwitchBot OpenAPI
|
|
84
|
+
if (this.context?.sendOpenAPI) {
|
|
85
|
+
await this.sendOpenAPICommand('turnOn')
|
|
86
|
+
this.logInfo('OpenAPI open command sent.')
|
|
87
|
+
} else {
|
|
88
|
+
this.logWarn('OpenAPI sender not available in context.')
|
|
89
|
+
}
|
|
90
|
+
} catch (e: any) {
|
|
91
|
+
this.logWarn(`OpenAPI open failed: ${String(e?.message ?? e)}`)
|
|
92
|
+
}
|
|
70
93
|
}
|
|
71
94
|
|
|
72
|
-
|
|
95
|
+
public async handleDownOrClose(): Promise<void> {
|
|
73
96
|
this.logInfo('closed blind.')
|
|
74
|
-
|
|
97
|
+
try {
|
|
98
|
+
// Send close command to SwitchBot OpenAPI
|
|
99
|
+
if (this.context?.sendOpenAPI) {
|
|
100
|
+
await this.sendOpenAPICommand('turnOff')
|
|
101
|
+
this.logInfo('OpenAPI close command sent.')
|
|
102
|
+
} else {
|
|
103
|
+
this.logWarn('OpenAPI sender not available in context.')
|
|
104
|
+
}
|
|
105
|
+
} catch (e: any) {
|
|
106
|
+
this.logWarn(`OpenAPI close failed: ${String(e?.message ?? e)}`)
|
|
107
|
+
}
|
|
75
108
|
}
|
|
76
109
|
|
|
77
|
-
|
|
110
|
+
public async handleStop(): Promise<void> {
|
|
78
111
|
this.logInfo('stopped blind.')
|
|
79
|
-
|
|
112
|
+
try {
|
|
113
|
+
// Send pause command to SwitchBot OpenAPI
|
|
114
|
+
if (this.context?.sendOpenAPI) {
|
|
115
|
+
await this.sendOpenAPICommand('pause')
|
|
116
|
+
this.logInfo('OpenAPI pause command sent.')
|
|
117
|
+
} else {
|
|
118
|
+
this.logWarn('OpenAPI sender not available in context.')
|
|
119
|
+
}
|
|
120
|
+
} catch (e: any) {
|
|
121
|
+
this.logWarn(`OpenAPI pause failed: ${String(e?.message ?? e)}`)
|
|
122
|
+
}
|
|
80
123
|
}
|
|
81
124
|
|
|
82
125
|
public updateLiftPosition(openPercent: number): void {
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
<div id="menuWrapper" class="btn-group w-100 mb-0" role="group" aria-label="UI Menu" style="display: none">
|
|
29
29
|
<button type="button" class="btn btn-primary" id="menuSettings">Settings</button>
|
|
30
30
|
<button type="button" class="btn btn-primary" id="menuDevices">Devices</button>
|
|
31
|
-
<button type="button" class="btn btn-primary
|
|
31
|
+
<button type="button" class="btn btn-primary" id="menuHome">Support</button>
|
|
32
|
+
<button type="button" class="btn btn-primary mr-0" id="dynamic-config-tab">Dynamic Config</button>
|
|
32
33
|
</div>
|
|
33
34
|
<div id="disabledBanner" class="alert alert-secondary mb-0 mt-3" role="alert" style="display: none">
|
|
34
35
|
Plugin is currently disabled
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
</form>
|
|
44
45
|
<table class="table w-100" id="deviceTable" style="display: none">
|
|
45
46
|
<thead>
|
|
46
|
-
<tr
|
|
47
|
+
<tr>
|
|
47
48
|
<th scope="col" style="width: 40%">Device Name</th>
|
|
48
49
|
<th scope="col" style="width: 60%" id="displayName"></th>
|
|
49
50
|
</tr>
|
|
@@ -69,8 +70,22 @@
|
|
|
69
70
|
<th scope="row">Connection Type</th>
|
|
70
71
|
<td id="connectionType"></td>
|
|
71
72
|
</tr>
|
|
73
|
+
<tr>
|
|
74
|
+
<th scope="row">Refresh Rate</th>
|
|
75
|
+
<td id="refreshRate"></td>
|
|
76
|
+
</tr>
|
|
77
|
+
<tr>
|
|
78
|
+
<th scope="row">Update Rate</th>
|
|
79
|
+
<td id="updateRate"></td>
|
|
80
|
+
</tr>
|
|
81
|
+
<tr>
|
|
82
|
+
<th scope="row">Push Rate</th>
|
|
83
|
+
<td id="pushRate"></td>
|
|
84
|
+
</tr>
|
|
72
85
|
</tbody>
|
|
73
86
|
</table>
|
|
87
|
+
<h5 class="mt-4">Cached Accessories</h5>
|
|
88
|
+
<ul id="cachedAccessoriesList"></ul>
|
|
74
89
|
<p class="text-center">External accessories will not be displayed here.</p>
|
|
75
90
|
</div>
|
|
76
91
|
</div>
|
|
@@ -118,10 +133,50 @@
|
|
|
118
133
|
</li>
|
|
119
134
|
</ul>
|
|
120
135
|
</div>
|
|
136
|
+
<div id="dynamic-config-content" class="tab-content" style="display: none;">
|
|
137
|
+
<h2>Dynamic Config</h2>
|
|
138
|
+
<p>Discover and configure devices dynamically.</p>
|
|
139
|
+
<!-- Placeholder for dynamic content -->
|
|
140
|
+
</div>
|
|
121
141
|
<script>
|
|
122
142
|
(async () => {
|
|
123
143
|
try {
|
|
124
144
|
const currentConfig = await homebridge.getPluginConfig();
|
|
145
|
+
|
|
146
|
+
// Defensive wrapper: ensure token/secret aren't accidentally cleared by
|
|
147
|
+
// the UI/schema form. Some versions of config UI can omit sensitive
|
|
148
|
+
// fields from the submitted payload; when that happens we copy the
|
|
149
|
+
// existing values from `currentConfig` into the outgoing payload so
|
|
150
|
+
// saved config does not inadvertently remove credentials.
|
|
151
|
+
try {
|
|
152
|
+
if (typeof homebridge.updatePluginConfig === 'function') {
|
|
153
|
+
const _origUpdatePluginConfig = homebridge.updatePluginConfig.bind(homebridge)
|
|
154
|
+
homebridge.updatePluginConfig = async (cfg) => {
|
|
155
|
+
try {
|
|
156
|
+
if (Array.isArray(cfg) && cfg.length > 0 && Array.isArray(currentConfig) && currentConfig.length > 0) {
|
|
157
|
+
const incoming = cfg[0] || {}
|
|
158
|
+
const existing = currentConfig[0] || {}
|
|
159
|
+
incoming.credentials = incoming.credentials || {}
|
|
160
|
+
// Preserve token/secret when incoming payload leaves them blank/undefined
|
|
161
|
+
if ((incoming.credentials.token === undefined || String(incoming.credentials.token).trim() === '') && existing.credentials && existing.credentials.token) {
|
|
162
|
+
incoming.credentials.token = existing.credentials.token
|
|
163
|
+
}
|
|
164
|
+
if ((incoming.credentials.secret === undefined || String(incoming.credentials.secret).trim() === '') && existing.credentials && existing.credentials.secret) {
|
|
165
|
+
incoming.credentials.secret = existing.credentials.secret
|
|
166
|
+
}
|
|
167
|
+
cfg[0] = incoming
|
|
168
|
+
}
|
|
169
|
+
} catch (e) {
|
|
170
|
+
// Swallow any wrapper errors but log to console for debugging
|
|
171
|
+
// (do not expose secrets).
|
|
172
|
+
console.error('updatePluginConfig wrapper error', e)
|
|
173
|
+
}
|
|
174
|
+
return await _origUpdatePluginConfig(cfg)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
} catch (e) {
|
|
178
|
+
console.error('Failed to attach updatePluginConfig wrapper', e)
|
|
179
|
+
}
|
|
125
180
|
showIntro = () => {
|
|
126
181
|
const introLink = document.getElementById('introLink');
|
|
127
182
|
introLink.addEventListener('click', () => {
|
|
@@ -144,13 +199,33 @@
|
|
|
144
199
|
document.getElementById('menuSettings').classList.add('btn-primary');
|
|
145
200
|
document.getElementById('pageSupport').style.display = 'none';
|
|
146
201
|
document.getElementById('pageDevices').style.display = 'block';
|
|
147
|
-
|
|
202
|
+
let cachedAccessories =
|
|
148
203
|
typeof homebridge.getCachedAccessories === 'function'
|
|
149
204
|
? await homebridge.getCachedAccessories()
|
|
150
205
|
: await homebridge.request('/getCachedAccessories');
|
|
206
|
+
|
|
207
|
+
// If no HAP cached accessories were returned, try the Matter cached list using the new native method
|
|
208
|
+
if ((!cachedAccessories || cachedAccessories.length === 0)) {
|
|
209
|
+
try {
|
|
210
|
+
// Use the new native getCachedMatterAccessories() method from @homebridge/plugin-ui-utils v2.1.1-beta.0+
|
|
211
|
+
const matter = typeof homebridge.getCachedMatterAccessories === 'function'
|
|
212
|
+
? await homebridge.getCachedMatterAccessories()
|
|
213
|
+
: await homebridge.request('/getCachedMatterAccessories'); // Fallback to custom handler for older UI versions
|
|
214
|
+
if (Array.isArray(matter) && matter.length > 0) {
|
|
215
|
+
cachedAccessories = matter
|
|
216
|
+
}
|
|
217
|
+
} catch (e) {
|
|
218
|
+
// ignore
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
console.log('Cached Accessories:', cachedAccessories); // Log cached accessories for debugging
|
|
151
222
|
if (cachedAccessories.length > 0) {
|
|
152
223
|
cachedAccessories.sort((a, b) => {
|
|
153
|
-
return a.displayName.toLowerCase() > b.displayName.toLowerCase()
|
|
224
|
+
return a.displayName.toLowerCase() > b.displayName.toLowerCase()
|
|
225
|
+
? 1
|
|
226
|
+
: b.displayName.toLowerCase() > a.displayName.toLowerCase()
|
|
227
|
+
? -1
|
|
228
|
+
: 0;
|
|
154
229
|
});
|
|
155
230
|
}
|
|
156
231
|
const deviceSelect = document.getElementById('deviceSelect');
|
|
@@ -158,24 +233,141 @@
|
|
|
158
233
|
cachedAccessories.forEach((a) => {
|
|
159
234
|
const option = document.createElement('option');
|
|
160
235
|
option.text = a.displayName;
|
|
161
|
-
option.value = a.UUID;
|
|
236
|
+
option.value = a.UUID || a.uuid; // Handle both HAP and Matter UUID formats
|
|
162
237
|
deviceSelect.add(option);
|
|
163
238
|
});
|
|
239
|
+
const cachedAccessoriesList = document.getElementById('cachedAccessoriesList');
|
|
240
|
+
cachedAccessoriesList.innerHTML = ''; // Clear previous entries
|
|
241
|
+
cachedAccessories.forEach((a) => {
|
|
242
|
+
const listItem = document.createElement('li');
|
|
243
|
+
listItem.textContent = `${a.displayName} (${a.UUID || a.uuid})`;
|
|
244
|
+
cachedAccessoriesList.appendChild(listItem);
|
|
245
|
+
});
|
|
246
|
+
const validateConfig = (config) => {
|
|
247
|
+
const deviceIds = new Set();
|
|
248
|
+
const isValid = config[0].options.devices.every((device) => {
|
|
249
|
+
if (!device.deviceId || typeof device.deviceId !== 'string') {
|
|
250
|
+
homebridge.toast.error(`Invalid device ID: ${device.deviceId}`, 'Error');
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
if (deviceIds.has(device.deviceId)) {
|
|
254
|
+
homebridge.toast.error(`Duplicate device ID found: ${device.deviceId}`, 'Error');
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
deviceIds.add(device.deviceId);
|
|
258
|
+
return true;
|
|
259
|
+
});
|
|
260
|
+
return isValid;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const addDeviceToConfig = async (deviceId) => {
|
|
264
|
+
try {
|
|
265
|
+
homebridge.showSpinner();
|
|
266
|
+
const currentConfig = await homebridge.getPluginConfig();
|
|
267
|
+
if (!currentConfig[0].options.devices) {
|
|
268
|
+
currentConfig[0].options.devices = [];
|
|
269
|
+
}
|
|
270
|
+
currentConfig[0].options.devices.push({
|
|
271
|
+
deviceId: deviceId.replace(/:/g, ''),
|
|
272
|
+
hide_device: false,
|
|
273
|
+
disablePlatformBLE: false,
|
|
274
|
+
allowPush: false,
|
|
275
|
+
disableCaching: false,
|
|
276
|
+
});
|
|
277
|
+
if (!validateConfig(currentConfig)) {
|
|
278
|
+
homebridge.hideSpinner();
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
await homebridge.updatePluginConfig(currentConfig);
|
|
282
|
+
await homebridge.savePluginConfig();
|
|
283
|
+
homebridge.toast.success('Device added to config successfully!', 'Success');
|
|
284
|
+
} catch (error) {
|
|
285
|
+
homebridge.toast.error('Failed to add device to config!', 'Error');
|
|
286
|
+
} finally {
|
|
287
|
+
homebridge.hideSpinner();
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const protocolInfo = document.createElement('p');
|
|
292
|
+
protocolInfo.id = 'protocolInfo';
|
|
293
|
+
protocolInfo.style.marginTop = '10px';
|
|
294
|
+
document.getElementById('deviceInfo').appendChild(protocolInfo);
|
|
295
|
+
|
|
296
|
+
const addDeviceButton = document.createElement('button');
|
|
297
|
+
addDeviceButton.textContent = 'Add Device to Config';
|
|
298
|
+
addDeviceButton.className = 'btn btn-success';
|
|
299
|
+
addDeviceButton.style.marginTop = '10px';
|
|
300
|
+
addDeviceButton.addEventListener('click', () => {
|
|
301
|
+
const deviceId = document.getElementById('deviceId').textContent;
|
|
302
|
+
if (deviceId) {
|
|
303
|
+
addDeviceToConfig(deviceId);
|
|
304
|
+
} else {
|
|
305
|
+
homebridge.toast.error('No device ID found!', 'Error');
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
document.getElementById('deviceInfo').appendChild(addDeviceButton);
|
|
309
|
+
|
|
310
|
+
const updateTableWithDetails = (deviceContext) => {
|
|
311
|
+
const tableBody = document.querySelector('#deviceTable tbody');
|
|
312
|
+
|
|
313
|
+
Object.entries(deviceContext).forEach(([key, value]) => {
|
|
314
|
+
if (/string|number|boolean/.test(typeof value) && (typeof value !== 'string' || value.trim())) {
|
|
315
|
+
let existingCell = document.getElementById(key);
|
|
316
|
+
if (existingCell) {
|
|
317
|
+
existingCell.textContent = value;
|
|
318
|
+
} else {
|
|
319
|
+
const row = document.createElement('tr');
|
|
320
|
+
const keyCell = document.createElement('th');
|
|
321
|
+
keyCell.scope = 'row';
|
|
322
|
+
keyCell.textContent = key;
|
|
323
|
+
const valueCell = document.createElement('td');
|
|
324
|
+
valueCell.textContent = value;
|
|
325
|
+
row.appendChild(keyCell);
|
|
326
|
+
row.appendChild(valueCell);
|
|
327
|
+
tableBody.appendChild(row);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// Ensure the element exists before attempting to set its innerHTML
|
|
334
|
+
const safeSetInnerHTML = (id, value) => {
|
|
335
|
+
const element = document.getElementById(id);
|
|
336
|
+
if (element) {
|
|
337
|
+
element.innerHTML = value;
|
|
338
|
+
} else {
|
|
339
|
+
console.warn(`Element with id '${id}' not found.`);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
164
343
|
showDeviceInfo = async (UUID) => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
344
|
+
try {
|
|
345
|
+
homebridge.showSpinner();
|
|
346
|
+
const thisAcc = cachedAccessories.find((x) => x.UUID === UUID);
|
|
347
|
+
if (!thisAcc) {
|
|
348
|
+
throw new Error('Device not found');
|
|
349
|
+
}
|
|
350
|
+
const context = thisAcc.context;
|
|
351
|
+
const protocol = thisAcc.isMatter ? 'Matter Protocol' : 'HAP Protocol';
|
|
352
|
+
safeSetInnerHTML('displayName', thisAcc.displayName);
|
|
353
|
+
safeSetInnerHTML('deviceId', context.deviceId);
|
|
354
|
+
safeSetInnerHTML('model', context.model);
|
|
355
|
+
safeSetInnerHTML('version', context.version);
|
|
356
|
+
safeSetInnerHTML('deviceType', context.deviceType);
|
|
357
|
+
safeSetInnerHTML('connectionType', context.connectionType);
|
|
358
|
+
safeSetInnerHTML('refreshRate', context.refreshRate);
|
|
359
|
+
safeSetInnerHTML('updateRate', context.updateRate);
|
|
360
|
+
safeSetInnerHTML('pushRate', context.pushRate);
|
|
361
|
+
safeSetInnerHTML('protocolInfo', protocol);
|
|
362
|
+
document.getElementById('deviceTable').style.display = 'inline-table';
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
updateTableWithDetails(context);
|
|
366
|
+
} catch (error) {
|
|
367
|
+
homebridge.toast.error(error.message, 'Error');
|
|
368
|
+
} finally {
|
|
369
|
+
homebridge.hideSpinner();
|
|
370
|
+
}
|
|
179
371
|
};
|
|
180
372
|
deviceSelect.addEventListener('change', (event) => showDeviceInfo(event.target.value));
|
|
181
373
|
if (cachedAccessories.length > 0) {
|
|
@@ -246,4 +438,12 @@
|
|
|
246
438
|
homebridge.hideSpinner();
|
|
247
439
|
}
|
|
248
440
|
})();
|
|
441
|
+
|
|
442
|
+
document.getElementById('dynamic-config-tab').addEventListener('click', function() {
|
|
443
|
+
// Hide other tabs
|
|
444
|
+
document.querySelectorAll('.tab-content').forEach(tab => tab.style.display = 'none');
|
|
445
|
+
|
|
446
|
+
// Show Dynamic Config tab
|
|
447
|
+
document.getElementById('dynamic-config-content').style.display = 'block';
|
|
448
|
+
});
|
|
249
449
|
</script>
|
|
@@ -1,42 +1,8 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
|
|
3
1
|
import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils'
|
|
4
2
|
|
|
5
3
|
class PluginUiServer extends HomebridgePluginUiServer {
|
|
6
4
|
constructor() {
|
|
7
5
|
super()
|
|
8
|
-
/*
|
|
9
|
-
A native method getCachedAccessories() was introduced in config-ui-x v4.37.0
|
|
10
|
-
The following is for users who have a lower version of config-ui-x
|
|
11
|
-
*/
|
|
12
|
-
this.onRequest('getCachedAccessories', () => {
|
|
13
|
-
try {
|
|
14
|
-
const plugin = 'homebridge-switchbot'
|
|
15
|
-
const devicesToReturn = []
|
|
16
|
-
|
|
17
|
-
// The path and file of the cached accessories
|
|
18
|
-
const accFile = `${this.homebridgeStoragePath}/accessories/cachedAccessories`
|
|
19
|
-
|
|
20
|
-
// Check the file exists
|
|
21
|
-
if (fs.existsSync(accFile)) {
|
|
22
|
-
// read the cached accessories file
|
|
23
|
-
const cachedAccessories: any[] = JSON.parse(fs.readFileSync(accFile, 'utf8'))
|
|
24
|
-
|
|
25
|
-
cachedAccessories.forEach((accessory: any) => {
|
|
26
|
-
// Check the accessory is from this plugin
|
|
27
|
-
if (accessory.plugin === plugin) {
|
|
28
|
-
// Add the cached accessory to the array
|
|
29
|
-
devicesToReturn.push(accessory.accessory as never)
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
// Return the array
|
|
34
|
-
return devicesToReturn
|
|
35
|
-
} catch {
|
|
36
|
-
// Just return an empty accessory list in case of any errors
|
|
37
|
-
return []
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
6
|
this.ready()
|
|
41
7
|
}
|
|
42
8
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,17 +7,11 @@ import type { API } from 'homebridge'
|
|
|
7
7
|
import { SwitchBotHAPPlatform } from './platform-hap.js'
|
|
8
8
|
import { SwitchBotMatterPlatform } from './platform-matter.js'
|
|
9
9
|
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'
|
|
10
|
+
import { createPlatformProxy } from './utils.js'
|
|
10
11
|
|
|
11
12
|
// Register our platform with homebridge.
|
|
12
13
|
export default (api: API): void => {
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
? Boolean(api.isMatterEnabled())
|
|
17
|
-
: Boolean((api as any).isMatterEnabled)
|
|
18
|
-
|
|
19
|
-
const log = (api as any).logger ?? (api as any).log ?? console
|
|
20
|
-
log.info?.(`Homebridge SwitchBot Plugin initializing in ${isMatter ? 'Matter' : 'HAP'} mode.`)
|
|
21
|
-
// If Matter is enabled register the Matter platform, otherwise use HAP platform.
|
|
22
|
-
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, isMatter ? SwitchBotMatterPlatform : SwitchBotHAPPlatform)
|
|
14
|
+
// Create and register a small proxy that selects the correct platform (HAP or Matter) at runtime.
|
|
15
|
+
const ProxyCtor = createPlatformProxy(SwitchBotHAPPlatform, SwitchBotMatterPlatform)
|
|
16
|
+
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, ProxyCtor as any)
|
|
23
17
|
}
|
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
|
}
|