@switchbot/homebridge-switchbot 3.5.0-beta.57 → 3.5.0-beta.59

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 (164) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/dist/device/blindtilt.d.ts +5 -5
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +103 -69
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +4 -4
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +201 -154
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +3 -3
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +41 -36
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +3 -3
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +36 -37
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +4 -4
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +76 -55
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +4 -4
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +99 -55
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +4 -4
  27. package/dist/device/device.d.ts.map +1 -1
  28. package/dist/device/device.js +11 -9
  29. package/dist/device/device.js.map +1 -1
  30. package/dist/device/fan.d.ts +3 -3
  31. package/dist/device/fan.d.ts.map +1 -1
  32. package/dist/device/fan.js +54 -24
  33. package/dist/device/fan.js.map +1 -1
  34. package/dist/device/hub.d.ts +4 -4
  35. package/dist/device/hub.d.ts.map +1 -1
  36. package/dist/device/hub.js +40 -57
  37. package/dist/device/hub.js.map +1 -1
  38. package/dist/device/humidifier.d.ts +3 -3
  39. package/dist/device/humidifier.d.ts.map +1 -1
  40. package/dist/device/humidifier.js +39 -39
  41. package/dist/device/humidifier.js.map +1 -1
  42. package/dist/device/iosensor.d.ts +3 -3
  43. package/dist/device/iosensor.d.ts.map +1 -1
  44. package/dist/device/iosensor.js +41 -50
  45. package/dist/device/iosensor.js.map +1 -1
  46. package/dist/device/lightstrip.d.ts +4 -4
  47. package/dist/device/lightstrip.d.ts.map +1 -1
  48. package/dist/device/lightstrip.js +36 -33
  49. package/dist/device/lightstrip.js.map +1 -1
  50. package/dist/device/lock.d.ts +3 -3
  51. package/dist/device/lock.d.ts.map +1 -1
  52. package/dist/device/lock.js +68 -59
  53. package/dist/device/lock.js.map +1 -1
  54. package/dist/device/meter.d.ts +3 -3
  55. package/dist/device/meter.d.ts.map +1 -1
  56. package/dist/device/meter.js +42 -51
  57. package/dist/device/meter.js.map +1 -1
  58. package/dist/device/meterplus.d.ts +3 -3
  59. package/dist/device/meterplus.d.ts.map +1 -1
  60. package/dist/device/meterplus.js +42 -51
  61. package/dist/device/meterplus.js.map +1 -1
  62. package/dist/device/motion.d.ts +3 -3
  63. package/dist/device/motion.d.ts.map +1 -1
  64. package/dist/device/motion.js +52 -40
  65. package/dist/device/motion.js.map +1 -1
  66. package/dist/device/plug.d.ts +3 -3
  67. package/dist/device/plug.d.ts.map +1 -1
  68. package/dist/device/plug.js +13 -13
  69. package/dist/device/plug.js.map +1 -1
  70. package/dist/device/robotvacuumcleaner.d.ts +4 -4
  71. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  72. package/dist/device/robotvacuumcleaner.js +81 -98
  73. package/dist/device/robotvacuumcleaner.js.map +1 -1
  74. package/dist/device/waterdetector.d.ts +3 -3
  75. package/dist/device/waterdetector.d.ts.map +1 -1
  76. package/dist/device/waterdetector.js +39 -31
  77. package/dist/device/waterdetector.js.map +1 -1
  78. package/dist/homebridge-ui/public/index.html +20 -14
  79. package/dist/index.d.ts +1 -1
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +1 -1
  82. package/dist/index.js.map +1 -1
  83. package/dist/irdevice/airconditioner.d.ts +3 -3
  84. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  85. package/dist/irdevice/airconditioner.js +9 -9
  86. package/dist/irdevice/airconditioner.js.map +1 -1
  87. package/dist/irdevice/airpurifier.d.ts +3 -3
  88. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  89. package/dist/irdevice/airpurifier.js +1 -1
  90. package/dist/irdevice/airpurifier.js.map +1 -1
  91. package/dist/irdevice/camera.d.ts +3 -3
  92. package/dist/irdevice/camera.d.ts.map +1 -1
  93. package/dist/irdevice/camera.js +2 -2
  94. package/dist/irdevice/camera.js.map +1 -1
  95. package/dist/irdevice/fan.d.ts +6 -6
  96. package/dist/irdevice/fan.d.ts.map +1 -1
  97. package/dist/irdevice/fan.js +37 -29
  98. package/dist/irdevice/fan.js.map +1 -1
  99. package/dist/irdevice/irdevice.d.ts +3 -3
  100. package/dist/irdevice/irdevice.d.ts.map +1 -1
  101. package/dist/irdevice/irdevice.js.map +1 -1
  102. package/dist/irdevice/light.d.ts +9 -14
  103. package/dist/irdevice/light.d.ts.map +1 -1
  104. package/dist/irdevice/light.js +67 -88
  105. package/dist/irdevice/light.js.map +1 -1
  106. package/dist/irdevice/other.d.ts +3 -3
  107. package/dist/irdevice/other.d.ts.map +1 -1
  108. package/dist/irdevice/other.js +1 -1
  109. package/dist/irdevice/other.js.map +1 -1
  110. package/dist/irdevice/tv.d.ts +3 -3
  111. package/dist/irdevice/tv.d.ts.map +1 -1
  112. package/dist/irdevice/tv.js +3 -3
  113. package/dist/irdevice/tv.js.map +1 -1
  114. package/dist/irdevice/vacuumcleaner.d.ts +3 -3
  115. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  116. package/dist/irdevice/vacuumcleaner.js +2 -2
  117. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  118. package/dist/irdevice/waterheater.d.ts +3 -3
  119. package/dist/irdevice/waterheater.d.ts.map +1 -1
  120. package/dist/irdevice/waterheater.js +2 -2
  121. package/dist/irdevice/waterheater.js.map +1 -1
  122. package/dist/platform.d.ts +7 -7
  123. package/dist/platform.d.ts.map +1 -1
  124. package/dist/platform.js +20 -23
  125. package/dist/platform.js.map +1 -1
  126. package/dist/settings.d.ts +24 -10
  127. package/dist/settings.d.ts.map +1 -1
  128. package/dist/settings.js +16 -0
  129. package/dist/settings.js.map +1 -1
  130. package/eslint.config.js +89 -78
  131. package/package.json +3 -3
  132. package/src/device/blindtilt.ts +120 -87
  133. package/src/device/bot.ts +238 -175
  134. package/src/device/ceilinglight.ts +49 -46
  135. package/src/device/colorbulb.ts +40 -43
  136. package/src/device/contact.ts +91 -65
  137. package/src/device/curtain.ts +113 -66
  138. package/src/device/device.ts +12 -13
  139. package/src/device/fan.ts +66 -29
  140. package/src/device/hub.ts +53 -60
  141. package/src/device/humidifier.ts +54 -56
  142. package/src/device/iosensor.ts +57 -56
  143. package/src/device/lightstrip.ts +43 -39
  144. package/src/device/lock.ts +79 -68
  145. package/src/device/meter.ts +54 -54
  146. package/src/device/meterplus.ts +54 -54
  147. package/src/device/motion.ts +62 -46
  148. package/src/device/plug.ts +19 -18
  149. package/src/device/robotvacuumcleaner.ts +89 -104
  150. package/src/device/waterdetector.ts +46 -34
  151. package/src/homebridge-ui/public/index.html +20 -14
  152. package/src/index.ts +3 -2
  153. package/src/irdevice/airconditioner.ts +13 -11
  154. package/src/irdevice/airpurifier.ts +5 -3
  155. package/src/irdevice/camera.ts +6 -4
  156. package/src/irdevice/fan.ts +42 -29
  157. package/src/irdevice/irdevice.ts +4 -5
  158. package/src/irdevice/light.ts +83 -103
  159. package/src/irdevice/other.ts +5 -3
  160. package/src/irdevice/tv.ts +7 -5
  161. package/src/irdevice/vacuumcleaner.ts +6 -4
  162. package/src/irdevice/waterheater.ts +6 -4
  163. package/src/platform.ts +59 -66
  164. package/src/settings.ts +73 -58
