@switchbot/homebridge-switchbot 3.5.1-beta.12 → 3.5.1-beta.13

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 (150) hide show
  1. package/config.schema.json +19 -3
  2. package/dist/device/blindtilt.d.ts +6 -4
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +57 -45
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +6 -3
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +38 -24
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +6 -3
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +40 -21
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +6 -3
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +42 -31
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +6 -3
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +40 -28
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +6 -4
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +35 -22
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +13 -2
  27. package/dist/device/device.d.ts.map +1 -1
  28. package/dist/device/device.js +223 -108
  29. package/dist/device/device.js.map +1 -1
  30. package/dist/device/fan.d.ts +6 -3
  31. package/dist/device/fan.d.ts.map +1 -1
  32. package/dist/device/fan.js +48 -29
  33. package/dist/device/fan.js.map +1 -1
  34. package/dist/device/hub.d.ts +6 -3
  35. package/dist/device/hub.d.ts.map +1 -1
  36. package/dist/device/hub.js +43 -26
  37. package/dist/device/hub.js.map +1 -1
  38. package/dist/device/humidifier.d.ts +6 -3
  39. package/dist/device/humidifier.d.ts.map +1 -1
  40. package/dist/device/humidifier.js +43 -26
  41. package/dist/device/humidifier.js.map +1 -1
  42. package/dist/device/iosensor.d.ts +6 -3
  43. package/dist/device/iosensor.d.ts.map +1 -1
  44. package/dist/device/iosensor.js +39 -24
  45. package/dist/device/iosensor.js.map +1 -1
  46. package/dist/device/lightstrip.d.ts +6 -3
  47. package/dist/device/lightstrip.d.ts.map +1 -1
  48. package/dist/device/lightstrip.js +43 -27
  49. package/dist/device/lightstrip.js.map +1 -1
  50. package/dist/device/lock.d.ts +6 -3
  51. package/dist/device/lock.d.ts.map +1 -1
  52. package/dist/device/lock.js +33 -22
  53. package/dist/device/lock.js.map +1 -1
  54. package/dist/device/meter.d.ts +6 -3
  55. package/dist/device/meter.d.ts.map +1 -1
  56. package/dist/device/meter.js +38 -24
  57. package/dist/device/meter.js.map +1 -1
  58. package/dist/device/meterplus.d.ts +6 -3
  59. package/dist/device/meterplus.d.ts.map +1 -1
  60. package/dist/device/meterplus.js +37 -24
  61. package/dist/device/meterplus.js.map +1 -1
  62. package/dist/device/motion.d.ts +6 -3
  63. package/dist/device/motion.d.ts.map +1 -1
  64. package/dist/device/motion.js +33 -22
  65. package/dist/device/motion.js.map +1 -1
  66. package/dist/device/plug.d.ts +6 -3
  67. package/dist/device/plug.d.ts.map +1 -1
  68. package/dist/device/plug.js +27 -16
  69. package/dist/device/plug.js.map +1 -1
  70. package/dist/device/robotvacuumcleaner.d.ts +6 -3
  71. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  72. package/dist/device/robotvacuumcleaner.js +34 -21
  73. package/dist/device/robotvacuumcleaner.js.map +1 -1
  74. package/dist/device/waterdetector.d.ts +6 -3
  75. package/dist/device/waterdetector.d.ts.map +1 -1
  76. package/dist/device/waterdetector.js +38 -23
  77. package/dist/device/waterdetector.js.map +1 -1
  78. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  79. package/dist/irdevice/airconditioner.js +19 -72
  80. package/dist/irdevice/airconditioner.js.map +1 -1
  81. package/dist/irdevice/airpurifier.js +4 -4
  82. package/dist/irdevice/airpurifier.js.map +1 -1
  83. package/dist/irdevice/camera.d.ts.map +1 -1
  84. package/dist/irdevice/camera.js +3 -10
  85. package/dist/irdevice/camera.js.map +1 -1
  86. package/dist/irdevice/fan.d.ts.map +1 -1
  87. package/dist/irdevice/fan.js +7 -25
  88. package/dist/irdevice/fan.js.map +1 -1
  89. package/dist/irdevice/irdevice.d.ts +1 -1
  90. package/dist/irdevice/irdevice.js +1 -1
  91. package/dist/irdevice/irdevice.js.map +1 -1
  92. package/dist/irdevice/light.d.ts.map +1 -1
  93. package/dist/irdevice/light.js +9 -27
  94. package/dist/irdevice/light.js.map +1 -1
  95. package/dist/irdevice/other.js +1 -1
  96. package/dist/irdevice/other.js.map +1 -1
  97. package/dist/irdevice/tv.d.ts.map +1 -1
  98. package/dist/irdevice/tv.js +3 -18
  99. package/dist/irdevice/tv.js.map +1 -1
  100. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  101. package/dist/irdevice/vacuumcleaner.js +2 -9
  102. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  103. package/dist/irdevice/waterheater.d.ts.map +1 -1
  104. package/dist/irdevice/waterheater.js +2 -9
  105. package/dist/irdevice/waterheater.js.map +1 -1
  106. package/dist/platform.d.ts +0 -11
  107. package/dist/platform.d.ts.map +1 -1
  108. package/dist/platform.js +11 -184
  109. package/dist/platform.js.map +1 -1
  110. package/dist/settings.d.ts +9 -8
  111. package/dist/settings.d.ts.map +1 -1
  112. package/dist/settings.js.map +1 -1
  113. package/dist/types/bledevicestatus.d.ts +2 -1
  114. package/dist/types/bledevicestatus.d.ts.map +1 -1
  115. package/dist/types/devicestatus.d.ts +1 -1
  116. package/dist/types/devicestatus.d.ts.map +1 -1
  117. package/package.json +9 -9
  118. package/src/device/blindtilt.ts +60 -47
  119. package/src/device/bot.ts +47 -25
  120. package/src/device/ceilinglight.ts +52 -21
  121. package/src/device/colorbulb.ts +45 -31
  122. package/src/device/contact.ts +43 -28
  123. package/src/device/curtain.ts +45 -23
  124. package/src/device/device.ts +226 -96
  125. package/src/device/fan.ts +61 -30
  126. package/src/device/hub.ts +55 -29
  127. package/src/device/humidifier.ts +55 -31
  128. package/src/device/iosensor.ts +45 -27
  129. package/src/device/lightstrip.ts +48 -28
  130. package/src/device/lock.ts +49 -23
  131. package/src/device/meter.ts +54 -26
  132. package/src/device/meterplus.ts +50 -26
  133. package/src/device/motion.ts +45 -24
  134. package/src/device/plug.ts +34 -17
  135. package/src/device/robotvacuumcleaner.ts +49 -23
  136. package/src/device/waterdetector.ts +56 -25
  137. package/src/irdevice/airconditioner.ts +19 -65
  138. package/src/irdevice/airpurifier.ts +4 -4
  139. package/src/irdevice/camera.ts +4 -9
  140. package/src/irdevice/fan.ts +10 -22
  141. package/src/irdevice/irdevice.ts +1 -1
  142. package/src/irdevice/light.ts +10 -24
  143. package/src/irdevice/other.ts +1 -1
  144. package/src/irdevice/tv.ts +5 -16
  145. package/src/irdevice/vacuumcleaner.ts +3 -8
  146. package/src/irdevice/waterheater.ts +3 -8
  147. package/src/platform.ts +11 -184
  148. package/src/settings.ts +10 -8
  149. package/src/types/bledevicestatus.ts +4 -2
  150. package/src/types/devicestatus.ts +1 -1
