@switchbot/homebridge-switchbot 2.7.1 → 2.8.0-beta.1

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 (119) hide show
  1. package/.github/npm-version-script.js +81 -0
  2. package/.prettierrc +1 -1
  3. package/.vscode/settings.json +1 -1
  4. package/CHANGELOG.md +10 -0
  5. package/config.schema.json +8 -0
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +49 -59
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +44 -50
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts.map +1 -1
  13. package/dist/device/ceilinglight.js +60 -63
  14. package/dist/device/ceilinglight.js.map +1 -1
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +68 -70
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +22 -25
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts.map +1 -1
  22. package/dist/device/curtain.js +50 -58
  23. package/dist/device/curtain.js.map +1 -1
  24. package/dist/device/hub.d.ts +6 -0
  25. package/dist/device/hub.d.ts.map +1 -1
  26. package/dist/device/hub.js +168 -26
  27. package/dist/device/hub.js.map +1 -1
  28. package/dist/device/humidifier.d.ts.map +1 -1
  29. package/dist/device/humidifier.js +49 -56
  30. package/dist/device/humidifier.js.map +1 -1
  31. package/dist/device/iosensor.d.ts.map +1 -1
  32. package/dist/device/iosensor.js +18 -20
  33. package/dist/device/iosensor.js.map +1 -1
  34. package/dist/device/lightstrip.d.ts.map +1 -1
  35. package/dist/device/lightstrip.js +59 -61
  36. package/dist/device/lightstrip.js.map +1 -1
  37. package/dist/device/lock.d.ts.map +1 -1
  38. package/dist/device/lock.js +40 -41
  39. package/dist/device/lock.js.map +1 -1
  40. package/dist/device/meter.d.ts +3 -3
  41. package/dist/device/meter.d.ts.map +1 -1
  42. package/dist/device/meter.js +65 -68
  43. package/dist/device/meter.js.map +1 -1
  44. package/dist/device/meterplus.d.ts.map +1 -1
  45. package/dist/device/meterplus.js +18 -20
  46. package/dist/device/meterplus.js.map +1 -1
  47. package/dist/device/motion.d.ts.map +1 -1
  48. package/dist/device/motion.js +20 -23
  49. package/dist/device/motion.js.map +1 -1
  50. package/dist/device/plug.d.ts.map +1 -1
  51. package/dist/device/plug.js +30 -33
  52. package/dist/device/plug.js.map +1 -1
  53. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  54. package/dist/device/robotvacuumcleaner.js +48 -51
  55. package/dist/device/robotvacuumcleaner.js.map +1 -1
  56. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  57. package/dist/irdevice/airconditioner.js +57 -61
  58. package/dist/irdevice/airconditioner.js.map +1 -1
  59. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  60. package/dist/irdevice/airpurifier.js +29 -31
  61. package/dist/irdevice/airpurifier.js.map +1 -1
  62. package/dist/irdevice/camera.d.ts.map +1 -1
  63. package/dist/irdevice/camera.js +17 -20
  64. package/dist/irdevice/camera.js.map +1 -1
  65. package/dist/irdevice/fan.d.ts.map +1 -1
  66. package/dist/irdevice/fan.js +27 -29
  67. package/dist/irdevice/fan.js.map +1 -1
  68. package/dist/irdevice/light.d.ts.map +1 -1
  69. package/dist/irdevice/light.js +23 -26
  70. package/dist/irdevice/light.js.map +1 -1
  71. package/dist/irdevice/other.d.ts.map +1 -1
  72. package/dist/irdevice/other.js +19 -20
  73. package/dist/irdevice/other.js.map +1 -1
  74. package/dist/irdevice/tv.d.ts.map +1 -1
  75. package/dist/irdevice/tv.js +44 -47
  76. package/dist/irdevice/tv.js.map +1 -1
  77. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  78. package/dist/irdevice/vacuumcleaner.js +17 -20
  79. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  80. package/dist/irdevice/waterheater.d.ts.map +1 -1
  81. package/dist/irdevice/waterheater.js +19 -20
  82. package/dist/irdevice/waterheater.js.map +1 -1
  83. package/dist/platform.d.ts.map +1 -1
  84. package/dist/platform.js +44 -43
  85. package/dist/platform.js.map +1 -1
  86. package/dist/settings.d.ts +1 -0
  87. package/dist/settings.d.ts.map +1 -1
  88. package/dist/settings.js.map +1 -1
  89. package/dist/utils.js +1 -1
  90. package/dist/utils.js.map +1 -1
  91. package/package.json +1 -1
  92. package/src/device/blindtilt.ts +106 -72
  93. package/src/device/bot.ts +94 -58
  94. package/src/device/ceilinglight.ts +102 -68
  95. package/src/device/colorbulb.ts +134 -82
  96. package/src/device/contact.ts +54 -33
  97. package/src/device/curtain.ts +130 -101
  98. package/src/device/hub.ts +198 -35
  99. package/src/device/humidifier.ts +128 -80
  100. package/src/device/iosensor.ts +43 -27
  101. package/src/device/lightstrip.ts +108 -67
  102. package/src/device/lock.ts +73 -45
  103. package/src/device/meter.ts +94 -75
  104. package/src/device/meterplus.ts +43 -27
  105. package/src/device/motion.ts +50 -32
  106. package/src/device/plug.ts +62 -39
  107. package/src/device/robotvacuumcleaner.ts +78 -54
  108. package/src/irdevice/airconditioner.ts +111 -83
  109. package/src/irdevice/airpurifier.ts +55 -34
  110. package/src/irdevice/camera.ts +35 -23
  111. package/src/irdevice/fan.ts +47 -33
  112. package/src/irdevice/light.ts +43 -29
  113. package/src/irdevice/other.ts +39 -23
  114. package/src/irdevice/tv.ts +65 -51
  115. package/src/irdevice/vacuumcleaner.ts +35 -23
  116. package/src/irdevice/waterheater.ts +43 -27
  117. package/src/platform.ts +85 -55
  118. package/src/settings.ts +41 -40
  119. package/src/utils.ts +1 -1