package/dist/platform.js CHANGED
@@ -1,19 +1,22 @@
1
- import { PLATFORM_NAME, PLUGIN_NAME, Devices } from './settings.js';
1
+ /* Copyright(C) 2017-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * platform.ts: @switchbot/homebridge-switchbot platform class.
4
+ */
5
+ import { Hub } from './device/hub.js';
2
6
  import { Bot } from './device/bot.js';
3
7
  import { Plug } from './device/plug.js';
4
8
  import { Lock } from './device/lock.js';
5
9
  import { Meter } from './device/meter.js';
6
10
  import { Motion } from './device/motion.js';
7
- import { Hub } from './device/hub.js';
8
11
  import { Contact } from './device/contact.js';
9
12
  import { Curtain } from './device/curtain.js';
10
13
  import { IOSensor } from './device/iosensor.js';
11
- import { WaterDetector } from './device/waterdetector.js';
12
14
  import { MeterPlus } from './device/meterplus.js';
13
15
  import { ColorBulb } from './device/colorbulb.js';
14
- import { CeilingLight } from './device/ceilinglight.js';
15
16
  import { StripLight } from './device/lightstrip.js';
16
17
  import { Humidifier } from './device/humidifier.js';
18
+ import { CeilingLight } from './device/ceilinglight.js';
19
+ import { WaterDetector } from './device/waterdetector.js';
17
20
  import { RobotVacuumCleaner } from './device/robotvacuumcleaner.js';
18
21
  import { Fan } from './device/fan.js';
19
22
  import { TV } from './irdevice/tv.js';
@@ -26,16 +29,17 @@ import { AirPurifier } from './irdevice/airpurifier.js';
26
29
  import { WaterHeater } from './irdevice/waterheater.js';
27
30
  import { VacuumCleaner } from './irdevice/vacuumcleaner.js';
28
31
  import { AirConditioner } from './irdevice/airconditioner.js';
29
- import * as http from 'http';
30
32
  import { Buffer } from 'buffer';
31
33
  import { request } from 'undici';
