@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.9.0

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 (105) hide show
  1. package/.eslintrc +1 -1
  2. package/.vscode/settings.json +1 -1
  3. package/CHANGELOG.md +8 -0
  4. package/config.schema.json +9 -0
  5. package/dist/devices/bots.d.ts +37 -34
  6. package/dist/devices/bots.d.ts.map +1 -1
  7. package/dist/devices/bots.js +196 -243
  8. package/dist/devices/bots.js.map +1 -1
  9. package/dist/devices/colorbulb.d.ts +50 -50
  10. package/dist/devices/colorbulb.d.ts.map +1 -1
  11. package/dist/devices/colorbulb.js +131 -145
  12. package/dist/devices/colorbulb.js.map +1 -1
  13. package/dist/devices/contact.d.ts +29 -27
  14. package/dist/devices/contact.d.ts.map +1 -1
  15. package/dist/devices/contact.js +115 -138
  16. package/dist/devices/contact.js.map +1 -1
  17. package/dist/devices/curtains.d.ts +31 -29
  18. package/dist/devices/curtains.d.ts.map +1 -1
  19. package/dist/devices/curtains.js +176 -211
  20. package/dist/devices/curtains.js.map +1 -1
  21. package/dist/devices/humidifiers.d.ts +33 -33
  22. package/dist/devices/humidifiers.d.ts.map +1 -1
  23. package/dist/devices/humidifiers.js +189 -214
  24. package/dist/devices/humidifiers.js.map +1 -1
  25. package/dist/devices/meters.d.ts +31 -30
  26. package/dist/devices/meters.d.ts.map +1 -1
  27. package/dist/devices/meters.js +100 -124
  28. package/dist/devices/meters.js.map +1 -1
  29. package/dist/devices/motion.d.ts +26 -25
  30. package/dist/devices/motion.d.ts.map +1 -1
  31. package/dist/devices/motion.js +102 -120
  32. package/dist/devices/motion.js.map +1 -1
  33. package/dist/devices/plugs.d.ts +23 -23
  34. package/dist/devices/plugs.d.ts.map +1 -1
  35. package/dist/devices/plugs.js +63 -81
  36. package/dist/devices/plugs.js.map +1 -1
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +3 -22
  40. package/dist/index.js.map +1 -1
  41. package/dist/irdevices/airconditioners.d.ts +6 -6
  42. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  43. package/dist/irdevices/airconditioners.js +79 -105
  44. package/dist/irdevices/airconditioners.js.map +1 -1
  45. package/dist/irdevices/airpurifiers.d.ts +5 -5
  46. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  47. package/dist/irdevices/airpurifiers.js +42 -56
  48. package/dist/irdevices/airpurifiers.js.map +1 -1
  49. package/dist/irdevices/cameras.d.ts +5 -5
  50. package/dist/irdevices/cameras.d.ts.map +1 -1
  51. package/dist/irdevices/cameras.js +27 -31
  52. package/dist/irdevices/cameras.js.map +1 -1
  53. package/dist/irdevices/fans.d.ts +5 -5
  54. package/dist/irdevices/fans.d.ts.map +1 -1
  55. package/dist/irdevices/fans.js +38 -45
  56. package/dist/irdevices/fans.js.map +1 -1
  57. package/dist/irdevices/lights.d.ts +5 -5
  58. package/dist/irdevices/lights.d.ts.map +1 -1
  59. package/dist/irdevices/lights.js +33 -37
  60. package/dist/irdevices/lights.js.map +1 -1
  61. package/dist/irdevices/others.d.ts +5 -5
  62. package/dist/irdevices/others.d.ts.map +1 -1
  63. package/dist/irdevices/others.js +29 -34
  64. package/dist/irdevices/others.js.map +1 -1
  65. package/dist/irdevices/tvs.d.ts +5 -5
  66. package/dist/irdevices/tvs.d.ts.map +1 -1
  67. package/dist/irdevices/tvs.js +76 -91
  68. package/dist/irdevices/tvs.js.map +1 -1
  69. package/dist/irdevices/vacuumcleaners.d.ts +5 -5
  70. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  71. package/dist/irdevices/vacuumcleaners.js +27 -31
  72. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  73. package/dist/irdevices/waterheaters.d.ts +5 -5
  74. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  75. package/dist/irdevices/waterheaters.js +27 -31
  76. package/dist/irdevices/waterheaters.js.map +1 -1
  77. package/dist/platform.d.ts +12 -12
  78. package/dist/platform.d.ts.map +1 -1
  79. package/dist/platform.js +172 -241
  80. package/dist/platform.js.map +1 -1
  81. package/dist/settings.d.ts +2 -1
  82. package/dist/settings.d.ts.map +1 -1
  83. package/dist/settings.js +4 -4
  84. package/dist/settings.js.map +1 -1
  85. package/package.json +71 -72
  86. package/src/devices/bots.ts +455 -929
  87. package/src/devices/colorbulb.ts +246 -473
  88. package/src/devices/contact.ts +208 -381
  89. package/src/devices/curtains.ts +321 -613
  90. package/src/devices/humidifiers.ts +323 -594
  91. package/src/devices/meters.ts +186 -331
  92. package/src/devices/motion.ts +184 -327
  93. package/src/devices/plugs.ts +107 -175
  94. package/src/index.ts +5 -5
  95. package/src/irdevices/airconditioners.ts +149 -360
  96. package/src/irdevices/airpurifiers.ts +80 -178
  97. package/src/irdevices/cameras.ts +51 -109
  98. package/src/irdevices/fans.ts +77 -174
  99. package/src/irdevices/lights.ts +57 -110
  100. package/src/irdevices/others.ts +62 -137
  101. package/src/irdevices/tvs.ts +124 -249
  102. package/src/irdevices/vacuumcleaners.ts +52 -112
  103. package/src/irdevices/waterheaters.ts +53 -115
  104. package/src/platform.ts +357 -768
  105. package/src/settings.ts +24 -17
