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