@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-beta.10

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 (139) hide show
  1. package/.prettierrc +1 -1
  2. package/.vscode/settings.json +1 -1
  3. package/CHANGELOG.md +10 -0
  4. package/config.schema.json +8 -0
  5. package/dist/device/blindtilt.d.ts +1 -0
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +58 -65
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot.d.ts +1 -0
  10. package/dist/device/bot.d.ts.map +1 -1
  11. package/dist/device/bot.js +52 -55
  12. package/dist/device/bot.js.map +1 -1
  13. package/dist/device/ceilinglight.d.ts +1 -0
  14. package/dist/device/ceilinglight.d.ts.map +1 -1
  15. package/dist/device/ceilinglight.js +68 -68
  16. package/dist/device/ceilinglight.js.map +1 -1
  17. package/dist/device/colorbulb.d.ts +1 -0
  18. package/dist/device/colorbulb.d.ts.map +1 -1
  19. package/dist/device/colorbulb.js +76 -75
  20. package/dist/device/colorbulb.js.map +1 -1
  21. package/dist/device/contact.d.ts +2 -0
  22. package/dist/device/contact.d.ts.map +1 -1
  23. package/dist/device/contact.js +67 -59
  24. package/dist/device/contact.js.map +1 -1
  25. package/dist/device/curtain.d.ts +2 -0
  26. package/dist/device/curtain.d.ts.map +1 -1
  27. package/dist/device/curtain.js +81 -94
  28. package/dist/device/curtain.js.map +1 -1
  29. package/dist/device/hub.d.ts +9 -1
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +197 -30
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts.map +1 -1
  34. package/dist/device/humidifier.js +58 -62
  35. package/dist/device/humidifier.js.map +1 -1
  36. package/dist/device/iosensor.d.ts +1 -0
  37. package/dist/device/iosensor.d.ts.map +1 -1
  38. package/dist/device/iosensor.js +28 -26
  39. package/dist/device/iosensor.js.map +1 -1
  40. package/dist/device/lightstrip.d.ts +1 -0
  41. package/dist/device/lightstrip.d.ts.map +1 -1
  42. package/dist/device/lightstrip.js +68 -67
  43. package/dist/device/lightstrip.js.map +1 -1
  44. package/dist/device/lock.d.ts +2 -0
  45. package/dist/device/lock.d.ts.map +1 -1
  46. package/dist/device/lock.js +51 -47
  47. package/dist/device/lock.js.map +1 -1
  48. package/dist/device/meter.d.ts +5 -3
  49. package/dist/device/meter.d.ts.map +1 -1
  50. package/dist/device/meter.js +75 -74
  51. package/dist/device/meter.js.map +1 -1
  52. package/dist/device/meterplus.d.ts +4 -3
  53. package/dist/device/meterplus.d.ts.map +1 -1
  54. package/dist/device/meterplus.js +74 -74
  55. package/dist/device/meterplus.js.map +1 -1
  56. package/dist/device/motion.d.ts +2 -0
  57. package/dist/device/motion.d.ts.map +1 -1
  58. package/dist/device/motion.js +66 -54
  59. package/dist/device/motion.js.map +1 -1
  60. package/dist/device/plug.d.ts +1 -0
  61. package/dist/device/plug.d.ts.map +1 -1
  62. package/dist/device/plug.js +39 -39
  63. package/dist/device/plug.js.map +1 -1
  64. package/dist/device/robotvacuumcleaner.d.ts +1 -0
  65. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  66. package/dist/device/robotvacuumcleaner.js +74 -53
  67. package/dist/device/robotvacuumcleaner.js.map +1 -1
  68. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  69. package/dist/irdevice/airconditioner.js +64 -66
  70. package/dist/irdevice/airconditioner.js.map +1 -1
  71. package/dist/irdevice/airpurifier.d.ts +1 -1
  72. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  73. package/dist/irdevice/airpurifier.js +32 -34
  74. package/dist/irdevice/airpurifier.js.map +1 -1
  75. package/dist/irdevice/camera.d.ts +1 -1
  76. package/dist/irdevice/camera.d.ts.map +1 -1
  77. package/dist/irdevice/camera.js +20 -23
  78. package/dist/irdevice/camera.js.map +1 -1
  79. package/dist/irdevice/fan.d.ts +2 -2
  80. package/dist/irdevice/fan.d.ts.map +1 -1
  81. package/dist/irdevice/fan.js +30 -32
  82. package/dist/irdevice/fan.js.map +1 -1
  83. package/dist/irdevice/light.d.ts +1 -1
  84. package/dist/irdevice/light.d.ts.map +1 -1
  85. package/dist/irdevice/light.js +26 -29
  86. package/dist/irdevice/light.js.map +1 -1
  87. package/dist/irdevice/other.d.ts +1 -1
  88. package/dist/irdevice/other.d.ts.map +1 -1
  89. package/dist/irdevice/other.js +22 -23
  90. package/dist/irdevice/other.js.map +1 -1
  91. package/dist/irdevice/tv.d.ts +2 -2
  92. package/dist/irdevice/tv.d.ts.map +1 -1
  93. package/dist/irdevice/tv.js +47 -50
  94. package/dist/irdevice/tv.js.map +1 -1
  95. package/dist/irdevice/vacuumcleaner.d.ts +1 -1
  96. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  97. package/dist/irdevice/vacuumcleaner.js +20 -23
  98. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  99. package/dist/irdevice/waterheater.d.ts +1 -1
  100. package/dist/irdevice/waterheater.d.ts.map +1 -1
  101. package/dist/irdevice/waterheater.js +22 -23
  102. package/dist/irdevice/waterheater.js.map +1 -1
  103. package/dist/platform.d.ts.map +1 -1
  104. package/dist/platform.js +46 -44
  105. package/dist/platform.js.map +1 -1
  106. package/dist/settings.d.ts +1 -0
  107. package/dist/settings.d.ts.map +1 -1
  108. package/dist/settings.js.map +1 -1
  109. package/dist/utils.js +1 -1
  110. package/dist/utils.js.map +1 -1
  111. package/package.json +3 -3
  112. package/src/device/blindtilt.ts +114 -78
  113. package/src/device/bot.ts +102 -63
  114. package/src/device/ceilinglight.ts +113 -73
  115. package/src/device/colorbulb.ts +144 -87
  116. package/src/device/contact.ts +98 -63
  117. package/src/device/curtain.ts +160 -134
  118. package/src/device/hub.ts +228 -39
  119. package/src/device/humidifier.ts +136 -85
  120. package/src/device/iosensor.ts +52 -32
  121. package/src/device/lightstrip.ts +118 -72
  122. package/src/device/lock.ts +85 -50
  123. package/src/device/meter.ts +104 -80
  124. package/src/device/meterplus.ts +103 -80
  125. package/src/device/motion.ts +95 -59
  126. package/src/device/plug.ts +70 -44
  127. package/src/device/robotvacuumcleaner.ts +107 -56
  128. package/src/irdevice/airconditioner.ts +116 -86
  129. package/src/irdevice/airpurifier.ts +60 -39
  130. package/src/irdevice/camera.ts +40 -28
  131. package/src/irdevice/fan.ts +52 -38
  132. package/src/irdevice/light.ts +48 -34
  133. package/src/irdevice/other.ts +44 -28
  134. package/src/irdevice/tv.ts +70 -56
  135. package/src/irdevice/vacuumcleaner.ts +40 -28
  136. package/src/irdevice/waterheater.ts +48 -32
  137. package/src/platform.ts +87 -56
  138. package/src/settings.ts +41 -40
  139. package/src/utils.ts +1 -1