@@ -1,13 +1,7 @@
1
- import { AxiosResponse } from "axios";
2
- import { SwitchBotPlatform } from "../platform";
3
- import { CharacteristicValue, PlatformAccessory, Service } from "homebridge";
4
- import {
5
- DeviceURL,
6
- irdevice,
7
- deviceStatusResponse,
8
- irDevicesConfig,
9
- payload,
10
- } from "../settings";
1
+ import { AxiosResponse } from 'axios';
2
+ import { SwitchBotPlatform } from '../platform';
3
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
11
5
 
12
6
  /**
13
7
  * Platform Accessory
@@ -47,45 +41,35 @@ export class TV {
47
41
  // set accessory information
48
42
  accessory
49
43
  .getService(this.platform.Service.AccessoryInformation)!
50
- .setCharacteristic(
51
- this.platform.Characteristic.Name,
52
- `${device.deviceName} ${device.remoteType}`,
53
- )
54
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
44
+ .setCharacteristic(this.platform.Characteristic.Name, `${device.deviceName} ${device.remoteType}`)
45
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
55
46
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
56
- .setCharacteristic(
57
- this.platform.Characteristic.SerialNumber,
58
- device.deviceId!,
59
- );
47
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
60
48
 
61
49
  // set the accessory category
62
50
  switch (device.remoteType) {
63
- case "Speaker":
64
- case "DIY Speaker":
51
+ case 'Speaker':
52
+ case 'DIY Speaker':
65
53
  accessory.category = this.platform.api.hap.Categories.SPEAKER;
66
54
  (this.service =
67
55
  accessory.getService(this.platform.Service.Television) ||
68
- accessory.addService(this.platform.Service.Television)),
69
- `${accessory.displayName} Speaker`;
56
+ accessory.addService(this.platform.Service.Television)), `${accessory.displayName} Speaker`;
70
57
  break;
71
- case "IPTV":
72
- case "DIY IPTV":
73
- accessory.category =
74
- this.platform.api.hap.Categories.TV_STREAMING_STICK;
58
+ case 'IPTV':
59
+ case 'DIY IPTV':
60
+ accessory.category = this.platform.api.hap.Categories.TV_STREAMING_STICK;
75
61
  (this.service =
76
62
  accessory.getService(this.platform.Service.Television) ||
77
- accessory.addService(this.platform.Service.Television)),
78
- `${accessory.displayName} Streaming Stick`;
63
+ accessory.addService(this.platform.Service.Television)), `${accessory.displayName} Streaming Stick`;
79
64
  break;
80
- case "DVD":
81
- case "DIY DVD":
82
- case "Set Top Box":
83
- case "DIY Set Top Box":
65
+ case 'DVD':
66
+ case 'DIY DVD':
67
+ case 'Set Top Box':
68
+ case 'DIY Set Top Box':
84
69
  accessory.category = this.platform.api.hap.Categories.TV_SET_TOP_BOX;
85
70
  (this.service =
86
71
  accessory.getService(this.platform.Service.Television) ||
87
- accessory.addService(this.platform.Service.Television)),
88
- `${accessory.displayName} Set Top Box`;
72
+ accessory.addService(this.platform.Service.Television)), `${accessory.displayName} Set Top Box`;
89
73
  break;
90
74
  default:
91
75
  accessory.category = this.platform.api.hap.Categories.TELEVISION;
@@ -94,8 +78,7 @@ export class TV {
94
78
  // you can create multiple services for each accessory
95
79
  (this.service =
96
80
  accessory.getService(this.platform.Service.Television) ||
97
- accessory.addService(this.platform.Service.Television)),
98
- `${accessory.displayName} TV`;
81
+ accessory.addService(this.platform.Service.Television)), `${accessory.displayName} TV`;
99
82
  }
100
83
 
101
84
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -113,24 +96,15 @@ export class TV {
113
96
  );
114
97
 
115
98
  // handle on / off events using the Active characteristic
116
- this.service
117
- .getCharacteristic(this.platform.Characteristic.Active)
118
- .onSet(this.ActiveSet.bind(this));
99
+ this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
119
100
 
120
- this.service.setCharacteristic(
121
- this.platform.Characteristic.ActiveIdentifier,
122
- 1,
123
- );
101
+ this.service.setCharacteristic(this.platform.Characteristic.ActiveIdentifier, 1);
124
102
 
125
103
  // handle input source changes
126
- this.service
127
- .getCharacteristic(this.platform.Characteristic.ActiveIdentifier)
128
- .onSet(this.ActiveIdentifierSet.bind(this));
104
+ this.service.getCharacteristic(this.platform.Characteristic.ActiveIdentifier).onSet(this.ActiveIdentifierSet.bind(this));
129
105
 
130
106
  // handle remote control input
131
- this.service
132
- .getCharacteristic(this.platform.Characteristic.RemoteKey)
133
- .onSet(this.RemoteKeySet.bind(this));
107
+ this.service.getCharacteristic(this.platform.Characteristic.RemoteKey).onSet(this.RemoteKeySet.bind(this));
134
108
 
135
109
  /**
136
110
  * Create a speaker service to allow volume control
@@ -138,19 +112,12 @@ export class TV {
138
112
  // create a new Television Speaker service
139
113
  (this.speakerService =
140
114
  accessory.getService(this.platform.Service.TelevisionSpeaker) ||
141
- accessory.addService(this.platform.Service.TelevisionSpeaker)),
142
- `${accessory.displayName} Speaker`;
115
+ accessory.addService(this.platform.Service.TelevisionSpeaker)), `${accessory.displayName} Speaker`;
143
116
 
144
- this.speakerService.setCharacteristic(
145
- this.platform.Characteristic.Name,
146
- `${accessory.displayName} Speaker`,
147
- );
117
+ this.speakerService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Speaker`);
148
118
 
149
119
  this.speakerService
150
- .setCharacteristic(
151
- this.platform.Characteristic.Active,
152
- this.platform.Characteristic.Active.ACTIVE,
153
- )
120
+ .setCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.ACTIVE)
154
121
  .setCharacteristic(
155
122
  this.platform.Characteristic.VolumeControlType,
156
123
  this.platform.Characteristic.VolumeControlType.ABSOLUTE,
@@ -163,9 +130,7 @@ export class TV {
163
130
  }
164
131
 
165
132
  private VolumeSelectorSet(value: CharacteristicValue) {
166
- this.debugLog(
167
- `${this.device.remoteType}: ${this.accessory.displayName} VolumeSelector: ${value}`,
168
- );
133
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} VolumeSelector: ${value}`);
169
134
  if (value === this.platform.Characteristic.VolumeSelector.INCREMENT) {
170
135
  this.pushVolumeUpChanges();
171
136
  } else {
@@ -176,87 +141,61 @@ export class TV {
176
141
  private RemoteKeySet(value: CharacteristicValue) {
177
142
  switch (value) {
178
143
  case this.platform.Characteristic.RemoteKey.REWIND: {
179
- this.debugLog(
180
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: REWIND`,
181
- );
144
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: REWIND`);
182
145
  break;
183
146
  }
184
147
  case this.platform.Characteristic.RemoteKey.FAST_FORWARD: {
185
- this.debugLog(
186
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: FAST_FORWARD`,
187
- );
148
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: FAST_FORWARD`);
188
149
  break;
189
150
  }
190
151
  case this.platform.Characteristic.RemoteKey.NEXT_TRACK: {
191
- this.debugLog(
192
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: NEXT_TRACK`,
193
- );
152
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: NEXT_TRACK`);
194
153
  break;
195
154
  }
196
155
  case this.platform.Characteristic.RemoteKey.PREVIOUS_TRACK: {
197
- this.debugLog(
198
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: PREVIOUS_TRACK`,
199
- );
156
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: PREVIOUS_TRACK`);
200
157
  break;
201
158
  }
202
159
  case this.platform.Characteristic.RemoteKey.ARROW_UP: {
203
- this.debugLog(
204
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_UP`,
205
- );
160
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_UP`);
206
161
  //this.pushUpChanges();
207
162
  break;
208
163
  }
209
164
  case this.platform.Characteristic.RemoteKey.ARROW_DOWN: {
210
- this.debugLog(
211
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_DOWN`,
212
- );
165
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_DOWN`);
213
166
  //this.pushDownChanges();
214
167
  break;
215
168
  }
216
169
  case this.platform.Characteristic.RemoteKey.ARROW_LEFT: {
217
- this.debugLog(
218
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_LEFT`,
219
- );
170
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_LEFT`);
220
171
  //this.pushLeftChanges();
221
172
  break;
222
173
  }
223
174
  case this.platform.Characteristic.RemoteKey.ARROW_RIGHT: {
224
- this.debugLog(
225
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_RIGHT`,
226
- );
175
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_RIGHT`);
227
176
  //this.pushRightChanges();
228
177
  break;
229
178
  }
230
179
  case this.platform.Characteristic.RemoteKey.SELECT: {
231
- this.debugLog(
232
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: SELECT`,
233
- );
180
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: SELECT`);
234
181
  //this.pushOkChanges();
235
182
  break;
236
183
  }
237
184
  case this.platform.Characteristic.RemoteKey.BACK: {
238
- this.debugLog(
239
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: BACK`,
240
- );
185
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: BACK`);
241
186
  //this.pushBackChanges();
242
187
  break;
243
188
  }
244
189
  case this.platform.Characteristic.RemoteKey.EXIT: {
245
- this.debugLog(
246
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: EXIT`,
247
- );
190
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: EXIT`);
248
191
  break;
249
192
  }
250
193
  case this.platform.Characteristic.RemoteKey.PLAY_PAUSE: {
251
- this.debugLog(
252
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: PLAY_PAUSE`,
253
- );
194
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: PLAY_PAUSE`);
254
195
  break;
255
196
  }
256
197
  case this.platform.Characteristic.RemoteKey.INFORMATION: {
257
- this.debugLog(
258
- `${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: INFORMATION`,
259
- );
198
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: INFORMATION`);
260
199
  //this.pushMenuChanges();
261
200
  break;
262
201
  }
@@ -264,16 +203,12 @@ export class TV {
264
203
  }
265
204
 
266
205
  private ActiveIdentifierSet(value: CharacteristicValue) {
267
- this.debugLog(
268
- `${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${value}`,
269
- );
206
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${value}`);
270
207
  this.ActiveIdentifier = value;
271
208
  }
272
209
 
273
210
  private ActiveSet(value: CharacteristicValue) {
274
- this.debugLog(
275
- `${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`,
276
- );
211
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
277
212
  if (!this.device.irtv?.disable_power) {
278
213
  if (value === this.platform.Characteristic.Active.INACTIVE) {
279
214
  this.pushTvOffChanges();
@@ -288,31 +223,17 @@ export class TV {
288
223
 
289
224
  private updateHomeKitCharacteristics() {
290
225
  if (this.Active === undefined) {
291
- this.debugLog(
292
- `${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`,
293
- );
226
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
294
227
  } else {
295
- this.service?.updateCharacteristic(
296
- this.platform.Characteristic.Active,
297
- this.Active,
298
- );
299
- this.debugLog(
300
- `${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
301
- );
228
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
229
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
302
230
  }
303
231
  if (this.ActiveIdentifier === undefined) {
304
- this.debugLog(
305
- `${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`,
306
- );
232
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
307
233
  } else {
308
- this.service?.updateCharacteristic(
309
- this.platform.Characteristic.ActiveIdentifier,
310
- this.ActiveIdentifier,
311
- );
312
- this.debugLog(
313
- `${this.device.remoteType}: ${this.accessory.displayName}` +
314
- ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`,
315
- );
234
+ this.service?.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
235
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
236
+ + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
316
237
  }
317
238
  }
318
239
 
@@ -327,197 +248,164 @@ export class TV {
327
248
  * TV: "command" "channelSub" "default" = previous channel
328
249
  */
