@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.0

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.
Files changed (178) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/CHANGELOG.md +4 -1
  3. package/config.schema.json +166 -24
  4. package/dist/device/blindtilt.d.ts +21 -96
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +439 -817
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +27 -72
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +835 -865
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +15 -69
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +287 -653
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +15 -76
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +354 -732
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/contact.d.ts +14 -66
  21. package/dist/device/contact.d.ts.map +1 -1
  22. package/dist/device/contact.js +268 -576
  23. package/dist/device/contact.js.map +1 -1
  24. package/dist/device/curtain.d.ts +18 -89
  25. package/dist/device/curtain.d.ts.map +1 -1
  26. package/dist/device/curtain.js +431 -851
  27. package/dist/device/curtain.js.map +1 -1
  28. package/dist/device/device.d.ts +60 -0
  29. package/dist/device/device.d.ts.map +1 -0
  30. package/dist/device/device.js +739 -0
  31. package/dist/device/device.js.map +1 -0
  32. package/dist/device/fan.d.ts +63 -0
  33. package/dist/device/fan.d.ts.map +1 -0
  34. package/dist/device/fan.js +698 -0
  35. package/dist/device/fan.js.map +1 -0
  36. package/dist/device/hub.d.ts +15 -60
  37. package/dist/device/hub.d.ts.map +1 -1
  38. package/dist/device/hub.js +257 -631
  39. package/dist/device/hub.js.map +1 -1
  40. package/dist/device/humidifier.d.ts +11 -66
  41. package/dist/device/humidifier.d.ts.map +1 -1
  42. package/dist/device/humidifier.js +266 -629
  43. package/dist/device/humidifier.js.map +1 -1
  44. package/dist/device/iosensor.d.ts +12 -64
  45. package/dist/device/iosensor.d.ts.map +1 -1
  46. package/dist/device/iosensor.js +215 -615
  47. package/dist/device/iosensor.js.map +1 -1
  48. package/dist/device/lightstrip.d.ts +12 -70
  49. package/dist/device/lightstrip.d.ts.map +1 -1
  50. package/dist/device/lightstrip.js +336 -645
  51. package/dist/device/lightstrip.js.map +1 -1
  52. package/dist/device/lock.d.ts +17 -63
  53. package/dist/device/lock.d.ts.map +1 -1
  54. package/dist/device/lock.js +290 -595
  55. package/dist/device/lock.js.map +1 -1
  56. package/dist/device/meter.d.ts +15 -64
  57. package/dist/device/meter.d.ts.map +1 -1
  58. package/dist/device/meter.js +211 -608
  59. package/dist/device/meter.js.map +1 -1
  60. package/dist/device/meterplus.d.ts +15 -65
  61. package/dist/device/meterplus.d.ts.map +1 -1
  62. package/dist/device/meterplus.js +205 -615
  63. package/dist/device/meterplus.js.map +1 -1
  64. package/dist/device/motion.d.ts +12 -69
  65. package/dist/device/motion.d.ts.map +1 -1
  66. package/dist/device/motion.js +202 -563
  67. package/dist/device/motion.js.map +1 -1
  68. package/dist/device/plug.d.ts +10 -57
  69. package/dist/device/plug.d.ts.map +1 -1
  70. package/dist/device/plug.js +125 -484
  71. package/dist/device/plug.js.map +1 -1
  72. package/dist/device/robotvacuumcleaner.d.ts +13 -63
  73. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  74. package/dist/device/robotvacuumcleaner.js +233 -549
  75. package/dist/device/robotvacuumcleaner.js.map +1 -1
  76. package/dist/device/waterdetector.d.ts +11 -63
  77. package/dist/device/waterdetector.d.ts.map +1 -1
  78. package/dist/device/waterdetector.js +170 -493
  79. package/dist/device/waterdetector.js.map +1 -1
  80. package/dist/homebridge-ui/public/index.html +22 -16
  81. package/dist/homebridge-ui/server.js +1 -1
  82. package/dist/homebridge-ui/server.js.map +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +2 -2
  86. package/dist/index.js.map +1 -1
  87. package/dist/irdevice/airconditioner.d.ts +10 -50
  88. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  89. package/dist/irdevice/airconditioner.js +340 -468
  90. package/dist/irdevice/airconditioner.js.map +1 -1
  91. package/dist/irdevice/airpurifier.d.ts +8 -39
  92. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  93. package/dist/irdevice/airpurifier.js +105 -319
  94. package/dist/irdevice/airpurifier.js.map +1 -1
  95. package/dist/irdevice/camera.d.ts +7 -36
  96. package/dist/irdevice/camera.d.ts.map +1 -1
  97. package/dist/irdevice/camera.js +44 -285
  98. package/dist/irdevice/camera.js.map +1 -1
  99. package/dist/irdevice/fan.d.ts +7 -43
  100. package/dist/irdevice/fan.d.ts.map +1 -1
  101. package/dist/irdevice/fan.js +92 -350
  102. package/dist/irdevice/fan.js.map +1 -1
  103. package/dist/irdevice/irdevice.d.ts +40 -0
  104. package/dist/irdevice/irdevice.d.ts.map +1 -0
  105. package/dist/irdevice/irdevice.js +369 -0
  106. package/dist/irdevice/irdevice.js.map +1 -0
  107. package/dist/irdevice/light.d.ts +12 -45
  108. package/dist/irdevice/light.d.ts.map +1 -1
  109. package/dist/irdevice/light.js +118 -362
  110. package/dist/irdevice/light.js.map +1 -1
  111. package/dist/irdevice/other.d.ts +19 -48
  112. package/dist/irdevice/other.d.ts.map +1 -1
  113. package/dist/irdevice/other.js +438 -570
  114. package/dist/irdevice/other.js.map +1 -1
  115. package/dist/irdevice/tv.d.ts +8 -40
  116. package/dist/irdevice/tv.d.ts.map +1 -1
  117. package/dist/irdevice/tv.js +91 -339
  118. package/dist/irdevice/tv.js.map +1 -1
  119. package/dist/irdevice/vacuumcleaner.d.ts +7 -36
  120. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  121. package/dist/irdevice/vacuumcleaner.js +45 -285
  122. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  123. package/dist/irdevice/waterheater.d.ts +7 -36
  124. package/dist/irdevice/waterheater.d.ts.map +1 -1
  125. package/dist/irdevice/waterheater.js +47 -291
  126. package/dist/irdevice/waterheater.js.map +1 -1
  127. package/dist/platform.d.ts +22 -8
  128. package/dist/platform.d.ts.map +1 -1
  129. package/dist/platform.js +342 -191
  130. package/dist/platform.js.map +1 -1
  131. package/dist/settings.d.ts +64 -17
  132. package/dist/settings.d.ts.map +1 -1
  133. package/dist/settings.js +16 -552
  134. package/dist/settings.js.map +1 -1
  135. package/dist/utils.d.ts +77 -0
  136. package/dist/utils.d.ts.map +1 -1
  137. package/dist/utils.js +638 -1
  138. package/dist/utils.js.map +1 -1
  139. package/eslint.config.js +96 -0
  140. package/package.json +20 -16
  141. package/src/custom.d.ts +2 -1
  142. package/src/device/blindtilt.ts +472 -888
  143. package/src/device/bot.ts +893 -968
  144. package/src/device/ceilinglight.ts +304 -709
  145. package/src/device/colorbulb.ts +370 -803
  146. package/src/device/contact.ts +301 -611
  147. package/src/device/curtain.ts +460 -908
  148. package/src/device/device.ts +755 -0
  149. package/src/device/fan.ts +749 -0
  150. package/src/device/hub.ts +294 -664
  151. package/src/device/humidifier.ts +299 -696
  152. package/src/device/iosensor.ts +251 -644
  153. package/src/device/lightstrip.ts +362 -712
  154. package/src/device/lock.ts +328 -653
  155. package/src/device/meter.ts +247 -637
  156. package/src/device/meterplus.ts +240 -644
  157. package/src/device/motion.ts +230 -598
  158. package/src/device/plug.ts +139 -525
  159. package/src/device/robotvacuumcleaner.ts +258 -593
  160. package/src/device/waterdetector.ts +191 -522
  161. package/src/homebridge-ui/public/index.html +22 -16
  162. package/src/homebridge-ui/server.ts +1 -1
  163. package/src/index.ts +4 -3
  164. package/src/irdevice/airconditioner.ts +370 -527
  165. package/src/irdevice/airpurifier.ts +132 -356
  166. package/src/irdevice/camera.ts +58 -311
  167. package/src/irdevice/fan.ts +109 -379
  168. package/src/irdevice/irdevice.ts +382 -0
  169. package/src/irdevice/light.ts +157 -412
  170. package/src/irdevice/other.ts +507 -648
  171. package/src/irdevice/tv.ts +121 -375
  172. package/src/irdevice/vacuumcleaner.ts +59 -311
  173. package/src/irdevice/waterheater.ts +61 -320
  174. package/src/platform.ts +395 -259
  175. package/src/settings.ts +118 -609
  176. package/src/utils.ts +642 -1
  177. package/.github/npm-version-script.cjs +0 -81
  178. package/src/device/waterdetector.json +0 -11