@@ -369,7 +369,7 @@ export class TV extends irdeviceBase {
369
369
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
370
370
  const deviceStatus: any = await body.json();
371
371
  await this.pushStatusCodes(statusCode, deviceStatus);
372
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
372
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
373
373
  await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
374
374
  await this.updateHomeKitCharacteristics();
375
375
  } else {
@@ -388,22 +388,11 @@ export class TV extends irdeviceBase {
388
388
  async updateHomeKitCharacteristics(): Promise<void> {
389
389
  await this.debugLog('updateHomeKitCharacteristics');
390
390
  // Active
391
- if (this.Television.Active === undefined) {
392
- await this.debugLog(`Active: ${this.Television.Active}`);
393
- } else {
394
- this.accessory.context.Active = this.Television.Active;
395
- this.Television.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Television.Active);
396
- await this.debugLog(`updateCharacteristic Active: ${this.Television.Active}`);
397
- }
391
+ await this.updateCharacteristic(this.Television.Service, this.hap.Characteristic.Active,
392
+ this.Television.Active, 'Active');
398
393
  // ActiveIdentifier
399
- if (this.Television.ActiveIdentifier === undefined) {
400
- await this.debugLog(`ActiveIdentifier: ${this.Television.ActiveIdentifier}`);
401
- } else {
402
- this.accessory.context.ActiveIdentifier = this.Television.ActiveIdentifier;
403
- this.Television.Service.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, this.Television.ActiveIdentifier);
404
- await this.debugLog('updateCharacteristic'
405
- + ` ActiveIdentifier: ${this.Television.ActiveIdentifier}`);
406
- }
394
+ await this.updateCharacteristic(this.Television.Service, this.hap.Characteristic.ActiveIdentifier,
395
+ this.Television.ActiveIdentifier, 'ActiveIdentifier');
407
396
  }
