@switchbot/homebridge-switchbot 1.9.0 → 1.10.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 (116) hide show
  1. package/.eslintrc +14 -45
  2. package/.github/ISSUE_TEMPLATE/bug-report.yml +3 -3
  3. package/.github/ISSUE_TEMPLATE/feature-request.yml +2 -2
  4. package/.github/ISSUE_TEMPLATE/support-request.yml +3 -3
  5. package/.github/labeler.yml +1 -1
  6. package/.github/workflows/codeql-analysis.yml +29 -29
  7. package/.github/workflows/nodejs-beta.yml +1 -1
  8. package/.github/workflows/prerelease-beta.js +1 -1
  9. package/.github/workflows/stale.yml +1 -1
  10. package/.prettierrc +9 -0
  11. package/.vscode/extensions.json +2 -4
  12. package/.vscode/settings.json +13 -1
  13. package/CHANGELOG.md +16 -0
  14. package/README.md +100 -99
  15. package/SECURITY.md +2 -2
  16. package/config.schema.json +8 -0
  17. package/dist/devices/bots.d.ts +2 -2
  18. package/dist/devices/bots.d.ts.map +1 -1
  19. package/dist/devices/bots.js +91 -86
  20. package/dist/devices/bots.js.map +1 -1
  21. package/dist/devices/colorbulb.d.ts +15 -15
  22. package/dist/devices/colorbulb.d.ts.map +1 -1
  23. package/dist/devices/colorbulb.js +60 -71
  24. package/dist/devices/colorbulb.js.map +1 -1
  25. package/dist/devices/contact.d.ts +2 -2
  26. package/dist/devices/contact.d.ts.map +1 -1
  27. package/dist/devices/contact.js +33 -31
  28. package/dist/devices/contact.js.map +1 -1
  29. package/dist/devices/curtains.d.ts +2 -2
  30. package/dist/devices/curtains.d.ts.map +1 -1
  31. package/dist/devices/curtains.js +71 -71
  32. package/dist/devices/curtains.js.map +1 -1
  33. package/dist/devices/humidifiers.d.ts +2 -2
  34. package/dist/devices/humidifiers.d.ts.map +1 -1
  35. package/dist/devices/humidifiers.js +74 -76
  36. package/dist/devices/humidifiers.js.map +1 -1
  37. package/dist/devices/meters.d.ts +2 -2
  38. package/dist/devices/meters.d.ts.map +1 -1
  39. package/dist/devices/meters.js +29 -27
  40. package/dist/devices/meters.js.map +1 -1
  41. package/dist/devices/motion.d.ts +2 -2
  42. package/dist/devices/motion.d.ts.map +1 -1
  43. package/dist/devices/motion.js +34 -32
  44. package/dist/devices/motion.js.map +1 -1
  45. package/dist/devices/plugs.d.ts +7 -7
  46. package/dist/devices/plugs.d.ts.map +1 -1
  47. package/dist/devices/plugs.js +18 -23
  48. package/dist/devices/plugs.js.map +1 -1
  49. package/dist/irdevices/airconditioners.d.ts +5 -2
  50. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  51. package/dist/irdevices/airconditioners.js +61 -56
  52. package/dist/irdevices/airconditioners.js.map +1 -1
  53. package/dist/irdevices/airpurifiers.d.ts +2 -2
  54. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  55. package/dist/irdevices/airpurifiers.js +12 -17
  56. package/dist/irdevices/airpurifiers.js.map +1 -1
  57. package/dist/irdevices/cameras.d.ts +2 -2
  58. package/dist/irdevices/cameras.d.ts.map +1 -1
  59. package/dist/irdevices/cameras.js +10 -13
  60. package/dist/irdevices/cameras.js.map +1 -1
  61. package/dist/irdevices/fans.d.ts +2 -2
  62. package/dist/irdevices/fans.d.ts.map +1 -1
  63. package/dist/irdevices/fans.js +15 -17
  64. package/dist/irdevices/fans.js.map +1 -1
  65. package/dist/irdevices/lights.d.ts +2 -2
  66. package/dist/irdevices/lights.d.ts.map +1 -1
  67. package/dist/irdevices/lights.js +10 -13
  68. package/dist/irdevices/lights.js.map +1 -1
  69. package/dist/irdevices/others.d.ts +2 -2
  70. package/dist/irdevices/others.d.ts.map +1 -1
  71. package/dist/irdevices/others.js +10 -13
  72. package/dist/irdevices/others.js.map +1 -1
  73. package/dist/irdevices/tvs.d.ts +2 -2
  74. package/dist/irdevices/tvs.d.ts.map +1 -1
  75. package/dist/irdevices/tvs.js +22 -30
  76. package/dist/irdevices/tvs.js.map +1 -1
  77. package/dist/irdevices/vacuumcleaners.d.ts +2 -2
  78. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  79. package/dist/irdevices/vacuumcleaners.js +11 -13
  80. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  81. package/dist/irdevices/waterheaters.d.ts +2 -2
  82. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  83. package/dist/irdevices/waterheaters.js +10 -13
  84. package/dist/irdevices/waterheaters.js.map +1 -1
  85. package/dist/platform.d.ts +3 -3
  86. package/dist/platform.d.ts.map +1 -1
  87. package/dist/platform.js +13 -14
  88. package/dist/platform.js.map +1 -1
  89. package/dist/settings.d.ts +1 -0
  90. package/dist/settings.d.ts.map +1 -1
  91. package/dist/settings.js.map +1 -1
  92. package/homebridge-ui/public/index.html +231 -245
  93. package/homebridge-ui/server.js +2 -4
  94. package/nodemon.json +2 -4
  95. package/package.json +15 -9
  96. package/src/devices/bots.ts +217 -186
  97. package/src/devices/colorbulb.ts +90 -84
  98. package/src/devices/contact.ts +85 -78
  99. package/src/devices/curtains.ts +152 -135
  100. package/src/devices/humidifiers.ts +162 -137
  101. package/src/devices/meters.ts +76 -73
  102. package/src/devices/motion.ts +87 -78
  103. package/src/devices/plugs.ts +27 -31
  104. package/src/irdevices/airconditioners.ts +91 -59
  105. package/src/irdevices/airpurifiers.ts +22 -23
  106. package/src/irdevices/cameras.ts +18 -19
  107. package/src/irdevices/fans.ts +27 -25
  108. package/src/irdevices/lights.ts +18 -20
  109. package/src/irdevices/others.ts +18 -19
  110. package/src/irdevices/tvs.ts +33 -41
  111. package/src/irdevices/vacuumcleaners.ts +19 -19
  112. package/src/irdevices/waterheaters.ts +21 -31
  113. package/src/platform.ts +32 -33
  114. package/src/settings.ts +9 -19
  115. package/tsconfig.json +5 -14
  116. package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
