@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
@@ -19,11 +19,7 @@ export class Light {
19
19
  // Config
20
20
  deviceLogging!: string;
21
21
 
22
- constructor(
23
- private readonly platform: SwitchBotPlatform,
24
- private accessory: PlatformAccessory,
25
- public device: irdevice & irDevicesConfig,
26
- ) {
22
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
27
23
  // default placeholders
28
24
  this.logs(device);
29
25
  this.config(device);
@@ -42,9 +38,8 @@ export class Light {
42
38
 
43
39
  // get the Television service if it exists, otherwise create a new Television service
44
40
  // you can create multiple services for each accessory
45
- (this.service =
46
- accessory.getService(this.platform.Service.Lightbulb) ||
47
- accessory.addService(this.platform.Service.Lightbulb)), `${accessory.displayName} Light Bulb`;
41
+ (this.service = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
42
+ `${accessory.displayName} Light Bulb`;
48
43
 
49
44
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
50
45
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -144,8 +139,10 @@ export class Light {
144
139
 
145
140
  public async pushChanges(payload: payload) {
146
141
  try {
147
- this.infoLog(`Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
148
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
142
+ this.infoLog(
143
+ `Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
144
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
145
+ );
149
146
 
150
147
  // Make the API request
151
148
  const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
@@ -157,19 +154,18 @@ export class Light {
157
154
  } catch (e: any) {
158
155
  this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
159
156
  if (this.deviceLogging === 'debug') {
160
- this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
161
- + ` Error Message: ${JSON.stringify(e.message)}`);
157
+ this.errorLog(
158
+ `Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
159
+ );
162
160
  }
163
161
  if (this.platform.debugMode) {
164
- this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
165
- + ` Error: ${JSON.stringify(e)}`);
162
+ this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
166
163
  }
167
164
  this.apiError(e);
168
165
  }
169
166
  }
170
167
 
171
-
172
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
168
+ private statusCode(push: AxiosResponse<{ statusCode: number }>) {
173
169
  switch (push.data.statusCode) {
174
170
  case 151:
175
171
  this.errorLog(`Light: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -187,8 +183,10 @@ export class Light {
187
183
  this.errorLog(`Light: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
188
184
  break;
189
185
  case 190:
190
- this.errorLog(`Light: ${this.accessory.displayName} Device internal error due to device states not synchronized`
191
- + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
186
+ this.errorLog(
187
+ `Light: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
188
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
189
+ );
192
190
  break;
193
191
  case 100:
194
192
  this.debugLog(`Light: ${this.accessory.displayName} Command successfully sent.`);
@@ -233,8 +231,8 @@ export class Light {
233
231
  }
234
232
 
235
233
  /**
236
- * Logging for Device
237
- */
234
+ * Logging for Device
235
+ */
238
236
  infoLog(...log: any[]) {
239
237
  if (this.enablingDeviceLogging()) {
240
238
  this.platform.log.info(String(...log));
@@ -20,11 +20,7 @@ export class Others {
20
20
  deviceLogging!: string;
21
21
  otherDeviceType?: string;
22
22
 
23
- constructor(
24
- private readonly platform: SwitchBotPlatform,
25
- private accessory: PlatformAccessory,
26
- public device: irdevice & irDevicesConfig,
27
- ) {
23
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
28
24
  // default placeholders
29
25
  this.logs(device);
30
26
  this.deviceType(device);
@@ -54,9 +50,8 @@ export class Others {
54
50
  accessory.removeService(this.service!);
55
51
  } else if (!this.service && this.otherDeviceType === 'Fan') {
56
52
  this.debugLog(`Other: ${accessory.displayName} Add Fanv2 Service`);
57
- (this.service =
58
- this.accessory.getService(this.platform.Service.Fanv2) ||
59
- this.accessory.addService(this.platform.Service.Fanv2)), `${accessory.displayName} Fan`;
53
+ (this.service = this.accessory.getService(this.platform.Service.Fanv2) || this.accessory.addService(this.platform.Service.Fanv2)),
54
+ `${accessory.displayName} Fan`;
60
55
 
61
56
  this.service.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Fan`);
62
57
 
@@ -145,8 +140,10 @@ export class Others {
145
140
 
146
141
  public async pushChanges(payload: payload) {
147
142
  try {
148
- this.infoLog(`Other: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
149
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
143
+ this.infoLog(
144
+ `Other: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
145
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
146
+ );
150
147
 
151
148
  // Make the API request
152
149
  const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
@@ -156,18 +153,18 @@ export class Others {
156
153
  } catch (e: any) {
157
154
  this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
158
155
  if (this.deviceLogging === 'debug') {
159
- this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
160
- + ` Error Message: ${JSON.stringify(e.message)}`);
156
+ this.errorLog(
157
+ `Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
158
+ );
161
159
  }
162
160
  if (this.platform.debugMode) {
163
- this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
164
- + ` Error: ${JSON.stringify(e)}`);
161
+ this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
165
162
  }
166
163
  this.apiError(e);
167
164
  }
168
165
  }
169
166
 
170
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
167
+ private statusCode(push: AxiosResponse<{ statusCode: number }>) {
171
168
  switch (push.data.statusCode) {
172
169
  case 151:
173
170
  this.errorLog(`Other: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -185,8 +182,10 @@ export class Others {
185
182
  this.errorLog(`Other: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
186
183
  break;
187
184
  case 190:
188
- this.errorLog(`Other: ${this.accessory.displayName} Device internal error due to device states not synchronized`
189
- + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
185
+ this.errorLog(
186
+ `Other: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
187
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
188
+ );
190
189
  break;
191
190
  case 100:
192
191
  this.debugLog(`Other: ${this.accessory.displayName} Command successfully sent.`);
@@ -242,8 +241,8 @@ export class Others {
242
241
  }
243
242
 
244
243
  /**
245
- * Logging for Device
246
- */
244
+ * Logging for Device
245
+ */
247
246
  infoLog(...log: any[]) {
248
247
  if (this.enablingDeviceLogging()) {
249
248
  this.platform.log.info(String(...log));
@@ -24,11 +24,7 @@ export class TV {
24
24
  // Config
25
25
  deviceLogging!: string;
26
26
 
27
- constructor(
28
- private readonly platform: SwitchBotPlatform,
29
- private accessory: PlatformAccessory,
30
- public device: irdevice & irDevicesConfig,
31
- ) {
27
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
32
28
  // default placeholders
33
29
  this.logs(device);
34
30
  this.config(device);
@@ -51,34 +47,30 @@ export class TV {
51
47
  case 'Speaker':
52
48
  case 'DIY Speaker':
53
49
  accessory.category = this.platform.api.hap.Categories.SPEAKER;
54
- (this.service =
55
- accessory.getService(this.platform.Service.Television) ||
56
- accessory.addService(this.platform.Service.Television)), `${accessory.displayName} Speaker`;
50
+ (this.service = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)),
51
+ `${accessory.displayName} Speaker`;
57
52
  break;
58
53
  case 'IPTV':
59
54
  case 'DIY IPTV':
60
55
  accessory.category = this.platform.api.hap.Categories.TV_STREAMING_STICK;
61
- (this.service =
62
- accessory.getService(this.platform.Service.Television) ||
63
- accessory.addService(this.platform.Service.Television)), `${accessory.displayName} Streaming Stick`;
56
+ (this.service = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)),
57
+ `${accessory.displayName} Streaming Stick`;
64
58
  break;
65
59
  case 'DVD':
66
60
  case 'DIY DVD':
67
61
  case 'Set Top Box':
68
62
  case 'DIY Set Top Box':
69
63
  accessory.category = this.platform.api.hap.Categories.TV_SET_TOP_BOX;
70
- (this.service =
71
- accessory.getService(this.platform.Service.Television) ||
72
- accessory.addService(this.platform.Service.Television)), `${accessory.displayName} Set Top Box`;
64
+ (this.service = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)),
65
+ `${accessory.displayName} Set Top Box`;
73
66
  break;
74
67
  default:
75
68
  accessory.category = this.platform.api.hap.Categories.TELEVISION;
76
69
 
77
70
  // get the Television service if it exists, otherwise create a new Television service
78
71
  // you can create multiple services for each accessory
79
- (this.service =
80
- accessory.getService(this.platform.Service.Television) ||
81
- accessory.addService(this.platform.Service.Television)), `${accessory.displayName} TV`;
72
+ (this.service = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)),
73
+ `${accessory.displayName} TV`;
82
74
  }
83
75
 
84
76
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -111,22 +103,17 @@ export class TV {
111
103
  */
112
104
  // create a new Television Speaker service
113
105
  (this.speakerService =
114
- accessory.getService(this.platform.Service.TelevisionSpeaker) ||
115
- accessory.addService(this.platform.Service.TelevisionSpeaker)), `${accessory.displayName} Speaker`;
106
+ accessory.getService(this.platform.Service.TelevisionSpeaker) || accessory.addService(this.platform.Service.TelevisionSpeaker)),
107
+ `${accessory.displayName} Speaker`;
116
108
 
117
109
  this.speakerService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Speaker`);
118
110
 
119
111
  this.speakerService
120
112
  .setCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.ACTIVE)
121
- .setCharacteristic(
122
- this.platform.Characteristic.VolumeControlType,
123
- this.platform.Characteristic.VolumeControlType.ABSOLUTE,
124
- );
113
+ .setCharacteristic(this.platform.Characteristic.VolumeControlType, this.platform.Characteristic.VolumeControlType.ABSOLUTE);
125
114
 
126
115
  // handle volume control
127
- this.speakerService
128
- .getCharacteristic(this.platform.Characteristic.VolumeSelector)
129
- .onSet(this.VolumeSelectorSet.bind(this));
116
+ this.speakerService.getCharacteristic(this.platform.Characteristic.VolumeSelector).onSet(this.VolumeSelectorSet.bind(this));
130
117
  }
131
118
 
132
119
  private VolumeSelectorSet(value: CharacteristicValue) {
@@ -232,8 +219,7 @@ export class TV {
232
219
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
233
220
  } else {
234
221
  this.service?.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
235
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
236
- + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
222
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
237
223
  }
238
224
  }
239
225
 
@@ -350,8 +336,10 @@ export class TV {
350
336
 
351
337
  public async pushTVChanges(payload: payload) {
352
338
  try {
353
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
354
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
339
+ this.infoLog(
340
+ `${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
341
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
342
+ );
355
343
 
356
344
  // Make the API request
357
345
  const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
@@ -361,19 +349,21 @@ export class TV {
361
349
  } catch (e: any) {
362
350
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
363
351
  if (this.deviceLogging === 'debug') {
364
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
365
- + ` Error Message: ${JSON.stringify(e.message)}`);
352
+ this.errorLog(
353
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
354
+ ` Error Message: ${JSON.stringify(e.message)}`,
355
+ );
366
356
  }
367
357
  if (this.platform.debugMode) {
368
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
369
- + ` Error: ${JSON.stringify(e)}`);
358
+ this.errorLog(
359
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
360
+ );
370
361
  }
371
362
  this.apiError(e);
372
363
  }
373
364
  }
374
365
 
375
-
376
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
366
+ private statusCode(push: AxiosResponse<{ statusCode: number }>) {
377
367
  switch (push.data.statusCode) {
378
368
  case 151:
379
369
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -391,9 +381,11 @@ export class TV {
391
381
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
392
382
  break;
393
383
  case 190:
394
- this.errorLog(`${this.device.remoteType}: `
395
- + `${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
396
- + ` Or command: ${JSON.stringify(push.data)} format is invalid`);
384
+ this.errorLog(
385
+ `${this.device.remoteType}: ` +
386
+ `${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
387
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`,
388
+ );
397
389
  break;
398
390
  case 100:
399
391
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
@@ -439,8 +431,8 @@ export class TV {
439
431
  }
440
432
 
441
433
  /**
442
- * Logging for Device
443
- */
434
+ * Logging for Device
435
+ */
444
436
  infoLog(...log: any[]) {
445
437
  if (this.enablingDeviceLogging()) {
446
438
  this.platform.log.info(String(...log));
@@ -19,11 +19,7 @@ export class VacuumCleaner {
19
19
  // Config
20
20
  deviceLogging!: string;
21
21
 
22
- constructor(
23
- private readonly platform: SwitchBotPlatform,
24
- private accessory: PlatformAccessory,
25
- public device: irdevice & irDevicesConfig,
26
- ) {
22
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
27
23
  // default placeholders
28
24
  this.logs(device);
29
25
  this.config(device);
@@ -42,9 +38,8 @@ export class VacuumCleaner {
42
38
 
43
39
  // get the Television service if it exists, otherwise create a new Television service
44
40
  // you can create multiple services for each accessory
45
- (this.service =
46
- accessory.getService(this.platform.Service.Switch) ||
47
- accessory.addService(this.platform.Service.Switch)), `${accessory.displayName} Vacuum`;
41
+ (this.service = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
42
+ `${accessory.displayName} Vacuum`;
48
43
 
49
44
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
50
45
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -111,8 +106,10 @@ export class VacuumCleaner {
111
106
 
112
107
  public async pushChanges(payload: payload) {
113
108
  try {
114
- this.infoLog(`Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
115
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
109
+ this.infoLog(
110
+ `Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
111
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
112
+ );
116
113
 
117
114
  // Make the API request
118
115
  const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
@@ -124,18 +121,19 @@ export class VacuumCleaner {
124
121
  } catch (e: any) {
125
122
  this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
126
123
  if (this.deviceLogging === 'debug') {
127
- this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
128
- + ` Error Message: ${JSON.stringify(e.message)}`);
124
+ this.errorLog(
125
+ `Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
126
+ ` Error Message: ${JSON.stringify(e.message)}`,
127
+ );
129
128
  }
130
129
  if (this.platform.debugMode) {
131
- this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
132
- + ` Error: ${JSON.stringify(e)}`);
130
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
133
131
  }
134
132
  this.apiError(e);
135
133
  }
136
134
  }
137
135
 
138
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
136
+ private statusCode(push: AxiosResponse<{ statusCode: number }>) {
139
137
  switch (push.data.statusCode) {
140
138
  case 151:
141
139
  this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -153,8 +151,10 @@ export class VacuumCleaner {
153
151
  this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
154
152
  break;
155
153
  case 190:
156
- this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized`
157
- + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
154
+ this.errorLog(
155
+ `Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
156
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
157
+ );
158
158
  break;
159
159
  case 100:
160
160
  this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Command successfully sent.`);
@@ -199,8 +199,8 @@ export class VacuumCleaner {
199
199
  }
200
200
 
201
201
  /**
202
- * Logging for Device
203
- */
202
+ * Logging for Device
203
+ */
204
204
  infoLog(...log: any[]) {
205
205
  if (this.enablingDeviceLogging()) {
206
206
  this.platform.log.info(String(...log));
@@ -19,11 +19,7 @@ export class WaterHeater {
19
19
  // Config
20
20
  deviceLogging!: string;
21
21
 
22
- constructor(
23
- private readonly platform: SwitchBotPlatform,
24
- private accessory: PlatformAccessory,
25
- public device: irdevice & irDevicesConfig,
26
- ) {
22
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
27
23
  // default placeholders
28
24
  this.logs(device);
29
25
  this.config(device);
@@ -42,9 +38,8 @@ export class WaterHeater {
42
38
 
43
39
  // get the Television service if it exists, otherwise create a new Television service
44
40
  // you can create multiple services for each accessory
45
- (this.service =
46
- accessory.getService(this.platform.Service.Valve) ||
47
- accessory.addService(this.platform.Service.Valve)), `${accessory.displayName} Water Heater`;
41
+ (this.service = accessory.getService(this.platform.Service.Valve) || accessory.addService(this.platform.Service.Valve)),
42
+ `${accessory.displayName} Water Heater`;
48
43
 
49
44
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
50
45
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
@@ -52,16 +47,10 @@ export class WaterHeater {
52
47
 
53
48
  // set the service name, this is what is displayed as the default name on the Home app
54
49
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
55
- this.service.setCharacteristic(
56
- this.platform.Characteristic.Name,
57
- `${device.deviceName} ${device.remoteType}`,
58
- );
50
+ this.service.setCharacteristic(this.platform.Characteristic.Name, `${device.deviceName} ${device.remoteType}`);
59
51
 
60
52
  // set sleep discovery characteristic
61
- this.service.setCharacteristic(
62
- this.platform.Characteristic.ValveType,
63
- this.platform.Characteristic.ValveType.GENERIC_VALVE,
64
- );
53
+ this.service.setCharacteristic(this.platform.Characteristic.ValveType, this.platform.Characteristic.ValveType.GENERIC_VALVE);
65
54
 
66
55
  // handle on / off events using the Active characteristic
67
56
  this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
@@ -71,10 +60,7 @@ export class WaterHeater {
71
60
  this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${value}`);
72
61
  if (value === this.platform.Characteristic.Active.INACTIVE) {
73
62
  this.pushWaterHeaterOffChanges();
74
- this.service.setCharacteristic(
75
- this.platform.Characteristic.InUse,
76
- this.platform.Characteristic.InUse.NOT_IN_USE,
77
- );
63
+ this.service.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.NOT_IN_USE);
78
64
  } else {
79
65
  this.pushWaterHeaterOnChanges();
80
66
  this.service.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.IN_USE);
@@ -127,8 +113,10 @@ export class WaterHeater {
127
113
 
128
114
  public async pushChanges(payload: payload) {
129
115
  try {
130
- this.infoLog(`Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
131
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
116
+ this.infoLog(
117
+ `Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
118
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
119
+ );
132
120
 
133
121
  // Make the API request
134
122
  const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
@@ -138,18 +126,18 @@ export class WaterHeater {
138
126
  } catch (e: any) {
139
127
  this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
140
128
  if (this.deviceLogging === 'debug') {
141
- this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
142
- + ` Error Message: ${JSON.stringify(e.message)}`);
129
+ this.errorLog(
130
+ `Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
131
+ );
143
132
  }
144
133
  if (this.platform.debugMode) {
145
- this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
146
- + ` Error: ${JSON.stringify(e)}`);
134
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
147
135
  }
148
136
  this.apiError(e);
149
137
  }
150
138
  }
151
139
 
152
- private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
140
+ private statusCode(push: AxiosResponse<{ statusCode: number }>) {
153
141
  switch (push.data.statusCode) {
154
142
  case 151:
155
143
  this.errorLog(`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`);
@@ -167,8 +155,10 @@ export class WaterHeater {
167
155
  this.errorLog(`Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
168
156
  break;
169
157
  case 190:
170
- this.errorLog(`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized`
171
- + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
158
+ this.errorLog(
159
+ `Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
160
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
161
+ );
172
162
  break;
173
163
  case 100:
174
164
  this.debugLog(`Water Heater: ${this.accessory.displayName} Command successfully sent.`);
@@ -213,8 +203,8 @@ export class WaterHeater {
213
203
  }
214
204
 
215
205
  /**
216
- * Logging for Device
217
- */
206
+ * Logging for Device
207
+ */
218
208
  infoLog(...log: any[]) {
219
209
  if (this.enablingDeviceLogging()) {
220
210
  this.platform.log.info(String(...log));