408
397
 
409
398
  async apiError(e: any): Promise<void> {
@@ -103,7 +103,7 @@ export class VacuumCleaner extends irdeviceBase {
103
103
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
104
104
  const deviceStatus: any = await body.json();
105
105
  await this.pushStatusCodes(statusCode, deviceStatus);
106
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
106
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
107
107
  await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
108
108
  await this.updateHomeKitCharacteristics();
109
109
  } else {
@@ -122,13 +122,8 @@ export class VacuumCleaner extends irdeviceBase {
122
122
  async updateHomeKitCharacteristics(): Promise<void> {
123
123
  await this.debugLog('updateHomeKitCharacteristics');
124
124
  // On
125
- if (this.Switch.On === undefined) {
126
- await this.debugLog(`On: ${this.Switch.On}`);
127
- } else {
128
- this.accessory.context.On = this.Switch.On;
129
- this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
130
- await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
131
- }
125
+ await this.updateCharacteristic(this.Switch.Service, this.hap.Characteristic.On,
126
+ this.Switch.On, 'On');
132
127
  }
133
128
 
134
129
  async apiError(e: any): Promise<void> {
@@ -105,7 +105,7 @@ export class WaterHeater extends irdeviceBase {
105
105
  const { body, statusCode } = await this.pushChangeRequest(bodyChange);
106
106
  const deviceStatus: any = await body.json();
107
107
  await this.pushStatusCodes(statusCode, deviceStatus);
108
- if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
108
+ if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
109
109
  await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
110
110
  await this.updateHomeKitCharacteristics();
111
111
  } else {
@@ -124,13 +124,8 @@ export class WaterHeater extends irdeviceBase {
124
124
  async updateHomeKitCharacteristics(): Promise<void> {
125
125
  await this.debugLog('updateHomeKitCharacteristics');
126
126
  // Active
127
- if (this.Valve.Active === undefined) {
128
- await this.debugLog(`Active: ${this.Valve.Active}`);
129
- } else {
130
- this.accessory.context.Active = this.Valve.Active;
131
- this.Valve.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Valve.Active);
132
- await this.debugLog(`updateCharacteristic Active: ${this.Valve.Active}`);
133
- }
127
+ await this.updateCharacteristic(this.Valve.Service, this.hap.Characteristic.Active,
128
+ this.Valve.Active, 'Active');
134
129
  }
135
130
 
136
131
  async apiError({ e }: { e: any }): Promise<void> {
package/src/platform.ts CHANGED
@@ -33,21 +33,17 @@ import { AirConditioner } from './irdevice/airconditioner.js';
33
33
 
34
34
  import { Buffer } from 'buffer';
35
35
  import { request } from 'undici';
36
- import asyncmqtt from 'async-mqtt';
37
- import { createServer } from 'http';
38
36
  import { queueScheduler } from 'rxjs';
39
37
  import fakegato from 'fakegato-history';
40
38
  import crypto, { randomUUID } from 'crypto';
41
39
  import { readFileSync, writeFileSync } from 'fs';
42
40
  import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
41
+ import { PLATFORM_NAME, PLUGIN_NAME, Devices } from './settings.js';
43
42
  import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
44
- import { PLATFORM_NAME, PLUGIN_NAME, Devices, setupWebhook, updateWebhook, deleteWebhook, queryWebhook } from './settings.js';
45
43
 
46
44
  import type { UrlObject } from 'url';
47
- import type { MqttClient } from 'mqtt';
48
45
  import type { Dispatcher } from 'undici';
49
46
  import type { irdevice } from './types/irdevicelist.js';
50
- import type { Server, IncomingMessage, ServerResponse } from 'http';
51
47
  import type { blindTilt, curtain, curtain3, device } from './types/devicelist.js';
52
48
  import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge';
53
49
  import type { SwitchBotPlatformConfig, devicesConfig, irDevicesConfig } from './settings.js';
@@ -71,12 +67,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
71
67
  platformLogging!: SwitchBotPlatformConfig['logging'];
72
68
  config!: SwitchBotPlatformConfig;
73
69
 
74
- webhookEventListener: Server | null = null;
75
- mqttClient: MqttClient | null = null;
76
-
77
70
  public readonly fakegatoAPI: any;
78
71
  public readonly eve: any;
79
- public readonly webhookEventHandler: { [x: string]: (context: any) => void } = {};
80
72
 
81
73
  constructor(
82
74
  log: Logging,
@@ -144,171 +136,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
144
136
  await this.debugErrorLog(`Failed to Discover, Error: ${e}`);
145
137
  }
146
138
  });
147
-
148
- this.setupMqtt();
149
- this.setupwebhook();
150
- }
151
-
152
- async setupMqtt(): Promise<void> {
153
- if (this.config.options?.mqttURL) {
154
- try {
155
- const { connectAsync } = asyncmqtt;
156
- this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {});
157
- await this.debugLog('MQTT connection has been established successfully.');
158
- this.mqttClient.on('error', async (e: Error) => {
159
- await this.errorLog(`Failed to publish MQTT messages. ${e}`);
160
- });
161
- if (!this.config.options?.webhookURL) {
162
- // receive webhook events via MQTT
163
- await this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
164
- this.mqttClient.subscribe('homebridge-switchbot/webhook/+');
165
- this.mqttClient.on('message', async (topic: string, message) => {
166
- try {
167
- await await this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
168
- const context = JSON.parse(message.toString());
169
- this.webhookEventHandler[context.deviceMac]?.(context);
170
- } catch (e: any) {
171
- await this.errorLog(`Failed to handle webhook event. Error:${e}`);
172
- }
173
- });
174
- }
175
- } catch (e) {
176
- this.mqttClient = null;
177
- await this.errorLog(`Failed to establish MQTT connection. ${e}`);
178
- }
179
- }
180
- }
181
-
182
- async setupwebhook() {
183
- //webhook configuration
184
- if (this.config.options?.webhookURL) {
185
- const url = this.config.options?.webhookURL;
186
-
187
- try {
188
- const xurl = new URL(url);
189
- const port = Number(xurl.port);
190
- const path = xurl.pathname;
191
- this.webhookEventListener = createServer((request: IncomingMessage, response: ServerResponse) => {
192
- try {
193
- if (request.url === path && request.method === 'POST') {
194
- request.on('data', async (data) => {
195
- try {
196
- const body = JSON.parse(data);
197
- await this.debugLog(`Received Webhook: ${JSON.stringify(body)}`);
198
- if (this.config.options?.mqttURL) {
199
- const mac = body.context.deviceMac
200
- ?.toLowerCase()
201
- .match(/[\s\S]{1,2}/g)
202
- ?.join(':');
203
- const options = this.config.options?.mqttPubOptions || {};
204
- this.mqttClient?.publish(`homebridge-switchbot/webhook/${mac}`, `${JSON.stringify(body.context)}`, options);
205
- }
206
- this.webhookEventHandler[body.context.deviceMac]?.(body.context);
207
- } catch (e: any) {
208
- this.errorLog(`Failed to handle webhook event. Error:${e}`);
209
- }
210
- });
211
- response.writeHead(200, { 'Content-Type': 'text/plain' });
212
- response.end('OK');
213
- }
214
- // else {
215
- // response.writeHead(403, {'Content-Type': 'text/plain'});
216
- // response.end(`NG`);
217
- // }
218
- } catch (e: any) {
219
- this.errorLog(`Failed to handle webhook event. Error:${e}`);
220
- }
221
- }).listen(port ? port : 80);
222
- } catch (e: any) {
223
- this.errorLog(`Failed to create webhook listener. Error:${e.message}`);
224
- return;
225
- }
226
-
227
- try {
228
- const { body, statusCode } = await request(setupWebhook, {
229
- method: 'POST',
230
- headers: this.generateHeaders(),
231
- body: JSON.stringify({
232
- 'action': 'setupWebhook',
233
- 'url': url,
234
- 'deviceList': 'ALL',
235
- }),
236
- });
237
- const response: any = await body.json();
238
- await this.debugLog(`setupWebhook: url:${url}`);
239
- await this.debugLog(`setupWebhook: body:${JSON.stringify(response)}`);
240
- await this.debugLog(`setupWebhook: statusCode:${statusCode}`);
241
- if (statusCode !== 200 || response?.statusCode !== 100) {
242
- this.errorLog(`Failed to configure webhook. Existing webhook well be overridden. HTTP:${statusCode} API:${response?.statusCode} `
243
- + `message:${response?.message}`);
244
- }
245
- } catch (e: any) {
246
- this.errorLog(`Failed to configure webhook. Error: ${e.message}`);
247
- }
248
-
249
- try {
250
- const { body, statusCode } = await request(updateWebhook, {
251
- method: 'POST', headers: this.generateHeaders(), body: JSON.stringify({
252
- 'action': 'updateWebhook',
253
- 'config': {
254
- 'url': url,
255
- 'enable': true,
256
- },
257
- }),
258
- });
259
- const response: any = await body.json();
260
- await this.debugLog(`updateWebhook: url:${url}`);
261
- await this.debugLog(`updateWebhook: body:${JSON.stringify(response)}`);
262
- await this.debugLog(`updateWebhook: statusCode:${statusCode}`);
263
- if (statusCode !== 200 || response?.statusCode !== 100) {
264
- this.errorLog(`Failed to update webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
265
- }
266
- } catch (e: any) {
267
- this.errorLog(`Failed to update webhook. Error:${e.message}`);
268
- }
269
-
270
- try {
271
- const { body, statusCode } = await request(queryWebhook, {
272
- method: 'POST',
273
- headers: this.generateHeaders(),
274
- body: JSON.stringify({
275
- 'action': 'queryUrl',
276
- }),
277
- });
278
- const response: any = await body.json();
279
- await this.debugLog(`queryWebhook: body:${JSON.stringify(response)}`);
280
- await this.debugLog(`queryWebhook: statusCode:${statusCode}`);
281
- if (statusCode !== 200 || response?.statusCode !== 100) {
282
- this.errorLog(`Failed to query webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
283
- } else {
284
- this.infoLog(`Listening webhook on ${response?.body?.urls[0]}`);
285
- }
286
- } catch (e: any) {
287
- this.errorLog(`Failed to query webhook. Error:${e}`);
288
- }
289
-
290
- this.api.on('shutdown', async () => {
291
- try {
292
- const { body, statusCode } = await request(deleteWebhook, {
293
- method: 'POST',
294
- headers: this.generateHeaders(),
295
- body: JSON.stringify({
296
- 'action': 'deleteWebhook',
297
- 'url': url,
298
- }),
299
- });
300
- const response: any = await body.json();
301
- await this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
302
- if (statusCode !== 200 || response?.statusCode !== 100) {
303
- this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
304
- } else {
305
- this.infoLog('Unregistered webhook to close listening.');
306
- }
307
- } catch (e: any) {
308
- this.errorLog(`Failed to delete webhook. Error:${e.message}`);
309
- }
310
- });
311
- }
312
139
  }
313
140
 
314
141
  /**
@@ -2678,10 +2505,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2678
2505
  await this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
2679
2506
  break;
2680
2507
  case 100:
2681
- await await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
2508
+ await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
2682
2509
  break;
2683
2510
  case 200:
2684
- await await this.debugLog(`Request successful, statusCode: ${statusCode}`);
2511
+ await this.debugLog(`Request successful, statusCode: ${statusCode}`);
2685
2512
  break;
2686
2513
  case 400:
2687
2514
  await this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
@@ -2735,13 +2562,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2735
2562
  if (statusCode === 200 || statusCode === 100) {
2736
2563
  return { body, statusCode };
2737
2564
  } else {
2738
- await await this.debugLog(`Received status code: ${statusCode}`);
2565
+ await this.debugLog(`Received status code: ${statusCode}`);
2739
2566
  }
2740
2567
  } catch (error: any) {
2741
2568
  await this.errorLog(`Error making request: ${error.message}`);
2742
2569
  }
2743
2570
  retryCount++;
2744
- await await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
2571
+ await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
2745
2572
  await sleep(delayBetweenRetries);
2746
2573
  }
2747
2574
  return { body: null, statusCode: -1 };
@@ -2753,7 +2580,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2753
2580
  try {
2754
2581
  const SwitchBot = (await import('node-switchbot')).SwitchBot;
2755
2582
  queueScheduler.schedule(() => (switchbot = new SwitchBot()));
2756
- await await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`);
2583
+ await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`);
2757
2584
  } catch (e: any) {
2758
2585
  switchbot = false;
2759
2586
  await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}, Error: ${e}`);
@@ -2768,7 +2595,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2768
2595
  'utf-8',
2769
2596
  ),
2770
2597
  );
2771
- await await this.debugLog(`Plugin Version: ${json.version}`);
2598
+ await this.debugLog(`Plugin Version: ${json.version}`);
2772
2599
  this.version = json.version;
2773
2600
  }
2774
2601
 
@@ -2804,7 +2631,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2804
2631
  platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
2805
2632
  }
2806
2633
  if (Object.entries(platformConfig).length !== 0) {
2807
- await await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
2634
+ await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
2808
2635
  }
2809
2636
  this.platformConfig = platformConfig;
2810
2637
  }
@@ -2814,13 +2641,13 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2814
2641
  this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
2815
2642
  if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
2816
2643
  this.platformLogging = this.config.options.logging;
2817
- await await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
2644
+ await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
2818
2645
  } else if (this.debugMode) {
2819
2646
  this.platformLogging = 'debugMode';
2820
- await await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2647
+ await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2821
2648
  } else {
2822
2649
  this.platformLogging = 'standard';
2823
- await await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2650
+ await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2824
2651
  }
2825
2652
  }
2826
2653
 
package/src/settings.ts CHANGED
@@ -56,18 +56,18 @@ interface credentials {
56
56
  }
57
57
 
58
58
  interface options {
59
- refreshRate?: number;
60
- updateRate?: number;
61
- pushRate?: number;
62
- maxRetries?: number;
63
- delayBetweenRetries?: number;
64
- logging?: string;
65
59
  devices?: devicesConfig[];
66
60
  irdevices?: irDevicesConfig[];
67
- webhookURL?: string;
68
61
  mqttURL?: string;
69
62
  mqttOptions?: IClientOptions;
70
63
  mqttPubOptions?: IClientOptions;
64
+ webhookURL?: string;
65
+ maxRetries?: number;
66
+ delayBetweenRetries?: number;
67
+ refreshRate?: number;
68
+ updateRate?: number;
69
+ pushRate?: number;
70
+ logging?: string;
71
71
  };
72
72
 
73
73
  export interface devicesConfig extends device {
@@ -111,7 +111,7 @@ export interface devicesConfig extends device {
111
111
  colorbulb?: colorbulb;
112
112
  striplight?: striplight;
113
113
  ceilinglight?: ceilinglight;
114
- plug?: Record<any, any>;
114
+ plug?: plug;
115
115
  lock?: lock;
116
116
  hub?: hub;
117
117
  }
@@ -198,6 +198,8 @@ interface ceilinglight {
198
198
  adaptiveLightingShift?: number;
199
199
  };
200
200
 
201
+ type plug = object;
202
+
201
203
  interface lock {
202
204
  hide_contactsensor?: boolean;
203
205
  activate_latchbutton?: boolean;
@@ -16,8 +16,9 @@ export type ad = {
16
16
  rssi: number;
17
17
  serviceData: botServiceData | colorBulbServiceData | contactSensorServiceData |
18
18
  curtainServiceData | curtain3ServiceData | stripLightServiceData | lockServiceData |
19
- lockProServiceData | meterServiceData | meterPlusServiceData | motionSensorServiceData |
20
- plugMiniUSServiceData | plugMiniJPServiceData | blindTiltServiceData;
19
+ lockProServiceData | meterServiceData | meterPlusServiceData | motionSensorServiceData | outdoorMeterServiceData |
20
+ plugMiniUSServiceData | plugMiniJPServiceData | blindTiltServiceData | ceilingLightServiceData | ceilingLightProServiceData |
21
+ hub2ServiceData | batteryCirculatorFanServiceData | waterLeakDetectorServiceData | humidifierServiceData | robotVacuumCleanerServiceData;
21
22
  };
22
23
 
23
24
  type serviceData = {
@@ -271,6 +272,7 @@ export type batteryCirculatorFanServiceData = serviceData & {
271
272
  modelName: SwitchBotBLEModelName.Unknown,
272
273
  modelFriendlyName: SwitchBotBLEModelFriendlyName.Unknown,
273
274
  state: string;
275
+ fanSpeed: number;
274
276
  };
275
277
 
276
278
  export type waterLeakDetectorServiceData = serviceData & {
@@ -154,7 +154,7 @@ export type humidifierStatus = deviceStatus & {
154
154
 
155
155
  export type blindTiltStatus = deviceStatus & {
156
156
  calibrate: boolean;
157
- battery: boolean;
157
+ battery: number;
158
158
  direction: string;
159
159
  slidePosition: string;
160
160
  lightLevel?: 'bright' | 'dim';