329
250
  async pushTvOnChanges() {
330
- if (this.Active !== this.platform.Characteristic.Active.ACTIVE) {
251
+ if (this.Active !== 1) {
331
252
  const payload = {
332
- commandType: "command",
333
- parameter: "default",
334
- command: "turnOn",
253
+ commandType: 'command',
254
+ parameter: 'default',
255
+ command: 'turnOn',
335
256
  } as payload;
336
257
  await this.pushTVChanges(payload);
337
258
  }
338
259
  }
339
260
 
340
261
  async pushTvOffChanges() {
341
- if (this.Active !== this.platform.Characteristic.Active.INACTIVE) {
342
- const payload = {
343
- commandType: "command",
344
- parameter: "default",
345
- command: "turnOff",
346
- } as payload;
347
- await this.pushTVChanges(payload);
348
- }
262
+ const payload = {
263
+ commandType: 'command',
264
+ parameter: 'default',
265
+ command: 'turnOff',
266
+ } as payload;
267
+ await this.pushTVChanges(payload);
349
268
  }
350
269
 
351
270
  async pushOkChanges() {
352
271
  const payload = {
353
- commandType: "command",
354
- parameter: "default",
355
- command: "Ok",
272
+ commandType: 'command',
273
+ parameter: 'default',
274
+ command: 'Ok',
356
275
  } as payload;
357
276
  await this.pushTVChanges(payload);
358
277
  }
359
278
 
360
279
  async pushBackChanges() {
361
280
  const payload = {
362
- commandType: "command",
363
- parameter: "default",
364
- command: "Back",
281
+ commandType: 'command',
282
+ parameter: 'default',
283
+ command: 'Back',
365
284
  } as payload;
366
285
  await this.pushTVChanges(payload);
367
286
  }
368
287
 
369
288
  async pushMenuChanges() {
370
289
  const payload = {
371
- commandType: "command",
372
- parameter: "default",
373
- command: "Menu",
290
+ commandType: 'command',
291
+ parameter: 'default',
292
+ command: 'Menu',
374
293
  } as payload;
375
294
  await this.pushTVChanges(payload);
376
295
  }
377
296
 
378
297
  async pushUpChanges() {
379
298
  const payload = {
380
- commandType: "command",
381
- parameter: "default",
382
- command: "Up",
299
+ commandType: 'command',
300
+ parameter: 'default',
301
+ command: 'Up',
383
302
  } as payload;
384
303
  await this.pushTVChanges(payload);
385
304
  }
386
305
 
387
306
  async pushDownChanges() {
388
307
  const payload = {
389
- commandType: "command",
390
- parameter: "default",
391
- command: "Down",
308
+ commandType: 'command',
309
+ parameter: 'default',
310
+ command: 'Down',
392
311
  } as payload;
393
312
  await this.pushTVChanges(payload);
394
313
  }
395
314
 
396
315
  async pushRightChanges() {
397
316
  const payload = {
398
- commandType: "command",
399
- parameter: "default",
400
- command: "Right",
317
+ commandType: 'command',
318
+ parameter: 'default',
319
+ command: 'Right',
401
320
  } as payload;
402
321
  await this.pushTVChanges(payload);
403
322
  }
404
323
 
405
324
  async pushLeftChanges() {
406
325
  const payload = {
407
- commandType: "command",
408
- parameter: "default",
409
- command: "Left",
326
+ commandType: 'command',
327
+ parameter: 'default',
328
+ command: 'Left',
410
329
  } as payload;
411
330
  await this.pushTVChanges(payload);
412
331
  }
413
332
 
414
333
  async pushVolumeUpChanges() {
415
334
  const payload = {
416
- commandType: "command",
417
- parameter: "default",
418
- command: "volumeAdd",
335
+ commandType: 'command',
336
+ parameter: 'default',
337
+ command: 'volumeAdd',
419
338
  } as payload;
420
339
  await this.pushTVChanges(payload);
421
340
  }
422
341
 
423
342
  async pushVolumeDownChanges() {
424
343
  const payload = {
425
- commandType: "command",
426
- parameter: "default",
427
- command: "volumeSub",
344
+ commandType: 'command',
345
+ parameter: 'default',
346
+ command: 'volumeSub',
428
347
  } as payload;
429
348
  await this.pushTVChanges(payload);
430
349
  }
431
350
 
432
351
  public async pushTVChanges(payload: payload) {
433
352
  try {
434
- this.infoLog(
435
- `${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
436
- ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
437
- );
353
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
354
+ + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
438
355
 
439
356
  // Make the API request
440
- const push = await this.platform.axios.post(
441
- `${DeviceURL}/${this.device.deviceId}/commands`,
442
- payload,
443
- );
444
- this.debugLog(
445
- `${this.device.remoteType}: ${this.accessory.displayName} pushChanges: ${push.data}`,
446
- );
357
+ const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
358
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges: ${push.data}`);
447
359
  this.statusCode(push);
448
360
  this.updateHomeKitCharacteristics();
449
361
  } catch (e: any) {
450
- this.errorLog(
451
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
452
- );
453
- if (this.deviceLogging === "debug") {
454
- this.errorLog(
455
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
456
- ` Error Message: ${JSON.stringify(e.message)}`,
457
- );
362
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
363
+ 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)}`);
458
366
  }
459
367
  if (this.platform.debugMode) {
460
- this.errorLog(
461
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
462
- ` Error: ${JSON.stringify(e)}`,
463
- );
368
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
369
+ + ` Error: ${JSON.stringify(e)}`);
464
370
  }
465
371
  this.apiError(e);
466
372
  }
467
373
  }
468
374
 
469
- private statusCode(push: AxiosResponse<{ statusCode: number }>) {
375
+
376
+ private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
470
377
  switch (push.data.statusCode) {
471
378
  case 151:
472
- this.errorLog(
473
- `${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`,
474
- );
379
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
475
380
  break;
476
381
  case 152:
477
- this.errorLog(
478
- `${this.device.remoteType}: ${this.accessory.displayName} Device not found.`,
479
- );
382
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
480
383
  break;
481
384
  case 160:
482
- this.errorLog(
483
- `${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`,
484
- );
385
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
485
386
  break;
486
387
  case 161:
487
- this.errorLog(
488
- `${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`,
489
- );
388
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
490
389
  break;
491
390
  case 171:
492
- this.errorLog(
493
- `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
494
- );
391
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
495
392
  break;
496
393
  case 190:
497
- this.errorLog(
498
- `${this.device.remoteType}: ` +
499
- `${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
500
- ` Or command: ${JSON.stringify(push.data)} format is invalid`,
501
- );
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`);
502
397
  break;
503
398
  case 100:
504
- this.debugLog(
505
- `${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`,
506
- );
399
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
507
400
  break;
508
401
  default:
509
- this.debugLog(
510
- `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`,
511
- );
402
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
512
403
  }
513
404
  }
514
405
 
515
406
  public apiError(e: any) {
516
407
  this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
517
- this.service.updateCharacteristic(
518
- this.platform.Characteristic.ActiveIdentifier,
519
- e,
520
- );
408
+ this.service.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, e);
521
409
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
522
410
  }
523
411
 
@@ -527,45 +415,32 @@ export class TV {
527
415
  config = device.irtv;
528
416
  }
529
417
  if (device.logging !== undefined) {
530
- config["logging"] = device.logging;
418
+ config['logging'] = device.logging;
531
419
  }
532
420
  if (Object.entries(config).length !== 0) {
533
- this.warnLog(
534
- `${this.device.remoteType}: ${
535
- this.accessory.displayName
536
- } Config: ${JSON.stringify(config)}`,
537
- );
421
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
538
422
  }
539
423
  }