@@ -1,7 +1,7 @@
1
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
2
  import { request } from 'undici';
2
3
  import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, irdevice, Devices } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { Devices, irDevicesConfig, irdevice } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -21,14 +21,18 @@ export class Others {
21
21
  deviceLogging!: string;
22
22
  otherDeviceType?: string;
23
23
 
24
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
24
+ constructor(
25
+ private readonly platform: SwitchBotPlatform,
26
+ private accessory: PlatformAccessory,
27
+ public device: irdevice & irDevicesConfig,
28
+ ) {
25
29
  // default placeholders
26
30
  this.logs(device);
27
31
  this.deviceType(device);
28
- this.config(device);
29
32
  this.context();
30
33
  this.disablePushOnChanges({ device });
31
34
  this.disablePushOffChanges({ device });
35
+ this.config(device);
32
36
 
33
37
  // set accessory information
34
38
  accessory
@@ -87,16 +91,18 @@ export class Others {
87
91
  * Other - "command" "channelSub" "default" = previous channel
88
92
  */
89
93
  async pushOnChanges(): Promise<void> {
90
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges Active: ${this.Active},`
91
- + ` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`);
94
+ this.debugLog(
95
+ `${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges Active: ${this.Active},` +
96
+ ` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`,
97
+ );
92
98
  if (this.device.customize) {
93
99
  if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
94
100
  const commandType: string = await this.commandType();
95
101
  const command: string = await this.commandOn();
96
102
  const bodyChange = JSON.stringify({
97
- 'command': command,
98
- 'parameter': 'default',
99
- 'commandType': commandType,
103
+ command: command,
104
+ parameter: 'default',
105
+ commandType: commandType,
100
106
  });
101
107
  await this.pushChanges(bodyChange);
102
108
  }
@@ -106,16 +112,18 @@ export class Others {
106
112
  }
107
113
 
108
114
  async pushOffChanges(): Promise<void> {
109
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges Active: ${this.Active},`
110
- + ` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`);
115
+ this.debugLog(
116
+ `${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges Active: ${this.Active},` +
117
+ ` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`,
118
+ );
111
119
  if (this.device.customize) {
112
120
  if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
113
121
  const commandType: string = await this.commandType();
114
122
  const command: string = await this.commandOff();
115
123
  const bodyChange = JSON.stringify({
116
- 'command': command,
117
- 'parameter': 'default',
118
- 'commandType': commandType,
124
+ command: command,
125
+ parameter: 'default',
126
+ commandType: commandType,
119
127
  });
120
128
  await this.pushChanges(bodyChange);
121
129
  }
@@ -127,7 +135,7 @@ export class Others {
127
135
  async pushChanges(bodyChange: any): Promise<void> {
128
136
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
129
137
  if (this.device.connectionType === 'OpenAPI') {
130
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
138
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
131
139
  try {
132
140
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
133
141
  body: bodyChange,
@@ -141,13 +149,16 @@ export class Others {
141
149
  this.updateHomeKitCharacteristics();
142
150
  } catch (e: any) {
143
151
  this.apiError(e);
144
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
145
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
152
+ this.errorLog(
153
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
154
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
146
155
  );
147
156
  }
148
157
  } else {
149
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
150
- + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
158
+ this.warnLog(
159
+ `${this.device.remoteType}: ${this.accessory.displayName}` +
160
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
161
+ );
151
162
  }
152
163
  }
153
164
 
@@ -161,7 +172,7 @@ export class Others {
161
172
  }
162
173
  }
163
174
 
164
- async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
175
+ async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
165
176
  if (device.disablePushOn === undefined) {
166
177
  this.disablePushOn = false;
167
178
  } else {
@@ -169,7 +180,7 @@ export class Others {
169
180
  }
170
181
  }
171
182
 
172
- async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
183
+ async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
173
184
  if (device.disablePushOff === undefined) {
174
185
  this.disablePushOff = false;
175
186
  } else {
@@ -222,8 +233,10 @@ export class Others {
222
233
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
223
234
  break;
224
235
  case 171:
225
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
226
- + `Hub: ${this.device.hubDeviceId}`);
236
+ this.errorLog(
237
+ `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
238
+ `Hub: ${this.device.hubDeviceId}`,
239
+ );
227
240
  break;
228
241
  case 190:
229
242
  this.errorLog(
@@ -238,8 +251,10 @@ export class Others {
238
251
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
239
252
  break;
240
253
  default:
241
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
242
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
254
+ this.infoLog(
255
+ `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
256
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
257
+ );
243
258
  }
244
259
  }
245
260
 
@@ -261,8 +276,9 @@ export class Others {
261
276
 
262
277
  FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
263
278
  let FirmwareRevision: string;
264
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
265
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
279
+ this.debugLog(
280
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
281
+ );
266
282
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
267
283
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
268
284
  if (accessory.context.FirmwareRevision) {
@@ -313,7 +329,7 @@ export class Others {
313
329
  config['disablePushOff'] = device.disablePushOff;
314
330
  }
315
331
  if (Object.entries(config).length !== 0) {
316
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
332
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
317
333
  }
318
334
  }
319
335
 
@@ -1,7 +1,7 @@
1
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
2
  import { request } from 'undici';
2
3
  import { SwitchBotPlatform } from '../platform';
3
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
- import { irdevice, irDevicesConfig, Devices } from '../settings';
4
+ import { Devices, irDevicesConfig, irdevice } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -26,14 +26,18 @@ export class TV {
26
26
  disablePushDetail?: boolean;
27
27
  deviceLogging!: string;
28
28
 
29
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
29
+ constructor(
30
+ private readonly platform: SwitchBotPlatform,
31
+ private accessory: PlatformAccessory,
32
+ public device: irdevice & irDevicesConfig,
33
+ ) {
30
34
  // default placeholders
31
35
  this.logs(device);
32
- this.config(device);
33
36
  this.context();
34
37
  this.disablePushOnChanges({ device });
35
38
  this.disablePushOffChanges({ device });
36
39
  this.disablePushDetailChanges({ device });
40
+ this.config(device);
37
41
 
38
42
  // set accessory information
39
43
  accessory
@@ -222,30 +226,32 @@ export class TV {
222
226
  * TV "command" "channelSub" "default" previous channel
223
227
  */
224
228
  async pushTvOnChanges(): Promise<void> {
225
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushTvOnChanges Active: ${this.Active},`
226
- + ` disablePushOn: ${this.disablePushOn}`);
229
+ this.debugLog(
230
+ `${this.device.remoteType}: ${this.accessory.displayName} pushTvOnChanges Active: ${this.Active},` + ` disablePushOn: ${this.disablePushOn}`,
231
+ );
227
232
  if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
228
233
  const commandType: string = await this.commandType();
229
234
  const command: string = await this.commandOn();
230
235
  const bodyChange = JSON.stringify({
231
- 'command': command,
232
- 'parameter': 'default',
233
- 'commandType': commandType,
236
+ command: command,
237
+ parameter: 'default',
238
+ commandType: commandType,
234
239
  });
235
240
  await this.pushTVChanges(bodyChange);
236
241
  }
237
242
  }
238
243
 
239
244
  async pushTvOffChanges(): Promise<void> {
240
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushTvOffChanges Active: ${this.Active},`
241
- + ` disablePushOff: ${this.disablePushOff}`);
245
+ this.debugLog(
246
+ `${this.device.remoteType}: ${this.accessory.displayName} pushTvOffChanges Active: ${this.Active},` + ` disablePushOff: ${this.disablePushOff}`,
247
+ );
242
248
  if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
243
249
  const commandType: string = await this.commandType();
244
250
  const command: string = await this.commandOff();
245
251
  const bodyChange = JSON.stringify({
246
- 'command': command,
247
- 'parameter': 'default',
248
- 'commandType': commandType,
252
+ command: command,
253
+ parameter: 'default',
254
+ commandType: commandType,
249
255
  });
250
256
  await this.pushTVChanges(bodyChange);
251
257
  }
@@ -255,9 +261,9 @@ export class TV {
255
261
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOkChanges disablePushDetail: ${this.disablePushDetail}`);
256
262
  if (!this.disablePushDetail) {
257
263
  const bodyChange = JSON.stringify({
258
- 'command': 'Ok',
259
- 'parameter': 'default',
260
- 'commandType': 'command',
264
+ command: 'Ok',
265
+ parameter: 'default',
266
+ commandType: 'command',
261
267
  });
262
268
  await this.pushTVChanges(bodyChange);
263
269
  }
@@ -267,9 +273,9 @@ export class TV {
267
273
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushBackChanges disablePushDetail: ${this.disablePushDetail}`);
268
274
  if (!this.disablePushDetail) {
269
275
  const bodyChange = JSON.stringify({
270
- 'command': 'Back',
271
- 'parameter': 'default',
272
- 'commandType': 'command',
276
+ command: 'Back',
277
+ parameter: 'default',
278
+ commandType: 'command',
273
279
  });
274
280
  await this.pushTVChanges(bodyChange);
275
281
  }
@@ -279,9 +285,9 @@ export class TV {
279
285
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushMenuChanges disablePushDetail: ${this.disablePushDetail}`);
280
286
  if (!this.disablePushDetail) {
281
287
  const bodyChange = JSON.stringify({
282
- 'command': 'Menu',
283
- 'parameter': 'default',
284
- 'commandType': 'command',
288
+ command: 'Menu',
289
+ parameter: 'default',
290
+ commandType: 'command',
285
291
  });
286
292
  await this.pushTVChanges(bodyChange);
287
293
  }
@@ -291,9 +297,9 @@ export class TV {
291
297
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushUpChanges disablePushDetail: ${this.disablePushDetail}`);
292
298
  if (!this.disablePushDetail) {
293
299
  const bodyChange = JSON.stringify({
294
- 'command': 'Up',
295
- 'parameter': 'default',
296
- 'commandType': 'command',
300
+ command: 'Up',
301
+ parameter: 'default',
302
+ commandType: 'command',
297
303
  });
298
304
  await this.pushTVChanges(bodyChange);
299
305
  }
@@ -303,9 +309,9 @@ export class TV {
303
309
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushDownChanges disablePushDetail: ${this.disablePushDetail}`);
304
310
  if (!this.disablePushDetail) {
305
311
  const bodyChange = JSON.stringify({
306
- 'command': 'Down',
307
- 'parameter': 'default',
308
- 'commandType': 'command',
312
+ command: 'Down',
313
+ parameter: 'default',
314
+ commandType: 'command',
309
315
  });
310
316
  await this.pushTVChanges(bodyChange);
311
317
  }
@@ -315,9 +321,9 @@ export class TV {
315
321
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushRightChanges disablePushDetail: ${this.disablePushDetail}`);
316
322
  if (!this.disablePushDetail) {
317
323
  const bodyChange = JSON.stringify({
318
- 'command': 'Right',
319
- 'parameter': 'default',
320
- 'commandType': 'command',
324
+ command: 'Right',
325
+ parameter: 'default',
326
+ commandType: 'command',
321
327
  });
322
328
  await this.pushTVChanges(bodyChange);
323
329
  }
@@ -327,9 +333,9 @@ export class TV {
327
333
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLeftChanges disablePushDetail: ${this.disablePushDetail}`);
328
334
  if (!this.disablePushDetail) {
329
335
  const bodyChange = JSON.stringify({
330
- 'command': 'Left',
331
- 'parameter': 'default',
332
- 'commandType': 'command',
336
+ command: 'Left',
337
+ parameter: 'default',
338
+ commandType: 'command',
333
339
  });
334
340
  await this.pushTVChanges(bodyChange);
335
341
  }
@@ -339,9 +345,9 @@ export class TV {
339
345
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushVolumeUpChanges disablePushDetail: ${this.disablePushDetail}`);
340
346
  if (!this.disablePushDetail) {
341
347
  const bodyChange = JSON.stringify({
342
- 'command': 'volumeAdd',
343
- 'parameter': 'default',
344
- 'commandType': 'command',
348
+ command: 'volumeAdd',
349
+ parameter: 'default',
350
+ commandType: 'command',
345
351
  });
346
352
  await this.pushTVChanges(bodyChange);
347
353
  }
@@ -351,9 +357,9 @@ export class TV {
351
357
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushVolumeDownChanges disablePushDetail: ${this.disablePushDetail}`);
352
358
  if (!this.disablePushDetail) {
353
359
  const bodyChange = JSON.stringify({
354
- 'command': 'volumeSub',
355
- 'parameter': 'default',
356
- 'commandType': 'command',
360
+ command: 'volumeSub',
361
+ parameter: 'default',
362
+ commandType: 'command',
357
363
  });
358
364
  await this.pushTVChanges(bodyChange);
359
365
  }
@@ -362,7 +368,7 @@ export class TV {
362
368
  async pushTVChanges(bodyChange: any): Promise<void> {
363
369
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushTVChanges`);
364
370
  if (this.device.connectionType === 'OpenAPI') {
365
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
371
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
366
372
  try {
367
373
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
368
374
  body: bodyChange,
@@ -376,13 +382,16 @@ export class TV {
376
382
  this.updateHomeKitCharacteristics();
377
383
  } catch (e: any) {
378
384
  this.apiError(e);
379
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushTVChanges with ${this.device.connectionType}`
380
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
385
+ this.errorLog(
386
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushTVChanges with ${this.device.connectionType}` +
387
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
381
388
  );
382
389
  }
383
390
  } else {
384
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
385
- + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
391
+ this.warnLog(
392
+ `${this.device.remoteType}: ${this.accessory.displayName}` +
393
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
394
+ );
386
395
  }
387
396
  }
388
397
 
@@ -403,7 +412,7 @@ export class TV {
403
412
  }
404
413
  }
405
414
 
406
- async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
415
+ async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
407
416
  if (device.disablePushOn === undefined) {
408
417
  this.disablePushOn = false;
409
418
  } else {
@@ -411,7 +420,7 @@ export class TV {
411
420
  }
412
421
  }
413
422
 
414
- async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
423
+ async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
415
424
  if (device.disablePushOff === undefined) {
416
425
  this.disablePushOff = false;
417
426
  } else {
@@ -419,7 +428,7 @@ export class TV {
419
428
  }
420
429
  }
421
430
 
422
- async disablePushDetailChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
431
+ async disablePushDetailChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
423
432
  if (device.disablePushDetail === undefined) {
424
433
  this.disablePushDetail = false;
425
434
  } else {
@@ -472,8 +481,10 @@ export class TV {
472
481
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
473
482
  break;
474
483
  case 171:
475
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
476
- + `Hub: ${this.device.hubDeviceId}`);
484
+ this.errorLog(
485
+ `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
486
+ `Hub: ${this.device.hubDeviceId}`,
487
+ );
477
488
  break;
478
489
  case 190:
479
490
  this.errorLog(
@@ -488,8 +499,10 @@ export class TV {
488
499
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
489
500
  break;
490
501
  default:
491
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
492
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
502
+ this.infoLog(
503
+ `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
504
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
505
+ );
493
506
  }
494
507
  }
495
508
 
@@ -500,8 +513,9 @@ export class TV {
500
513
 
501
514
  FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
502
515
  let FirmwareRevision: string;
503
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
504
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
516
+ this.debugLog(
517
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
518
+ );
505
519
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
506
520
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
507
521
  if (accessory.context.FirmwareRevision) {
@@ -560,7 +574,7 @@ export class TV {
560
574
  config['disablePushDetail'] = device.disablePushDetail;
561
575
  }
562
576
  if (Object.entries(config).length !== 0) {
563
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
577
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
564
578
  }
565
579
  }
566
580
 
@@ -1,7 +1,7 @@
1
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
2
  import { request } from 'undici';
2
3
  import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, irdevice, Devices } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { Devices, irDevicesConfig, irdevice } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -20,13 +20,17 @@ export class VacuumCleaner {
20
20
  disablePushOff?: boolean;
21
21
  deviceLogging!: string;
22
22
 
23
- constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
23
+ constructor(
24
+ private readonly platform: SwitchBotPlatform,
25
+ private accessory: PlatformAccessory,
26
+ public device: irdevice & irDevicesConfig,
27
+ ) {
24
28
  // default placeholders
25
29
  this.logs(device);
26
- this.config(device);
27
30
  this.context();
28
31
  this.disablePushOnChanges({ device });
29
32
  this.disablePushOffChanges({ device });
33
+ this.config(device);
30
34
 
31
35
  // set accessory information
32
36
  accessory
@@ -76,30 +80,30 @@ export class VacuumCleaner {
76
80
  * Vacuum Cleaner "command" "turnOn" "default" set to ON state
77
81
  */
78
82
  async pushOnChanges(): Promise<void> {
79
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.On},`
80
- + ` disablePushOn: ${this.disablePushOn}`);
83
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.On},` + ` disablePushOn: ${this.disablePushOn}`);
81
84
  if (this.On && !this.disablePushOn) {
82
85
  const commandType: string = await this.commandType();
83
86
  const command: string = await this.commandOn();
84
87
  const bodyChange = JSON.stringify({
85
- 'command': command,
86
- 'parameter': 'default',
87
- 'commandType': commandType,
88
+ command: command,
89
+ parameter: 'default',
90
+ commandType: commandType,
88
91
  });
89
92
  await this.pushChanges(bodyChange);
90
93
  }
91
94
  }
92
95
 
93
96
  async pushOffChanges(): Promise<void> {
94
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${this.On},`
95
- + ` disablePushOff: ${this.disablePushOff}`);
97
+ this.debugLog(
98
+ `${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${this.On},` + ` disablePushOff: ${this.disablePushOff}`,
99
+ );
96
100
  if (!this.On && !this.disablePushOff) {
97
101
  const commandType: string = await this.commandType();
98
102
  const command: string = await this.commandOff();
99
103
  const bodyChange = JSON.stringify({
100
- 'command': command,
101
- 'parameter': 'default',
102
- 'commandType': commandType,
104
+ command: command,
105
+ parameter: 'default',
106
+ commandType: commandType,
103
107
  });
104
108
  await this.pushChanges(bodyChange);
105
109
  }
@@ -108,7 +112,7 @@ export class VacuumCleaner {
108
112
  async pushChanges(bodyChange: any): Promise<void> {
109
113
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
110
114
  if (this.device.connectionType === 'OpenAPI') {
111
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
115
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
112
116
  try {
113
117
  const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
114
118
  body: bodyChange,
@@ -122,13 +126,16 @@ export class VacuumCleaner {
122
126
  this.updateHomeKitCharacteristics();
123
127
  } catch (e: any) {
124
128
  this.apiError(e);
125
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
126
- + ` Connection, Error Message: ${JSON.stringify(e.message)}`,
129
+ this.errorLog(
130
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
131
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
127
132
  );
128
133
  }
129
134
  } else {
130
- this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
131
- + ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
135
+ this.warnLog(
136
+ `${this.device.remoteType}: ${this.accessory.displayName}` +
137
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
138
+ );
132
139
  }
133
140
  }
134
141
 
@@ -142,7 +149,7 @@ export class VacuumCleaner {
142
149
  }
143
150
  }
144
151
 
145
- async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
152
+ async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
146
153
  if (device.disablePushOn === undefined) {
147
154
  this.disablePushOn = false;
148
155
  } else {
@@ -150,7 +157,7 @@ export class VacuumCleaner {
150
157
  }
151
158
  }
152
159
 
153
- async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
160
+ async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
154
161
  if (device.disablePushOff === undefined) {
155
162
  this.disablePushOff = false;
156
163
  } else {
@@ -203,8 +210,10 @@ export class VacuumCleaner {
203
210
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
204
211
  break;
205
212
  case 171:
206
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
207
- + `Hub: ${this.device.hubDeviceId}`);
213
+ this.errorLog(
214
+ `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
215
+ `Hub: ${this.device.hubDeviceId}`,
216
+ );
208
217
  break;
209
218
  case 190:
210
219
  this.errorLog(
@@ -219,8 +228,10 @@ export class VacuumCleaner {
219
228
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
220
229
  break;
221
230
  default:
222
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
223
- + `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
231
+ this.infoLog(
232
+ `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
233
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
234
+ );
224
235
  }
225
236
  }
226
237
 
@@ -230,8 +241,9 @@ export class VacuumCleaner {
230
241
 
231
242
  FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
232
243
  let FirmwareRevision: string;
233
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
234
- + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
244
+ this.debugLog(
245
+ `${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
246
+ );
235
247
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
236
248
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
237
249
  if (accessory.context.FirmwareRevision) {
@@ -282,7 +294,7 @@ export class VacuumCleaner {
282
294
  config['disablePushOff'] = device.disablePushOff;
283
295
  }
284
296
  if (Object.entries(config).length !== 0) {
285
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
297
+ this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
286
298
  }
287
299
  }
288
300