package/src/platform.ts CHANGED
@@ -51,8 +51,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
51
51
 
52
52
  // HOOBS notice
53
53
  if (__dirname.includes('hoobs')) {
54
- this.log.warn('This plugin has not been tested under HOOBS, it is highly recommended that ' +
55
- 'you switch to Homebridge: https://git.io/Jtxb0');
54
+ this.log.warn('This plugin has not been tested under HOOBS, it is highly recommended that you switch to Homebridge: https://git.io/Jtxb0');
56
55
  }
57
56
 
58
57
  // verify the config
@@ -207,8 +206,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
207
206
  }
208
207
 
209
208
  /**
210
- * this method discovers devices
211
- */
209
+ * this method discovers devices
210
+ */
212
211
  async discoverDevices() {
213
212
  try {
214
213
  if (this.config.credentials?.openToken) {
@@ -234,10 +233,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
234
233
  this.debugLog(`SwitchBot Device Config Set: ${JSON.stringify(this.config.options?.devices)}`);
235
234
  const deviceConfigs = this.config.options?.devices;
236
235
 
237
- const mergeBydeviceId = (a1: { deviceId: string; }[], a2: any[]) =>
238
- a1.map((itm: { deviceId: string; }) => ({
239
- ...a2.find((item: { deviceId: string; }) => (
240
- item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '')) && item),
236
+ const mergeBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
237
+ a1.map((itm: { deviceId: string }) => ({
238
+ ...a2.find(
239
+ (item: { deviceId: string }) =>
240
+ item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
241
+ ),
241
242
  ...itm,
242
243
  }));
243
244
 
@@ -269,10 +270,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
269
270
  this.debugLog(`IR Device Config Set: ${JSON.stringify(this.config.options?.irdevices)}`);
270
271
  const irDeviceConfig = this.config.options?.irdevices;
271
272
 
272
- const mergeIRBydeviceId = (a1: { deviceId: string; }[], a2: any[]) =>
273
- a1.map((itm: { deviceId: string; }) => ({
274
- ...a2.find((item: { deviceId: string; }) => (
275
- item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '')) && item),
273
+ const mergeIRBydeviceId = (a1: { deviceId: string }[], a2: any[]) =>
274
+ a1.map((itm: { deviceId: string }) => ({
275
+ ...a2.find(
276
+ (item: { deviceId: string }) =>
277
+ item.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') === itm.deviceId.toUpperCase().replace(/[^A-Z0-9]+/g, '') && item,
278
+ ),
276
279
  ...itm,
277
280
  }));
278
281
 
@@ -324,8 +327,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
324
327
  this.debugLog('The client has defined a contentType header that is not supported by the server.');
325
328
  } else if (e.message.includes('422')) {
326
329
  this.errorLog('Failed to Discover Devices: Unprocessable Entity');
327
- this.debugLog('The client has made a valid request, but the server cannot process it.'
328
- + ' This is often used for APIs for which certain limits have been exceeded.');
330
+ this.debugLog(
331
+ 'The client has made a valid request, but the server cannot process it.' +
332
+ ' This is often used for APIs for which certain limits have been exceeded.',
333
+ );
329
334
  } else if (e.message.includes('429')) {
330
335
  this.errorLog('Failed to Discover Devices: Too Many Requests');
331
336
  this.debugLog('The client has exceeded the number of requests allowed for a given time window.');
@@ -826,8 +831,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
826
831
  }
827
832
 
828
833
  private isCurtainGrouped(device: device & devicesConfig) {
829
- this.debugLog(`deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},`
830
- + ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`);
834
+ this.debugLog(
835
+ `deviceId: ${device.deviceId}, curtainDevicesIds: ${device.curtainDevicesIds},` +
836
+ ` master: ${device.master}, group: ${device.group}, disable_group: ${device.curtain?.disable_group}`,
837
+ );
831
838
 
832
839
  if (device.group && !device.curtain?.disable_group) {
833
840
  this.debugLog(`[Curtain Config] disable_group: ${device.curtain?.disable_group}`);
@@ -991,10 +998,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
991
998
  this.debugLog(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${accessory.UUID})`);
992
999
 
993
1000
  /**
994
- * Publish as external accessory
995
- * Only one TV can exist per bridge, to bypass this limitation, you should
996
- * publish your TV as an external accessory.
997
- */
1001
+ * Publish as external accessory
1002
+ * Only one TV can exist per bridge, to bypass this limitation, you should
1003
+ * publish your TV as an external accessory.
1004
+ */
998
1005
  this.api.publishExternalAccessories(PLUGIN_NAME, [accessory]);
999
1006
  this.accessories.push(accessory);
1000
1007
  } else {
@@ -1443,9 +1450,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1443
1450
  }
1444
1451
  }
1445
1452
 
1446
- public async connectionTypeNewAccessory(
1447
- device: device & devicesConfig,
1448
- accessory: PlatformAccessory) {
1453
+ public async connectionTypeNewAccessory(device: device & devicesConfig, accessory: PlatformAccessory) {
1449
1454
  if (device.ble) {
1450
1455
  accessory.context.connectionType = 'BLE';
1451
1456
  } else {
@@ -1453,10 +1458,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1453
1458
  }
1454
1459
  }
1455
1460
 
1456
- public async connectionTypeExistingAccessory(
1457
- device: device & devicesConfig,
1458
- existingAccessory: PlatformAccessory,
1459
- ) {
1461
+ public async connectionTypeExistingAccessory(device: device & devicesConfig, existingAccessory: PlatformAccessory) {
1460
1462
  if (device.ble) {
1461
1463
  existingAccessory.context.connectionType = 'BLE';
1462
1464
  } else {
@@ -1464,14 +1466,11 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1464
1466
  }
1465
1467
  }
1466
1468
 
1467
- public async connectionTypeNewIRAccessory(
1468
- accessory: PlatformAccessory) {
1469
+ public async connectionTypeNewIRAccessory(accessory: PlatformAccessory) {
1469
1470
  accessory.context.connectionType = 'IR wirth OpenAPI';
1470
1471
  }
1471
1472
 
1472
- public async connectionTypeExistingIRAccessory(
1473
- existingAccessory: PlatformAccessory,
1474
- ) {
1473
+ public async connectionTypeExistingIRAccessory(existingAccessory: PlatformAccessory) {
1475
1474
  existingAccessory.context.connectionType = 'IR with OpenAPI';
1476
1475
  }
1477
1476
 
@@ -1487,7 +1486,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1487
1486
  }
1488
1487
  }
1489
1488
 
1490
- public async deviceInfo(device: irdevice & devicesConfig | device & devicesConfig) {
1489
+ public async deviceInfo(device: (irdevice & devicesConfig) | (device & devicesConfig)) {
1491
1490
  if (this.platformLogging === 'debug') {
1492
1491
  this.warnLog(JSON.stringify(device));
1493
1492
  this.deviceStatus = (await this.axios.get(`${DeviceURL}/${device.deviceId}/status`)).data;
package/src/settings.ts CHANGED
@@ -66,7 +66,7 @@ export type bot = {
66
66
  mode?: string;
67
67
  deviceType?: string;
68
68
  doublePress?: number;
69
- allowPush?: boolean
69
+ allowPush?: boolean;
70
70
  };
71
71
 
72
72
  export type humidifier = {
@@ -147,6 +147,7 @@ export type set_min = {
147
147
 
148
148
  export type irair = {
149
149
  hide_automode?: boolean;
150
+ pushOn?: boolean
150
151
  };
151
152
 
152
153
  export type irtv = {
@@ -285,9 +286,9 @@ export type ad = {
285
286
 
286
287
  export type serviceData = {
287
288
  //Model of BLE SwitchBot Device
288
- model: string,
289
+ model: string;
289
290
  //Model Name of BLE SwitchBot Device
290
- modelName: string
291
+ modelName: string;
291
292
  //Mode for Bot either Press or Switch
292
293
  mode?: boolean;
293
294
  //Bot State
@@ -305,9 +306,9 @@ export type serviceData = {
305
306
  // Fahrenheit enabled for Meter
306
307
  fahrenheit: boolean;
307
308
  // Humidity level for Meter
308
- humidity?: number,
309
+ humidity?: number;
309
310
  //Motion Detected for Contact or Motion Sensors
310
- movement?: boolean,
311
+ movement?: boolean;
311
312
  //Motion ((lightLevel == 1) ? 'dark' : ((lightLevel == 2) ? 'bright' : 'unknown'))
312
313
  //Contact ((lightLevel == 0) ? 'dark' : 'bright')
313
314
  //Curtain (light sensor level (1-10))
@@ -327,18 +328,8 @@ export type temperature = {
327
328
  };
328
329
 
329
330
  export type switchbot = {
330
- discover: (
331
- arg0:
332
- {
333
- duration?: any;
334
- model: string;
335
- quick: boolean;
336
- id?: MacAddress;
337
- }
338
- ) => Promise<any>;
339
- wait: (
340
- arg0: number
341
- ) => any;
331
+ discover: (arg0: { duration?: any; model: string; quick: boolean; id?: MacAddress }) => Promise<any>;
332
+ wait: (arg0: number) => any;
342
333
  };
343
334
 
344
335
  export function rgb2hs(r, g, b) {
@@ -894,5 +885,4 @@ export function m2hs(m) {
894
885
  const input = Math.min(Math.max(Math.round(m), 140), 500);
895
886
  const toReturn = table[input];
896
887
  return [Math.round(toReturn[1]), Math.round(toReturn[0])];
897
-
898
- }
888
+ }
package/tsconfig.json CHANGED
@@ -1,13 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2020",
3
+ "target": "ES2021",
4
4
  "module": "commonjs",
5
- "lib": [
6
- "es2015",
7
- "es2016",
8
- "es2017",
9
- "es2018"
10
- ],
5
+ "lib": ["ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020", "ES2021"],
11
6
  "declaration": true,
12
7
  "declarationMap": true,
13
8
  "sourceMap": true,
@@ -17,10 +12,6 @@
17
12
  "esModuleInterop": true,
18
13
  "noImplicitAny": false
19
14
  },
20
- "include": [
21
- "src/"
22
- ],
23
- "exclude": [
24
- "**/*.spec.ts"
25
- ]
26
- }
15
+ "include": ["src/"],
16
+ "exclude": ["**/*.spec.ts"]
17
+ }
@@ -1,27 +0,0 @@
1
- ---
2
- name: Enhancement
3
- about: Contribute to Plugin through Pull Request
4
- title: ''
5
- labels: 'enhancement'
6
- assignees: 'donavanbecker'
7
- ---
8
-
9
- **Is your enhancement related to a problem? Please describe.**
10
-
11
- <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
12
-
13
- **Describe the solution you are addding**
14
-
15
- <!-- A clear and concise description of what you want to happen. -->
16
-
17
- **Changes Proposed in this Pull Request**
18
-
19
- <!-- A clear and concise description of what is being changed. -->
20
-
21
- **Describe alternatives you've considered**
22
-
23
- <!-- A clear and concise description of any alternative solutions or features you've considered. -->
24
-
25
- **Additional context**
26
-
27
- <!-- Add any other context or screenshots about the feature request here. -->