@@ -0,0 +1,755 @@
1
+ /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * device.ts: @switchbot/homebridge-switchbot.
4
+ */
5
+
6
+ import { hostname } from 'os';
7
+ import asyncmqtt from 'async-mqtt';
8
+ import { BlindTiltMappingMode, SwitchBotModel, SwitchBotBLEModel, sleep } from '../utils.js';
9
+
10
+ import type { MqttClient } from 'mqtt';
11
+ import type { SwitchBotPlatform } from '../platform.js';
12
+ import type { API, HAP, Logging, PlatformAccessory } from 'homebridge';
13
+ import type { SwitchBotPlatformConfig, device, devicesConfig } from '../settings.js';
14
+
15
+ export abstract class deviceBase {
16
+ public readonly api: API;
17
+ public readonly log: Logging;
18
+ public readonly config!: SwitchBotPlatformConfig;
19
+ protected readonly hap: HAP;
20
+
21
+ // Config
22
+ protected deviceLogging!: string;
23
+ protected deviceRefreshRate!: number;
24
+ protected deviceUpdateRate!: number;
25
+ protected devicePushRate!: number;
26
+ protected deviceMaxRetries!: number;
27
+ protected deviceDelayBetweenRetries!: number;
28
+
29
+ // Connection
30
+ protected readonly BLE: boolean;
31
+ protected readonly OpenAPI: boolean;
32
+
33
+ // Accsrroy Information
34
+ protected deviceModel!: SwitchBotModel;
35
+ protected deviceBLEModel!: SwitchBotBLEModel;
36
+
37
+ // BLE
38
+ protected scanDuration!: number;
39
+
40
+ // EVE history service handler
41
+ protected historyService?: any = null;
42
+
43
+ //MQTT stuff
44
+ protected mqttClient: MqttClient | null = null;
45
+
46
+ constructor(
47
+ protected readonly platform: SwitchBotPlatform,
48
+ protected accessory: PlatformAccessory,
49
+ protected device: device & devicesConfig,
50
+ ) {
51
+ this.api = this.platform.api;
52
+ this.log = this.platform.log;
53
+ this.config = this.platform.config;
54
+ this.hap = this.api.hap;
55
+
56
+ // Connection
57
+ this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
58
+ this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
59
+
60
+ this.getDeviceLogSettings(accessory, device);
61
+ this.getDeviceRateSettings(accessory, device);
62
+ this.getDeviceRetry(accessory, device);
63
+ this.getDeviceConfigSettings(accessory, device);
64
+ this.getDeviceContext(accessory, device);
65
+ this.setupMqtt(accessory, device);
66
+ this.scan(accessory, device);
67
+
68
+ // Set accessory information
69
+ accessory
70
+ .getService(this.hap.Service.AccessoryInformation)!
71
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
72
+ .setCharacteristic(this.hap.Characteristic.AppMatchingIdentifier, 'id1087374760')
73
+ .setCharacteristic(this.hap.Characteristic.Name, device.deviceName ?? accessory.displayName)
74
+ .setCharacteristic(this.hap.Characteristic.ConfiguredName, device.deviceName ?? accessory.displayName)
75
+ .setCharacteristic(this.hap.Characteristic.Model, device.model ?? accessory.context.model)
76
+ .setCharacteristic(this.hap.Characteristic.ProductData, device.deviceId ?? accessory.context.deviceId)
77
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId);
78
+ }
79
+
80
+ async getDeviceLogSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
81
+ if (this.platform.debugMode) {
82
+ this.deviceLogging = accessory.context.logging = 'debugMode';
83
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
84
+ } else if (device.logging) {
85
+ this.deviceLogging = accessory.context.logging = device.logging;
86
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
87
+ } else if (this.config.logging) {
88
+ this.deviceLogging = accessory.context.logging = this.config.logging;
89
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
90
+ } else {
91
+ this.deviceLogging = accessory.context.logging = 'standard';
92
+ this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
93
+ }
94
+ }
95
+
96
+ async getDeviceRateSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
97
+ // refreshRate
98
+ if (device.refreshRate) {
99
+ this.deviceRefreshRate = device.refreshRate;
100
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
101
+ } else if (this.config.options?.refreshRate) {
102
+ this.deviceRefreshRate = this.config.options.refreshRate;
103
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
104
+ } else {
105
+ this.deviceRefreshRate = 5;
106
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Default refreshRate: ${this.deviceRefreshRate}`);
107
+ }
108
+ accessory.context.deviceRefreshRate = this.deviceRefreshRate;
109
+ // updateRate
110
+ if (device.updateRate) {
111
+ this.deviceUpdateRate = device.updateRate;
112
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Device Config updateRate: ${this.deviceUpdateRate}`);
113
+ } else if (this.config.options?.updateRate) {
114
+ this.deviceUpdateRate = this.config.options.updateRate;
115
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Platform Config updateRate: ${this.deviceUpdateRate}`);
116
+ } else {
117
+ this.deviceUpdateRate = 5;
118
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Default updateRate: ${this.deviceUpdateRate}`);
119
+ }
120
+ accessory.context.deviceUpdateRate = this.deviceUpdateRate;
121
+ // pushRate
122
+ if (device.pushRate) {
123
+ this.devicePushRate = device.pushRate;
124
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Device Config pushRate: ${this.deviceUpdateRate}`);
125
+ } else if (this.config.options?.pushRate) {
126
+ this.devicePushRate = this.config.options.pushRate;
127
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Platform Config pushRate: ${this.deviceUpdateRate}`);
128
+ } else {
129
+ this.devicePushRate = 1;
130
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Default pushRate: ${this.deviceUpdateRate}`);
131
+ }
132
+ accessory.context.devicePushRate = this.devicePushRate;
133
+ }
134
+
135
+ async getDeviceRetry(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
136
+ if (device.maxRetries) {
137
+ this.deviceMaxRetries = device.maxRetries;
138
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Device Max Retries: ${this.deviceMaxRetries}`);
139
+ } else {
140
+ this.deviceMaxRetries = 5; // Maximum number of retries
141
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Max Retries Not Set, Using: ${this.deviceMaxRetries}`);
142
+ }
143
+ if (device.delayBetweenRetries) {
144
+ this.deviceDelayBetweenRetries = device.delayBetweenRetries * 1000;
145
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Device Delay Between Retries: ${this.deviceDelayBetweenRetries}`);
146
+ } else {
147
+ this.deviceDelayBetweenRetries = 3000; // Delay between retries in milliseconds
148
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Delay Between Retries Not Set,`
149
+ + ` Using: ${this.deviceDelayBetweenRetries}`);
150
+ }
151
+ }
152
+
153
+ async retryBLE({ max, fn }: { max: number; fn: { (): any; (): Promise<any> } }): Promise<null> {
154
+ return fn().catch(async (e: any) => {
155
+ if (max === 0) {
156
+ throw e;
157
+ }
158
+ this.infoLog(e);
159
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
160
+ await sleep(1000);
161
+ return this.retryBLE({ max: max - 1, fn });
162
+ });
163
+ }
164
+
165
+ async maxRetryBLE(): Promise<number> {
166
+ if (this.device.maxRetry) {
167
+ return this.device.maxRetry;
168
+ } else {
169
+ return 5;
170
+ }
171
+ }
172
+
173
+ async scan(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
174
+ if (device.scanDuration) {
175
+ if (this.deviceUpdateRate > device.scanDuration) {
176
+ this.scanDuration = this.deviceUpdateRate;
177
+ if (this.BLE) {
178
+ this.warnLog(
179
+ `${this.device.deviceType}: `
180
+ + `${accessory.displayName} scanDuration is less than updateRate, overriding scanDuration with updateRate`);
181
+ }
182
+ } else {
183
+ this.scanDuration = accessory.context.scanDuration = device.scanDuration;
184
+ }
185
+ if (this.BLE) {
186
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
187
+ }
188
+ } else {
189
+ if (this.deviceUpdateRate > 1) {
190
+ this.scanDuration = this.deviceUpdateRate;
191
+ } else {
192
+ this.scanDuration = accessory.context.scanDuration = 1;
193
+ }
194
+ if (this.BLE) {
195
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
196
+ }
197
+ }
198
+ }
199
+
200
+ async getDeviceConfigSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
201
+ const deviceConfig = {};
202
+ if (device.logging !== 'standard') {
203
+ deviceConfig['logging'] = device.logging;
204
+ }
205
+ if (device.refreshRate !== 0) {
206
+ deviceConfig['refreshRate'] = device.refreshRate;
207
+ }
208
+ if (device.updateRate !== 0) {
209
+ deviceConfig['updateRate'] = device.updateRate;
210
+ }
211
+ if (device.scanDuration !== 0) {
212
+ deviceConfig['scanDuration'] = device.scanDuration;
213
+ }
214
+ if (device.offline === true) {
215
+ deviceConfig['offline'] = device.offline;
216
+ }
217
+ if (device.maxRetry !== 0) {
218
+ deviceConfig['maxRetry'] = device.maxRetry;
219
+ }
220
+ if (device.webhook === true) {
221
+ deviceConfig['webhook'] = device.webhook;
222
+ }
223
+ if (device.connectionType !== '') {
224
+ deviceConfig['connectionType'] = device.connectionType;
225
+ }
226
+ if (device.external === true) {
227
+ deviceConfig['external'] = device.external;
228
+ }
229
+ if (device.mqttURL !== '') {
230
+ deviceConfig['mqttURL'] = device.mqttURL;
231
+ }
232
+ if (device.maxRetries !== 0) {
233
+ deviceConfig['maxRetries'] = device.maxRetries;
234
+ }
235
+ if (device.delayBetweenRetries !== 0) {
236
+ deviceConfig['delayBetweenRetries'] = device.delayBetweenRetries;
237
+ }
238
+ let botConfig = {};
239
+ if (device.bot) {
240
+ botConfig = device.bot;
241
+ }
242
+ let lockConfig = {};
243
+ if (device.lock) {
244
+ lockConfig = device.lock;
245
+ }
246
+ let ceilinglightConfig = {};
247
+ if (device.ceilinglight) {
248
+ ceilinglightConfig = device.ceilinglight;
249
+ }
250
+ let colorbulbConfig = {};
251
+ if (device.colorbulb) {
252
+ colorbulbConfig = device.colorbulb;
253
+ }
254
+ let contactConfig = {};
255
+ if (device.contact) {
256
+ contactConfig = device.contact;
257
+ }
258
+ let motionConfig = {};
259
+ if (device.motion) {
260
+ motionConfig = device.motion;
261
+ }
262
+ let curtainConfig = {};
263
+ if (device.curtain) {
264
+ curtainConfig = device.curtain;
265
+ }
266
+ let hubConfig = {};
267
+ if (device.hub) {
268
+ hubConfig = device.hub;
269
+ }
270
+ let waterdetectorConfig = {};
271
+ if (device.waterdetector) {
272
+ waterdetectorConfig = device.waterdetector;
273
+ }
274
+ let humidifierConfig = {};
275
+ if (device.humidifier) {
276
+ humidifierConfig = device.humidifier;
277
+ }
278
+ let meterConfig = {};
279
+ if (device.meter) {
280
+ meterConfig = device.meter;
281
+ }
282
+ let iosensorConfig = {};
283
+ if (device.iosensor) {
284
+ iosensorConfig = device.iosensor;
285
+ }
286
+ let striplightConfig = {};
287
+ if (device.striplight) {
288
+ striplightConfig = device.striplight;
289
+ }
290
+ let plugConfig = {};
291
+ if (device.plug) {
292
+ plugConfig = device.plug;
293
+ }
294
+ let blindTiltConfig = {};
295
+ if (device.blindTilt) {
296
+ if (device.blindTilt?.mode === undefined) {
297
+ blindTiltConfig['mode'] = BlindTiltMappingMode.OnlyUp;
298
+ }
299
+ blindTiltConfig = device.blindTilt;
300
+ }
301
+ const config = Object.assign({}, deviceConfig, botConfig, curtainConfig, waterdetectorConfig, striplightConfig, plugConfig, iosensorConfig,
302
+ meterConfig, humidifierConfig, hubConfig, lockConfig, ceilinglightConfig, colorbulbConfig, contactConfig, motionConfig, blindTiltConfig);
303
+ if (Object.entries(config).length !== 0) {
304
+ this.debugSuccessLog(`${this.device.deviceType}: ${accessory.displayName} Config: ${JSON.stringify(config)}`);
305
+ }
306
+ }
307
+
308
+ /*
309
+ * Publish MQTT message for topics of
310
+ * 'homebridge-switchbot/${this.device.deviceType}/xx:xx:xx:xx:xx:xx'
311
+ */
312
+ mqttPublish(message: string, topic?: string) {
313
+ const mac = this.device.deviceId
314
+ ?.toLowerCase()
315
+ .match(/[\s\S]{1,2}/g)
316
+ ?.join(':');
317
+ const options = this.device.mqttPubOptions || {};
318
+ let mqttTopic: string;
319
+ let mqttMessageTopic: string;
320
+ if (topic) {
321
+ mqttTopic = `/${topic}`;
322
+ mqttMessageTopic = `${topic}/`;
323
+ } else {
324
+ mqttTopic = '';
325
+ mqttMessageTopic = '';
326
+ }
327
+ this.mqttClient?.publish(`homebridge-switchbot/${this.device.deviceType}/${mac}${mqttTopic}`, `${message}`, options);
328
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
329
+ + ` MQTT message: ${mqttMessageTopic}${message} options:${JSON.stringify(options)}`);
330
+ }
331
+
332
+ /*
333
+ * Setup MQTT hadler if URL is specified.
334
+ */
335
+ async setupMqtt(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
336
+ if (device.mqttURL) {
337
+ try {
338
+ const { connectAsync } = asyncmqtt;
339
+ this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
340
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
341
+ this.mqttClient.on('error', (e: Error) => {
342
+ this.errorLog(`${this.device.deviceType}: ${accessory.displayName} Failed to publish MQTT messages. ${e}`);
343
+ });
344
+ } catch (e) {
345
+ this.mqttClient = null;
346
+ this.errorLog(`${this.device.deviceType}: ${accessory.displayName} Failed to establish MQTT connection. ${e}`);
347
+ }
348
+ }
349
+ }
350
+
351
+ /*
352
+ * Setup EVE history graph feature if enabled.
353
+ */
354
+ async setupHistoryService(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
355
+ const mac = this.device
356
+ .deviceId!.match(/.{1,2}/g)!
357
+ .join(':')
358
+ .toLowerCase();
359
+ this.historyService = device.history
360
+ ? new this.platform.fakegatoAPI('room', accessory, {
361
+ log: this.platform.log,
362
+ storage: 'fs',
363
+ filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
364
+ })
365
+ : null;
366
+ }
367
+
368
+ async getCustomBLEAddress(switchbot: any) {
369
+ if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
370
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
371
+ (async () => {
372
+ // Start to monitor advertisement packets
373
+ await switchbot.startScan({ model: this.device.bleModel });
374
+ // Set an event handler
375
+ switchbot.onadvertisement = (ad: any) => {
376
+ this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
377
+ };
378
+ await sleep(10000);
379
+ // Stop to monitor
380
+ switchbot.stopScan();
381
+ })();
382
+ }
383
+ }
384
+
385
+ async getDeviceContext(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
386
+ // Set the accessory context
387
+ switch (device.deviceType) {
388
+ case 'Humidifier':
389
+ device.model = SwitchBotModel.Humidifier;
390
+ device.bleModel = SwitchBotBLEModel.Humidifier;
391
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
392
+ break;
393
+ case 'Hub Mini':
394
+ device.model = SwitchBotModel.HubMini;
395
+ device.bleModel = SwitchBotBLEModel.Unknown;
396
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
397
+ break;
398
+ case 'Hub Plus':
399
+ device.model = SwitchBotModel.HubPlus;
400
+ device.bleModel = SwitchBotBLEModel.Unknown;
401
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
402
+ break;
403
+ case 'Hub 2':
404
+ device.model = SwitchBotModel.Hub2;
405
+ device.bleModel = SwitchBotBLEModel.Unknown;
406
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
407
+ break;
408
+ case 'Bot':
409
+ device.model = SwitchBotModel.Bot;
410
+ device.bleModel = SwitchBotBLEModel.Bot;
411
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
412
+ break;
413
+ case 'Meter':
414
+ device.model = SwitchBotModel.Meter;
415
+ device.bleModel = SwitchBotBLEModel.Meter;
416
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
417
+ break;
418
+ case 'MeterPlus':
419
+ device.model = SwitchBotModel.MeterPlusUS;
420
+ device.bleModel = SwitchBotBLEModel.MeterPlus;
421
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
422
+ break;
423
+ case 'Meter Plus (JP)':
424
+ device.model = SwitchBotModel.MeterPlusJP;
425
+ device.bleModel = SwitchBotBLEModel.MeterPlus;
426
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
427
+ break;
428
+ case 'WoIOSensor':
429
+ device.model = SwitchBotModel.OutdoorMeter;
430
+ device.bleModel = SwitchBotBLEModel.OutdoorMeter;
431
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
432
+ break;
433
+ case 'Water Detector':
434
+ device.model = SwitchBotModel.WaterDetector;
435
+ device.bleModel = SwitchBotBLEModel.Unknown;
436
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
437
+ break;
438
+ case 'Motion Sensor':
439
+ device.model = SwitchBotModel.MotionSensor;
440
+ device.bleModel = SwitchBotBLEModel.MotionSensor;
441
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
442
+ break;
443
+ case 'Contact Sensor':
444
+ device.model = SwitchBotModel.ContactSensor;
445
+ device.bleModel = SwitchBotBLEModel.ContactSensor;
446
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
447
+ break;
448
+ case 'Curtain':
449
+ device.model = SwitchBotModel.Curtain;
450
+ device.bleModel = SwitchBotBLEModel.Curtain;
451
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
452
+ break;
453
+ case 'Curtain3':
454
+ device.model = SwitchBotModel.Curtain3;
455
+ device.bleModel = SwitchBotBLEModel.Curtain3;
456
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
457
+ break;
458
+ case 'Blind Tilt':
459
+ device.model = SwitchBotModel.BlindTilt;
460
+ device.bleModel = SwitchBotBLEModel.BlindTilt;
461
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
462
+ break;
463
+ case 'Plug':
464
+ device.model = SwitchBotModel.Plug;
465
+ device.bleModel = SwitchBotBLEModel.PlugMiniUS;
466
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
467
+ break;
468
+ case 'Plug Mini (US)':
469
+ device.model = SwitchBotModel.PlugMiniUS;
470
+ device.bleModel = SwitchBotBLEModel.PlugMiniUS;
471
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
472
+ break;
473
+ case 'Plug Mini (JP)':
474
+ device.model = SwitchBotModel.PlugMiniJP;
475
+ device.bleModel = SwitchBotBLEModel.PlugMiniJP;
476
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
477
+ break;
478
+ case 'Smart Lock':
479
+ device.model = SwitchBotModel.Lock;
480
+ device.bleModel = SwitchBotBLEModel.Lock;
481
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
482
+ break;
483
+ case 'Smart Lock Pro':
484
+ device.model = SwitchBotModel.LockPro;
485
+ device.bleModel = SwitchBotBLEModel.Unknown;
486
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
487
+ break;
488
+ case 'Color Bulb':
489
+ device.model = SwitchBotModel.ColorBulb;
490
+ device.bleModel = SwitchBotBLEModel.ColorBulb;
491
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
492
+ break;
493
+ case 'K10+':
494
+ device.model = SwitchBotModel.K10;
495
+ device.bleModel = SwitchBotBLEModel.Unknown;
496
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
497
+ break;
498
+ case 'WoSweeper':
499
+ device.model = SwitchBotModel.WoSweeper;
500
+ device.bleModel = SwitchBotBLEModel.Unknown;
501
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
502
+ break;
503
+ case 'WoSweeperMini':
504
+ device.model = SwitchBotModel.WoSweeperMini;
505
+ device.bleModel = SwitchBotBLEModel.Unknown;
506
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
507
+ break;
508
+ case 'Robot Vacuum Cleaner S1':
509
+ device.model = SwitchBotModel.RobotVacuumCleanerS1;
510
+ device.bleModel = SwitchBotBLEModel.Unknown;
511
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
512
+ break;
513
+ case 'Robot Vacuum Cleaner S1 Plus':
514
+ device.model = SwitchBotModel.RobotVacuumCleanerS1Plus;
515
+ device.bleModel = SwitchBotBLEModel.Unknown;
516
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
517
+ break;
518
+ case 'Robot Vacuum Cleaner S10':
519
+ device.model = SwitchBotModel.RobotVacuumCleanerS10;
520
+ device.bleModel = SwitchBotBLEModel.Unknown;
521
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
522
+ break;
523
+ case 'Ceiling Light':
524
+ device.model = SwitchBotModel.CeilingLight;
525
+ device.bleModel = SwitchBotBLEModel.CeilingLight;
526
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
527
+ break;
528
+ case 'Ceiling Light Pro':
529
+ device.model = SwitchBotModel.CeilingLightPro;
530
+ device.bleModel = SwitchBotBLEModel.CeilingLightPro;
531
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
532
+ break;
533
+ case 'Strip Light':
534
+ device.model = SwitchBotModel.StripLight;
535
+ device.bleModel = SwitchBotBLEModel.StripLight;
536
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
537
+ break;
538
+ case 'Indoor Cam':
539
+ device.model = SwitchBotModel.IndoorCam;
540
+ device.bleModel = SwitchBotBLEModel.Unknown;
541
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
542
+ break;
543
+ case 'Remote':
544
+ device.model = SwitchBotModel.Remote;
545
+ device.bleModel = SwitchBotBLEModel.Remote;
546
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
547
+ break;
548
+ case 'remote with screen+':
549
+ device.model = SwitchBotModel.UniversalRemote;
550
+ device.bleModel = SwitchBotBLEModel.Unknown;
551
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
552
+ break;
553
+ case 'Battery Circulator Fan':
554
+ device.model = SwitchBotModel.BatteryCirculatorFan;
555
+ device.bleModel = SwitchBotBLEModel.Unknown;
556
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
557
+ break;
558
+ default:
559
+ device.model = SwitchBotModel.Unknown;
560
+ device.bleModel = SwitchBotBLEModel.Unknown;
561
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Model: ${device.model}, BLE Model: ${device.bleModel}`);
562
+ }
563
+ accessory.context.model = device.model;
564
+
565
+ // Firmware Version
566
+ let deviceFirmwareVersion: string;
567
+ if (device.firmware) {
568
+ deviceFirmwareVersion = device.firmware;
569
+ this.debugSuccessLog(`${device.deviceType}: ${accessory.displayName} 1 FirmwareRevision: ${device.firmware}`);
570
+ } else if (device.version) {
571
+ deviceFirmwareVersion = device.version;
572
+ this.debugSuccessLog(`${device.deviceType}: ${accessory.displayName} 2 FirmwareRevision: ${device.version}`);
573
+ } else if (accessory.context.deviceVersion) {
574
+ deviceFirmwareVersion = accessory.context.deviceVersion;
575
+ this.debugSuccessLog(`${device.deviceType}: ${accessory.displayName} 3 FirmwareRevision: ${accessory.context.deviceVersion}`);
576
+ } else {
577
+ deviceFirmwareVersion = this.platform.version ?? '0.0.0';
578
+ if (this.platform.version) {
579
+ this.debugSuccessLog(`${device.deviceType}: ${accessory.displayName} 4 FirmwareRevision: ${this.platform.version}`);
580
+ } else {
581
+ this.debugSuccessLog(`${device.deviceType}: ${accessory.displayName} 5 FirmwareRevision: ${deviceFirmwareVersion}`);
582
+ }
583
+ }
584
+ const version = deviceFirmwareVersion.toString();
585
+ this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
586
+ let deviceVersion: string;
587
+ if (version?.includes('.') === false) {
588
+ const replace = version?.replace(/^V|-.*$/g, '');
589
+ const match = replace?.match(/.{1,1}/g);
590
+ const validVersion = match?.join('.');
591
+ deviceVersion = validVersion ?? '0.0.0';
592
+ } else {
593
+ deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
594
+ }
595
+ accessory
596
+ .getService(this.hap.Service.AccessoryInformation)!
597
+ .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
598
+ .setCharacteristic(this.hap.Characteristic.SoftwareRevision, deviceVersion)
599
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
600
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
601
+ .updateValue(deviceVersion);
602
+ accessory.context.deviceVersion = deviceVersion;
603
+ this.debugSuccessLog(`${device.deviceType}: ${accessory.displayName} deviceVersion: ${accessory.context.deviceVersion}`);
604
+ }
605
+
606
+ async statusCode(statusCode: number): Promise<void> {
607
+ if (statusCode === 171) {
608
+ const previousStatusCode = statusCode;
609
+ if (this.device.hubDeviceId === this.device.deviceId) {
610
+ statusCode = 161;
611
+ this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${previousStatusCode} is now statusCode: `
612
+ + `${statusCode}, because the hubDeviceId: ${this.device.hubDeviceId} is set to the same as the deviceId: `
613
+ + `${this.device.deviceId}, meaning the device is it's own hub.`);
614
+ }
615
+ if (this.device.hubDeviceId === '000000000000') {
616
+ statusCode = 161;
617
+ this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${previousStatusCode} is now statusCode: `
618
+ + `${statusCode}, because the hubDeviceId: ${this.device.hubDeviceId} is set to the same as the deviceId: `
619
+ + `${this.device.deviceId}, meaning the device is it's own hub.`);
620
+ }
621
+ }
622
+ switch (statusCode) {
623
+ case 151:
624
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
625
+ break;
626
+ case 152:
627
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
628
+ break;
629
+ case 160:
630
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
631
+ break;
632
+ case 161:
633
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
634
+ break;
635
+ case 171:
636
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
637
+ + `Hub: ${this.device.hubDeviceId}`);
638
+ break;
639
+ case 190:
640
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with`
641
+ + ` server, Or command format is invalid, statusCode: ${statusCode}`);
642
+ break;
643
+ case 100:
644
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
645
+ break;
646
+ case 200:
647
+ this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
648
+ break;
649
+ case 400:
650
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
651
+ + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
652
+ break;
653
+ case 401:
654
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
655
+ + `but the request has not been authenticated, statusCode: ${statusCode}`);
656
+ break;
657
+ case 403:
658
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
659
+ + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
660
+ break;
661
+ case 404:
662
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
663
+ + `statusCode: ${statusCode}`);
664
+ break;
665
+ case 406:
666
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
667
+ + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
668
+ break;
669
+ case 415:
670
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
671
+ + `header that is not supported by the server, statusCode: ${statusCode}`);
672
+ break;
673
+ case 422:
674
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
675
+ + `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
676
+ break;
677
+ case 429:
678
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
679
+ + `requests allowed for a given time window, statusCode: ${statusCode}`);
680
+ break;
681
+ case 500:
682
+ this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
683
+ + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
684
+ break;
685
+ default:
686
+ this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
687
+ + `${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
688
+ }
689
+ }
690
+
691
+ /**
692
+ * Logging for Device
693
+ */
694
+ infoLog(...log: any[]): void {
695
+ if (this.enablingDeviceLogging()) {
696
+ this.log.info(String(...log));
697
+ }
698
+ }
699
+
700
+ successLog(...log: any[]): void {
701
+ if (this.enablingDeviceLogging()) {
702
+ this.log.success(String(...log));
703
+ }
704
+ }
705
+
706
+ debugSuccessLog(...log: any[]): void {
707
+ if (this.enablingDeviceLogging()) {
708
+ if (this.deviceLogging?.includes('debug')) {
709
+ this.log.success('[DEBUG]', String(...log));
710
+ }
711
+ }
712
+ }
713
+
714
+ warnLog(...log: any[]): void {
715
+ if (this.enablingDeviceLogging()) {
716
+ this.log.warn(String(...log));
717
+ }
718
+ }
719
+
720
+ debugWarnLog(...log: any[]): void {
721
+ if (this.enablingDeviceLogging()) {
722
+ if (this.deviceLogging?.includes('debug')) {
723
+ this.log.warn('[DEBUG]', String(...log));
724
+ }
725
+ }
726
+ }
727
+
728
+ errorLog(...log: any[]): void {
729
+ if (this.enablingDeviceLogging()) {
730
+ this.log.error(String(...log));
731
+ }
732
+ }
733
+
734
+ debugErrorLog(...log: any[]): void {
735
+ if (this.enablingDeviceLogging()) {
736
+ if (this.deviceLogging?.includes('debug')) {
737
+ this.log.error('[DEBUG]', String(...log));
738
+ }
739
+ }
740
+ }
741
+
742
+ debugLog(...log: any[]): void {
743
+ if (this.enablingDeviceLogging()) {
744
+ if (this.deviceLogging === 'debug') {
745
+ this.log.info('[DEBUG]', String(...log));
746
+ } else {
747
+ this.log.debug(String(...log));
748
+ }
749
+ }
750
+ }
751
+
752
+ enablingDeviceLogging(): boolean {
753
+ return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
754
+ }
755
+ }