540
424
 
541
425
  logs(device: irdevice & irDevicesConfig) {
542
426
  if (this.platform.debugMode) {
543
- this.deviceLogging = this.accessory.context.logging = "debugMode";
544
- this.debugLog(
545
- `${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
546
- );
427
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
428
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
547
429
  } else if (device.logging) {
548
430
  this.deviceLogging = this.accessory.context.logging = device.logging;
549
- this.debugLog(
550
- `${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
551
- );
431
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
552
432
  } else if (this.platform.config.options?.logging) {
553
- this.deviceLogging = this.accessory.context.logging =
554
- this.platform.config.options?.logging;
555
- this.debugLog(
556
- `${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
557
- );
433
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
434
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
558
435
  } else {
559
- this.deviceLogging = this.accessory.context.logging = "standard";
560
- this.debugLog(
561
- `${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
562
- );
436
+ this.deviceLogging = this.accessory.context.logging = 'standard';
437
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
563
438
  }
564
439
  }
565
440
 
566
441
  /**
567
- * Logging for Device
568
- */
442
+ * Logging for Device
443
+ */
569
444
  infoLog(...log: any[]) {
570
445
  if (this.enablingDeviceLogging()) {
571
446
  this.platform.log.info(String(...log));
@@ -586,8 +461,8 @@ export class TV {
586
461
 
587
462
  debugLog(...log: any[]) {
588
463
  if (this.enablingDeviceLogging()) {
589
- if (this.deviceLogging === "debug") {
590
- this.platform.log.info("[DEBUG]", String(...log));
464
+ if (this.deviceLogging === 'debug') {
465
+ this.platform.log.info('[DEBUG]', String(...log));
591
466
  } else {
592
467
  this.platform.log.debug(String(...log));
593
468
  }
@@ -595,6 +470,6 @@ export class TV {
595
470
  }
596
471
 
597
472
  enablingDeviceLogging(): boolean {
598
- return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
473
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
599
474
  }
600
475
  }