34
+ import asyncmqtt from 'async-mqtt';
35
+ import { sleep } from './utils.js';
36
+ import { createServer } from 'http';
32
37
  import { queueScheduler } from 'rxjs';
33
38
  import fakegato from 'fakegato-history';
34
- import asyncmqtt from 'async-mqtt';
35
39
  import crypto, { randomUUID } from 'crypto';
36
40
  import { readFileSync, writeFileSync } from 'fs';
37
41
  import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
38
- import { sleep } from './utils.js';
42
+ import { PLATFORM_NAME, PLUGIN_NAME, Devices, setupWebhook, updateWebhook, deleteWebhook, queryWebhook } from './settings.js';
39
43
  /**
40
44
  * HomebridgePlatform
41
45
  * This class is the main constructor for your plugin, this is where you should
@@ -103,7 +107,6 @@ export class SwitchBotPlatform {
103
107
  await this.updateToken();
104
108
  }
105
109
  else if (this.config.credentials?.token && !this.config.credentials?.secret) {
106
- // eslint-disable-next-line no-useless-escape
107
110
  this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.');
108
111
  }
109
112
  else {
@@ -157,7 +160,7 @@ export class SwitchBotPlatform {
157
160
  const xurl = new URL(url);
158
161
  const port = Number(xurl.port);
159
162
  const path = xurl.pathname;
160
- this.webhookEventListener = http.createServer((request, response) => {
163
+ this.webhookEventListener = createServer((request, response) => {
161
164
  try {
162
165
  if (request.url === path && request.method === 'POST') {
163
166
  request.on('data', async (data) => {
@@ -196,7 +199,7 @@ export class SwitchBotPlatform {
196
199
  return;
197
200
  }
198
201
  try {
199
- const { body, statusCode } = await request('https://api.switch-bot.com/v1.1/webhook/setupWebhook', {
202
+ const { body, statusCode } = await request(setupWebhook, {
200
203
  method: 'POST',
201
204
  headers: this.generateHeaders(),
202
205
  body: JSON.stringify({
@@ -218,10 +221,8 @@ export class SwitchBotPlatform {
218
221
  this.errorLog(`Failed to configure webhook. Error: ${e.message}`);
219
222
  }
220
223
  try {
221
- const { body, statusCode } = await request('https://api.switch-bot.com/v1.1/webhook/updateWebhook', {
222
- method: 'POST',
223
- headers: this.generateHeaders(),
224
- body: JSON.stringify({
224
+ const { body, statusCode } = await request(updateWebhook, {
225
+ method: 'POST', headers: this.generateHeaders(), body: JSON.stringify({
225
226
  'action': 'updateWebhook',
226
227
  'config': {
227
228
  'url': url,
@@ -241,7 +242,7 @@ export class SwitchBotPlatform {
241
242
  this.errorLog(`Failed to update webhook. Error:${e.message}`);
242
243
  }
243
244
  try {
244
- const { body, statusCode } = await request('https://api.switch-bot.com/v1.1/webhook/queryWebhook', {
245
+ const { body, statusCode } = await request(queryWebhook, {
245
246
  method: 'POST',
246
247
  headers: this.generateHeaders(),
247
248
  body: JSON.stringify({
@@ -263,7 +264,7 @@ export class SwitchBotPlatform {
263
264
  }
264
265
  this.api.on('shutdown', async () => {
265
266
  try {
266
- const { body, statusCode } = await request('https://api.switch-bot.com/v1.1/webhook/deleteWebhook', {
267
+ const { body, statusCode } = await request(deleteWebhook, {
267
268
  method: 'POST',
268
269
  headers: this.generateHeaders(),
269
270
  body: JSON.stringify({
@@ -417,13 +418,11 @@ export class SwitchBotPlatform {
417
418
  }
418
419
  // Move openToken to token
419
420
  if (!this.config.credentials.secret) {
420
- // eslint-disable-next-line no-useless-escape, max-len
421
- 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');
422
- // eslint-disable-next-line no-useless-escape
421
+ this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken,'
422
+ + ' "openToken" cconfig has been moved to the "token" config');
423
423
  this.errorLog('"secret" config is not populated, you must populate then please restart Homebridge.');
424
424
  }
425
425
  else {
426
- // eslint-disable-next-line no-useless-escape, max-len
427
426
  this.warnLog('This plugin has been updated to use OpenAPI v1.1, config is set with openToken, '
428
427
  + '"openToken" config has been moved to the "token" config, please restart Homebridge.');
429
428
  }
@@ -709,9 +708,7 @@ export class SwitchBotPlatform {
709
708
  this.createFan(device);
710
709
  break;
711
710
  default:
712
- this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`);
713
- // eslint-disable-next-line max-len
714
- this.warnLog('Submit Feature Requests Here: ' + 'https://tinyurl.com/SwitchBotFeatureRequest');
711
+ this.warnLog(`Device: ${device.deviceName} with Device Type: ${device.deviceType}, is currently not supported.`, +'Submit Feature Requests Here: https://tinyurl.com/SwitchBotFeatureRequest');
715
712
  }
716
713
  }
717
714
  createIRDevice(device) {