package/src/platform.ts CHANGED
@@ -32,8 +32,7 @@ import { EveHomeKitTypes } from 'homebridge-lib';
32
32
 
33
33
  import { readFileSync, writeFileSync } from 'fs';
34
34
  import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, Service, Characteristic } from 'homebridge';
35
- import {
36
- PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig, devicesConfig, irDevicesConfig, Devices } from './settings';
35
+ import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig, devicesConfig, irDevicesConfig, Devices } from './settings';
37
36
 
38
37
  /**
39
38
  * HomebridgePlatform
@@ -54,7 +53,11 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
54
53
  public readonly fakegatoAPI: any;
55
54
  public readonly eve: any;
56
55
 
57
- constructor(public readonly log: Logger, public readonly config: SwitchBotPlatformConfig, public readonly api: API) {
56
+ constructor(
57
+ public readonly log: Logger,
58
+ public readonly config: SwitchBotPlatformConfig,
59
+ public readonly api: API,
60
+ ) {
58
61
  this.logs();
59
62
  this.debugLog('Finished initializing platform:', this.config.name);
60
63
  // only load if configured
@@ -64,8 +67,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
64
67
 
65
68
  // HOOBS notice
66
69
  if (__dirname.includes('hoobs')) {
67
- this.warnLog('This plugin has not been tested under HOOBS, it is highly recommended that you switch to Homebridge: '
68
- + 'https://tinyurl.com/HOOBS2Homebridge');
70
+ this.warnLog(
71
+ 'This plugin has not been tested under HOOBS, it is highly recommended that you switch to Homebridge: ' +
72
+ 'https://tinyurl.com/HOOBS2Homebridge',
73
+ );
69
74
  }
70
75
 
71
76
  // verify the config
@@ -94,7 +99,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
94
99
  await this.updateToken();
95
100
  } else if (this.config.credentials?.token && !this.config.credentials?.secret) {
96
101
  // eslint-disable-next-line no-useless-escape
97
- this.errorLog('\"secret\" config is not populated, you must populate then please restart Homebridge.');
102
+ this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.');
98
103
  } else {
99
104
  this.discoverDevices();
100
105
  }
@@ -177,9 +182,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
177
182
  }
178
183
 
179
184
  if (!this.config.options.pushRate) {
180
- // default 100 milliseconds
181
- this.config.options!.pushRate! = 0.1;
182
- this.debugWarnLog('Using Default Push Rate.');
185
+ // default 100 milliseconds
186
+ this.config.options!.pushRate! = 0.1;
187
+ this.debugWarnLog('Using Default Push Rate.');
183
188
  }
184
189
 
185
190
  if (!this.config.credentials && !this.config.options) {
@@ -230,14 +235,18 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
230
235
  throw new Error('pluginConfig.credentials is not an object');
231
236
  }
232
237
  // Move openToken to token
233
- if (!this.config.credentials.secret){
238
+ if (!this.config.credentials.secret) {
234
239
  // eslint-disable-next-line no-useless-escape, max-len
235
- this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken, \"openToken\" cconfig has been moved to the \"token\" config' );
240
+ this.warnLog(
241
+ 'This plugin has been updated to use OpenAPI v1.1, config is set with openToken, "openToken" cconfig has been moved to the "token" config',
242
+ );
236
243
  // eslint-disable-next-line no-useless-escape
237
- this.errorLog('\"secret\" config is not populated, you must populate then please restart Homebridge.');
244
+ this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.');
238
245
  } else {
239
246
  // eslint-disable-next-line no-useless-escape, max-len
240
- this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken, \"openToken\" config has been moved to the \"token\" config, please restart Homebridge.');
247
+ this.warnLog(
248
+ 'This plugin has been updated to use OpenAPI v1.1, config is set with openToken, "openToken" config has been moved to the "token" config, please restart Homebridge.',
249
+ );
241
250
  }
242
251
 
243
252
  // set the refresh token
@@ -260,14 +269,17 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
260
269
  const t = `${Date.now()}`;
261
270
  const nonce = randomUUID();
262
271
  const data = this.config.credentials?.token + t + nonce;
263
- const signTerm = crypto.createHmac('sha256', this.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
272
+ const signTerm = crypto
273
+ .createHmac('sha256', this.config.credentials?.secret)
274
+ .update(Buffer.from(data, 'utf-8'))
275
+ .digest();
264
276
  const sign = signTerm.toString('base64');
265
277
 
266
278
  return {
267
- 'Authorization': this.config.credentials?.token,
268
- 'sign': sign,
269
- 'nonce': nonce,
270
- 't': t,
279
+ Authorization: this.config.credentials?.token,
280
+ sign: sign,
281
+ nonce: nonce,
282
+ t: t,
271
283
  'Content-Type': 'application/json',
272
284
  };
273
285
  };
@@ -374,10 +386,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
374
386
  } else {
375
387
  this.debugLog(`Total IR Devices Found: ${devicesAPI.body.infraredRemoteList.length}`);
376
388
  }
377
-
378
389
  } catch (e: any) {
379
- this.debugErrorLog(`Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: `
380
- + 'https://tinyurl.com/SwitchBotBug');
390
+ this.debugErrorLog(
391
+ `Failed to Discover Devices, Error Message: ${JSON.stringify(e.message)}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug',
392
+ );
381
393
  this.debugErrorLog(`Failed to Discover Devices, Error: ${e}`);
382
394
  }
383
395
  } else if (!this.config.credentials?.token && this.config.options?.devices) {
@@ -624,7 +636,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
624
636
  if (existingAccessory) {
625
637
  // the accessory already exists
626
638
  if (await this.registerDevice(device)) {
627
-
628
639
  // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
629
640
  existingAccessory.context.model = device.deviceType;
630
641
  existingAccessory.context.deviceID = device.deviceId;
@@ -1043,8 +1054,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1043
1054
  }
1044
1055
 
1045
1056
  if (device.group && !device.curtain?.disable_group) {
1046
- this.debugLog('Your Curtains are grouped, '
1047
- + `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1057
+ this.debugLog(
1058
+ 'Your Curtains are grouped, ' +
1059
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`,
1060
+ );
1048
1061
  } else {
1049
1062
  if (device.master) {
1050
1063
  this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
@@ -1110,8 +1123,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1110
1123
  }
1111
1124
 
1112
1125
  if (device.group && !device.curtain?.disable_group) {
1113
- this.debugLog('Your Curtains are grouped, '
1114
- + `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
1126
+ this.debugLog(
1127
+ 'Your Curtains are grouped, ' +
1128
+ `, Secondary curtain automatically hidden. Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`,
1129
+ );
1115
1130
  } else {
1116
1131
  if (device.master) {
1117
1132
  this.warnLog(`Main Curtain: ${device.deviceName}, DeviceID: ${device.deviceId}`);
@@ -1983,42 +1998,56 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1983
1998
 
1984
1999
  async registerCurtains(device: device & devicesConfig) {
1985
2000
  if (device.deviceType === 'Curtain') {
1986
- this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: `
1987
- + `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
2001
+ this.debugWarnLog(
2002
+ `deviceName: ${device.deviceName} deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds}, master: ` +
2003
+ `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`,
2004
+ );
1988
2005
  } else {
1989
- this.debugWarnLog(`deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds}, master: `
1990
- + `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`);
2006
+ this.debugWarnLog(
2007
+ `deviceName: ${device.deviceName} deviceId: ${device.deviceId}, blindTiltDevicesIds: ${device.blindTiltDevicesIds}, master: ` +
2008
+ `${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}, connectionType: ${device.connectionType}`,
2009
+ );
1991
2010
  }
1992
2011
 
1993
2012
  let registerCurtain: boolean;
1994
2013
  if (device.master && device.group) {
1995
2014
  // OpenAPI: Master Curtains/Blind Tilt in Group
1996
2015
  registerCurtain = true;
1997
- this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group}`
1998
- + ` connectionType; ${device.connectionType}`);
2016
+ this.debugLog(
2017
+ `deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group}` +
2018
+ ` connectionType; ${device.connectionType}`,
2019
+ );
1999
2020
  this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
2000
- } else if (!device.master && device.curtain?.disable_group) { //!device.group && device.connectionType === 'BLE'
2021
+ } else if (!device.master && device.curtain?.disable_group) {
2022
+ //!device.group && device.connectionType === 'BLE'
2001
2023
  // OpenAPI: Non-Master Curtains/Blind Tilts that has Disable Grouping Checked
2002
2024
  registerCurtain = true;
2003
- this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: `
2004
- + `${device.curtain?.disable_group}, connectionType; ${device.connectionType}`);
2025
+ this.debugLog(
2026
+ `deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, disable_group: ` +
2027
+ `${device.curtain?.disable_group}, connectionType; ${device.connectionType}`,
2028
+ );
2005
2029
  this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
2006
2030
  } else if (device.master && !device.group) {
2007
2031
  // OpenAPI: Master Curtains/Blind Tilts not in Group
2008
2032
  registerCurtain = true;
2009
- this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group}`
2010
- + ` connectionType; ${device.connectionType}`);
2033
+ this.debugLog(
2034
+ `deviceName: ${device.deviceName} [${device.deviceType} Config] device.master: ${device.master}, device.group: ${device.group}` +
2035
+ ` connectionType; ${device.connectionType}`,
2036
+ );
2011
2037
  this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
2012
2038
  } else if (device.connectionType === 'BLE') {
2013
2039
  // BLE: Curtains/Blind Tilt
2014
2040
  registerCurtain = true;
2015
- this.debugLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, `
2016
- + ` group: ${device.group}`);
2041
+ this.debugLog(
2042
+ `deviceName: ${device.deviceName} [${device.deviceType} Config] connectionType: ${device.connectionType}, ` + ` group: ${device.group}`,
2043
+ );
2017
2044
  this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}`);
2018
2045
  } else {
2019
2046
  registerCurtain = false;
2020
- this.debugErrorLog(`deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group},`
2021
- + ` device.master: ${device.master}, device.group: ${device.group}`);
2047
+ this.debugErrorLog(
2048
+ `deviceName: ${device.deviceName} [${device.deviceType} Config] disable_group: ${device.curtain?.disable_group},` +
2049
+ ` device.master: ${device.master}, device.group: ${device.group}`,
2050
+ );
2022
2051
  this.debugWarnLog(`Device: ${device.deviceName} registerCurtains: ${registerCurtain}, device.connectionType: ${device.connectionType}`);
2023
2052
  }
2024
2053
  return registerCurtain;
@@ -2046,8 +2075,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2046
2075
  this.debugWarnLog(`Device: ${device.deviceName} registerDevice: ${registerDevice}`);
2047
2076
  }
2048
2077
  this.debugWarnLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will display in HomeKit`);
2049
- } else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName
2050
- && device.connectionType === 'BLE') {
2078
+ } else if (!device.hide_device && device.deviceId && device.configDeviceType && device.configDeviceName && device.connectionType === 'BLE') {
2051
2079
  if (device.deviceType === 'Curtain' || device.deviceType === 'Blind Tilt') {
2052
2080
  registerDevice = await this.registerCurtains(device);
2053
2081
  this.debugWarnLog(`Device: ${device.deviceName} ${device.deviceType} registerDevice: ${registerDevice}`);
@@ -2077,23 +2105,25 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2077
2105
  } else if (!device.connectionType && !device.hide_device) {
2078
2106
  registerDevice = false;
2079
2107
  this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, will not display in HomeKit`);
2080
- } else if (device.hide_device){
2108
+ } else if (device.hide_device) {
2081
2109
  registerDevice = false;
2082
2110
  this.debugErrorLog(`Device: ${device.deviceName} hide_device: ${device.hide_device}, will not display in HomeKit`);
2083
2111
  } else {
2084
2112
  registerDevice = false;
2085
- this.debugErrorLog(`Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: `
2086
- + `${device.hide_device}, will not display in HomeKit`);
2113
+ this.debugErrorLog(
2114
+ `Device: ${device.deviceName} connectionType: ${device.connectionType}, hide_device: ` +
2115
+ `${device.hide_device}, will not display in HomeKit`,
2116
+ );
2087
2117
  }
2088
2118
  return registerDevice;
2089
2119
  }
2090
2120
 
2091
2121
  public async externalOrPlatformIR(device: device & irDevicesConfig, accessory: PlatformAccessory) {
2092
2122
  /**
2093
- * Publish as external accessory
2094
- * Only one TV can exist per bridge, to bypass this limitation, you should
2095
- * publish your TV as an external accessory.
2096
- */
2123
+ * Publish as external accessory
2124
+ * Only one TV can exist per bridge, to bypass this limitation, you should
2125
+ * publish your TV as an external accessory.
2126
+ */
2097
2127
  if (device.external) {
2098
2128
  this.debugWarnLog(`${accessory.displayName} External Accessory Mode`);
2099
2129
  this.externalAccessory(accessory);
@@ -2126,8 +2156,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2126
2156
  async statusCode(statusCode: number): Promise<void> {
2127
2157
  switch (statusCode) {
2128
2158
  case 151:
2129
- this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: `
2130
- + 'https://tinyurl.com/SwitchBotFeatureRequest');
2159
+ this.errorLog(
2160
+ `Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
2161
+ 'https://tinyurl.com/SwitchBotFeatureRequest',
2162
+ );
2131
2163
  break;
2132
2164
  case 152:
2133
2165
  this.errorLog(`Device not found, statusCode: ${statusCode}`);
@@ -2161,9 +2193,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2161
2193
  let switchbot: any;
2162
2194
  try {
2163
2195
  Switchbot = require('node-switchbot');
2164
- queueScheduler.schedule(() =>
2165
- switchbot = new Switchbot(),
2166
- );
2196
+ queueScheduler.schedule(() => (switchbot = new Switchbot()));
2167
2197
  } catch (e: any) {
2168
2198
  switchbot = false;
2169
2199
  this.errorLog(`Was 'node-switchbot' found: ${switchbot}`);
package/src/settings.ts CHANGED
@@ -151,6 +151,7 @@ export type lock = {
151
151
  export type hub = {
152
152
  hide_temperature?: boolean;
153
153
  hide_humidity?: boolean;
154
+ hide_lightsensor?: boolean;
154
155
  };
155
156
 
156
157
  export interface irDevicesConfig extends irdevice {
@@ -201,7 +202,7 @@ export type body = {
201
202
  command: string;
202
203
  parameter: string;
203
204
  commandType: string;
204
- }
205
+ };
205
206
 
206
207
  //a list of physical devices.
207
208
  export type deviceList = {
@@ -254,45 +255,45 @@ export type irdevice = {
254
255
  };
255
256
 
256
257
  export type deviceStatus = {
257
- //v1.1 of API
258
- deviceId: string; //device ID. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
259
- deviceType: string; //device type. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
260
- hubDeviceId: string; //device's parent Hub ID. 000000000000 when the device itself is a Hub or it is connected through Wi-Fi. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
261
- power?: string; //ON/OFF state. (Used by the following deviceTypes: Bot, Ceiling Light, Ceiling Light Pro, PLug, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Humidifier)
262
- calibrate?: boolean; //determines if device has been calibrated or not. (Used by the following deviceTypes: Curtain, Lock, Blind Tilt)
263
- group?: boolean; //determines if a device is paired with or grouped with another device or not. (Used by the following deviceTypes: Curtain, Blind Tilt)
264
- moving?: boolean; //determines if a device is moving or not. (Used by the following deviceTypes: Curtain, Blind Tilt)
265
- slidePosition?: number;//the current position (0-100) the percentage of the distance between the calibrated open position and closed position. (Used by the following deviceTypes: Curtain, Blind Tilt)
266
- temperature?: number; //temperature in celsius (Used by the following deviceTypes: Meter, Meter Plus, Humidifier, IOSensor)
267
- humidity?: number; //humidity percentage. (Used by the following deviceTypes: Meter, Meter Plus, Humidifier, IOSensor)
268
- lockState?: string; //determines if locked or not. (Used by the following deviceTypes: Lock)
269
- doorState?: string; //determines if the door is closed or not. (Used by the following deviceTypes: Lock)
270
- moveDetected?: boolean; //determines if motion is detected. (Used by the following deviceTypes: Motion Sensor, Contact Sensor)
271
- brightness?: string | number; //the ambient brightness picked up by the sensor. bright or dim. (Used by the following deviceTypes: Motion Sensor, Contact Sensor) | the brightness value, range from 1 to 100. (Used by the following deviceTypes: Ceiling Light, Ceiling Light Pro, Strip Light, Color Bulb)
272
- openState?: string; //the open state of the sensor. open, close, or timeOutNotClose. (Used by the following deviceTypes: Contact Sensor)
273
- colorTemperature?: number; //the color temperature value, range from 2700 to 6500. (Used by the following deviceTypes: Ceiling Light, Ceiling Light Pro, Color Bulb)
274
- voltage?: number; //the voltage of the device, measured in Volt. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
275
- weight?: number; //the power consumed in a day, measured in Watts. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
276
- electricityOfDay?: number; //the duration that the device has been used during a day, measured in minutes. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
277
- electricCurrent?: number; //the current of the device at the moment, measured in Amp. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
278
- color?: string; //the color value, RGB "255:255:255". (Used by the following deviceTypes: Strip Light, Color Bulb)
279
- workingStatus?: string; //the working status of the device. StandBy, Clearing, Paused, GotoChargeBase, Charging, ChargeDone, Dormant, InTrouble, InRemoteControl, or InDustCollecting. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus)
280
- onlineStatus?: string; //the connection status of the device. online or offline. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus)
281
- battery?: number; //the current battery level. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Blind Tilt, IOSensor)
282
- deviceName?: string; //device name. (Used by the following deviceTypes: Robot Vacuum Cleaner S1 Plus)
283
- nebulizationEfficiency?: number; //atomization efficiency percentage. (Used by the following deviceTypes: Humidifier)
284
- auto?: boolean; //determines if a Humidifier is in Auto Mode or not. (Used by the following deviceTypes: Humidifier)
285
- childLock?: boolean; //determines if a Humidifier's safety lock is on or not. (Used by the following deviceTypes: Humidifier)
286
- sound?: boolean;//determines if a Humidifier is muted or not. (Used by the following deviceTypes: Humidifier)
287
- lackWater?: boolean;//determines if the water tank is empty or not. (Used by the following deviceTypes: Humidifier)
288
- version?: number;//the version of the device. (Used by the following deviceTypes: Blind Tilt)
289
- direction?: string;//the opening direction of a Blind Tilt device. (Used by the following deviceTypes: Blind Tilt)
290
- runStatus?: string;//'static' when not moving. (Used by the following deviceTypes: Blind Tilt)
291
- mode?: number; //available for devices. the fan mode. (Used by the following deviceTypes: Smart Fan)
292
- speed?: number;//the fan speed. (Used by the following deviceTypes: Smart Fan)
293
- shaking?: boolean;//determines if the fan is swinging or not. (Used by the following deviceTypes: Smart Fan)
294
- shakeCenter?: string;//the fan's swing direciton. (Used by the following deviceTypes: Smart Fan)
295
- shakeRange?: string;//the fan's swing range, 0~120°. (Used by the following deviceTypes: Smart Fan)
258
+ //v1.1 of API
259
+ deviceId: string; //device ID. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
260
+ deviceType: string; //device type. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
261
+ hubDeviceId: string; //device's parent Hub ID. 000000000000 when the device itself is a Hub or it is connected through Wi-Fi. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
262
+ power?: string; //ON/OFF state. (Used by the following deviceTypes: Bot, Ceiling Light, Ceiling Light Pro, PLug, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Humidifier)
263
+ calibrate?: boolean; //determines if device has been calibrated or not. (Used by the following deviceTypes: Curtain, Lock, Blind Tilt)
264
+ group?: boolean; //determines if a device is paired with or grouped with another device or not. (Used by the following deviceTypes: Curtain, Blind Tilt)
265
+ moving?: boolean; //determines if a device is moving or not. (Used by the following deviceTypes: Curtain, Blind Tilt)
266
+ slidePosition?: number; //the current position (0-100) the percentage of the distance between the calibrated open position and closed position. (Used by the following deviceTypes: Curtain, Blind Tilt)
267
+ temperature?: number; //temperature in celsius (Used by the following deviceTypes: Meter, Meter Plus, Humidifier, IOSensor)
268
+ humidity?: number; //humidity percentage. (Used by the following deviceTypes: Meter, Meter Plus, Humidifier, IOSensor)
269
+ lockState?: string; //determines if locked or not. (Used by the following deviceTypes: Lock)
270
+ doorState?: string; //determines if the door is closed or not. (Used by the following deviceTypes: Lock)
271
+ moveDetected?: boolean; //determines if motion is detected. (Used by the following deviceTypes: Motion Sensor, Contact Sensor)
272
+ brightness?: string | number; //the ambient brightness picked up by the sensor. bright or dim. (Used by the following deviceTypes: Motion Sensor, Contact Sensor) | the brightness value, range from 1 to 100. (Used by the following deviceTypes: Ceiling Light, Ceiling Light Pro, Strip Light, Color Bulb)
273
+ openState?: string; //the open state of the sensor. open, close, or timeOutNotClose. (Used by the following deviceTypes: Contact Sensor)
274
+ colorTemperature?: number; //the color temperature value, range from 2700 to 6500. (Used by the following deviceTypes: Ceiling Light, Ceiling Light Pro, Color Bulb)
275
+ voltage?: number; //the voltage of the device, measured in Volt. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
276
+ weight?: number; //the power consumed in a day, measured in Watts. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
277
+ electricityOfDay?: number; //the duration that the device has been used during a day, measured in minutes. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
278
+ electricCurrent?: number; //the current of the device at the moment, measured in Amp. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
279
+ color?: string; //the color value, RGB "255:255:255". (Used by the following deviceTypes: Strip Light, Color Bulb)
280
+ workingStatus?: string; //the working status of the device. StandBy, Clearing, Paused, GotoChargeBase, Charging, ChargeDone, Dormant, InTrouble, InRemoteControl, or InDustCollecting. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus)
281
+ onlineStatus?: string; //the connection status of the device. online or offline. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus)
282
+ battery?: number; //the current battery level. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Blind Tilt, IOSensor)
283
+ deviceName?: string; //device name. (Used by the following deviceTypes: Robot Vacuum Cleaner S1 Plus)
284
+ nebulizationEfficiency?: number; //atomization efficiency percentage. (Used by the following deviceTypes: Humidifier)
285
+ auto?: boolean; //determines if a Humidifier is in Auto Mode or not. (Used by the following deviceTypes: Humidifier)
286
+ childLock?: boolean; //determines if a Humidifier's safety lock is on or not. (Used by the following deviceTypes: Humidifier)
287
+ sound?: boolean; //determines if a Humidifier is muted or not. (Used by the following deviceTypes: Humidifier)
288
+ lackWater?: boolean; //determines if the water tank is empty or not. (Used by the following deviceTypes: Humidifier)
289
+ version?: number; //the version of the device. (Used by the following deviceTypes: Blind Tilt)
290
+ direction?: string; //the opening direction of a Blind Tilt device. (Used by the following deviceTypes: Blind Tilt)
291
+ runStatus?: string; //'static' when not moving. (Used by the following deviceTypes: Blind Tilt)
292
+ mode?: number; //available for devices. the fan mode. (Used by the following deviceTypes: Smart Fan)
293
+ speed?: number; //the fan speed. (Used by the following deviceTypes: Smart Fan)
294
+ shaking?: boolean; //determines if the fan is swinging or not. (Used by the following deviceTypes: Smart Fan)
295
+ shakeCenter?: string; //the fan's swing direciton. (Used by the following deviceTypes: Smart Fan)
296
+ shakeRange?: string; //the fan's swing range, 0~120°. (Used by the following deviceTypes: Smart Fan)
296
297
  };
297
298
 
298
299
  export type ad = {
package/src/utils.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export function sleep(ms: number): Promise<void> {
2
- return new Promise(resolve => setTimeout(resolve, ms));
2
+ return new Promise((resolve) => setTimeout(resolve, ms));
3
3
  }