@switchbot/homebridge-switchbot 2.0.0-beta.17 → 2.0.0-beta.19

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 (106) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/config.schema.json +14 -4
  3. package/dist/device/bot.d.ts +2 -0
  4. package/dist/device/bot.d.ts.map +1 -1
  5. package/dist/device/bot.js +201 -163
  6. package/dist/device/bot.js.map +1 -1
  7. package/dist/device/colorbulb.d.ts +2 -0
  8. package/dist/device/colorbulb.d.ts.map +1 -1
  9. package/dist/device/colorbulb.js +250 -218
  10. package/dist/device/colorbulb.js.map +1 -1
  11. package/dist/device/contact.d.ts +2 -0
  12. package/dist/device/contact.d.ts.map +1 -1
  13. package/dist/device/contact.js +85 -66
  14. package/dist/device/contact.js.map +1 -1
  15. package/dist/device/curtain.d.ts +2 -0
  16. package/dist/device/curtain.d.ts.map +1 -1
  17. package/dist/device/curtain.js +166 -136
  18. package/dist/device/curtain.js.map +1 -1
  19. package/dist/device/humidifier.d.ts.map +1 -1
  20. package/dist/device/humidifier.js +126 -115
  21. package/dist/device/humidifier.js.map +1 -1
  22. package/dist/device/lock.d.ts +2 -0
  23. package/dist/device/lock.d.ts.map +1 -1
  24. package/dist/device/lock.js +156 -130
  25. package/dist/device/lock.js.map +1 -1
  26. package/dist/device/meter.d.ts +2 -0
  27. package/dist/device/meter.d.ts.map +1 -1
  28. package/dist/device/meter.js +85 -64
  29. package/dist/device/meter.js.map +1 -1
  30. package/dist/device/meterplus.d.ts +2 -0
  31. package/dist/device/meterplus.d.ts.map +1 -1
  32. package/dist/device/meterplus.js +78 -59
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.d.ts +2 -0
  35. package/dist/device/motion.d.ts.map +1 -1
  36. package/dist/device/motion.js +76 -57
  37. package/dist/device/motion.js.map +1 -1
  38. package/dist/device/plug.d.ts +2 -0
  39. package/dist/device/plug.d.ts.map +1 -1
  40. package/dist/device/plug.js +133 -107
  41. package/dist/device/plug.js.map +1 -1
  42. package/dist/device/striplight.d.ts +2 -0
  43. package/dist/device/striplight.d.ts.map +1 -1
  44. package/dist/device/striplight.js +224 -195
  45. package/dist/device/striplight.js.map +1 -1
  46. package/dist/irdevice/airconditioner.d.ts +2 -0
  47. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  48. package/dist/irdevice/airconditioner.js +127 -105
  49. package/dist/irdevice/airconditioner.js.map +1 -1
  50. package/dist/irdevice/airpurifier.d.ts +2 -0
  51. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  52. package/dist/irdevice/airpurifier.js +83 -66
  53. package/dist/irdevice/airpurifier.js.map +1 -1
  54. package/dist/irdevice/camera.d.ts +8 -6
  55. package/dist/irdevice/camera.d.ts.map +1 -1
  56. package/dist/irdevice/camera.js +83 -68
  57. package/dist/irdevice/camera.js.map +1 -1
  58. package/dist/irdevice/fan.d.ts +7 -5
  59. package/dist/irdevice/fan.d.ts.map +1 -1
  60. package/dist/irdevice/fan.js +90 -75
  61. package/dist/irdevice/fan.js.map +1 -1
  62. package/dist/irdevice/light.d.ts +8 -6
  63. package/dist/irdevice/light.d.ts.map +1 -1
  64. package/dist/irdevice/light.js +83 -68
  65. package/dist/irdevice/light.js.map +1 -1
  66. package/dist/irdevice/other.d.ts +8 -6
  67. package/dist/irdevice/other.d.ts.map +1 -1
  68. package/dist/irdevice/other.js +93 -78
  69. package/dist/irdevice/other.js.map +1 -1
  70. package/dist/irdevice/tv.d.ts +8 -6
  71. package/dist/irdevice/tv.d.ts.map +1 -1
  72. package/dist/irdevice/tv.js +68 -52
  73. package/dist/irdevice/tv.js.map +1 -1
  74. package/dist/irdevice/vacuumcleaner.d.ts +8 -6
  75. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.js +83 -69
  77. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  78. package/dist/irdevice/waterheater.d.ts +2 -0
  79. package/dist/irdevice/waterheater.d.ts.map +1 -1
  80. package/dist/irdevice/waterheater.js +75 -60
  81. package/dist/irdevice/waterheater.js.map +1 -1
  82. package/dist/settings.d.ts +12 -11
  83. package/dist/settings.d.ts.map +1 -1
  84. package/dist/settings.js.map +1 -1
  85. package/package.json +1 -1
  86. package/src/device/bot.ts +200 -163
  87. package/src/device/colorbulb.ts +252 -221
  88. package/src/device/contact.ts +85 -66
  89. package/src/device/curtain.ts +165 -136
  90. package/src/device/humidifier.ts +126 -115
  91. package/src/device/lock.ts +156 -131
  92. package/src/device/meter.ts +85 -64
  93. package/src/device/meterplus.ts +78 -59
  94. package/src/device/motion.ts +76 -57
  95. package/src/device/plug.ts +132 -107
  96. package/src/device/striplight.ts +226 -198
  97. package/src/irdevice/airconditioner.ts +126 -103
  98. package/src/irdevice/airpurifier.ts +84 -66
  99. package/src/irdevice/camera.ts +84 -68
  100. package/src/irdevice/fan.ts +91 -75
  101. package/src/irdevice/light.ts +84 -68
  102. package/src/irdevice/other.ts +94 -78
  103. package/src/irdevice/tv.ts +69 -53
  104. package/src/irdevice/vacuumcleaner.ts +83 -68
  105. package/src/irdevice/waterheater.ts +76 -60
  106. package/src/settings.ts +12 -11
@@ -22,6 +22,7 @@ export class Others {
22
22
  // Config
23
23
  deviceLogging!: string;
24
24
  otherDeviceType?: string;
25
+ OpenAPI?: boolean;
25
26
 
26
27
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
27
28
  // default placeholders
@@ -44,15 +45,15 @@ export class Others {
44
45
  // get the Television service if it exists, otherwise create a new Television service
45
46
  // you can create multiple services for each accessory
46
47
  if (this.otherDeviceType !== 'Fan') {
47
- this.debugLog(`Other: ${accessory.displayName} Removing Fanv2 Service`);
48
+ this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Removing Fanv2 Service`);
48
49
 
49
50
  if (this.otherDeviceType === undefined) {
50
- this.errorLog(`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`);
51
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`);
51
52
  }
52
53
  this.fanService = this.accessory.getService(this.platform.Service.Fanv2);
53
54
  accessory.removeService(this.fanService!);
54
55
  } else if (!this.fanService && this.otherDeviceType === 'Fan') {
55
- this.debugLog(`Other: ${accessory.displayName} Add Fanv2 Service`);
56
+ this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Add Fanv2 Service`);
56
57
  (this.fanService = this.accessory.getService(this.platform.Service.Fanv2) || this.accessory.addService(this.platform.Service.Fanv2)),
57
58
  `${accessory.displayName} Fan`;
58
59
 
@@ -60,12 +61,12 @@ export class Others {
60
61
 
61
62
  this.fanService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
62
63
  } else {
63
- this.debugLog(`Other: ${accessory.displayName} Fanv2 Service Not Added, deviceType: ${device.other?.deviceType}`);
64
+ this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Fanv2 Service Not Added, deviceType: ${device.other?.deviceType}`);
64
65
  }
65
66
  }
66
67
 
67
68
  async ActiveSet(value: CharacteristicValue): Promise<void> {
68
- this.debugLog(`Other: ${this.accessory.displayName} On: ${value}`);
69
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
69
70
  if (value) {
70
71
  await this.pushOnChanges();
71
72
  } else {
@@ -78,22 +79,22 @@ export class Others {
78
79
 
79
80
  async updateHomeKitCharacteristics(): Promise<void> {
80
81
  if (this.Active === undefined) {
81
- this.debugLog(`Other: ${this.accessory.displayName} Active: ${this.Active}`);
82
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
82
83
  } else {
83
84
  this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
84
- this.debugLog(`Other: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
85
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
85
86
  }
86
87
  }
87
88
 
88
89
  /**
89
90
  * Pushes the requested changes to the SwitchBot API
90
91
  * deviceType commandType Command command parameter Description
91
- * Light: "command" "turnOff" "default" = set to OFF state
92
- * Light: "command" "turnOn" "default" = set to ON state
93
- * Light: "command" "volumeAdd" "default" = volume up
94
- * Light: "command" "volumeSub" "default" = volume down
95
- * Light: "command" "channelAdd" "default" = next channel
96
- * Light: "command" "channelSub" "default" = previous channel
92
+ * Other - "command" "turnOff" "default" = set to OFF state
93
+ * Other - "command" "turnOn" "default" = set to ON state
94
+ * Other - "command" "volumeAdd" "default" = volume up
95
+ * Other - "command" "volumeSub" "default" = volume down
96
+ * Other - "command" "channelAdd" "default" = next channel
97
+ * Other - "command" "channelSub" "default" = previous channel
97
98
  */
98
99
  async pushOnChanges(): Promise<void> {
99
100
  if (this.platform.config.options) {
@@ -108,13 +109,13 @@ export class Others {
108
109
  await this.pushChanges(body);
109
110
  }
110
111
  } else {
111
- this.errorLog(`Other: ${this.accessory.displayName} On Command not set, commandOn: ${this.device.other.commandOn}`);
112
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} On Command not set, commandOn: ${this.device.other.commandOn}`);
112
113
  }
113
114
  } else {
114
- this.errorLog(`Other: ${this.accessory.displayName} On Command not set, other: ${this.device.other}`);
115
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} On Command not set, other: ${this.device.other}`);
115
116
  }
116
117
  } else {
117
- this.errorLog(`Other: ${this.accessory.displayName} On Command not set`);
118
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} On Command not set`);
118
119
  }
119
120
  }
120
121
 
@@ -131,95 +132,98 @@ export class Others {
131
132
  await this.pushChanges(body);
132
133
  }
133
134
  } else {
134
- this.errorLog(`Other: ${this.accessory.displayName} Off Command not set, commandOff: ${this.device.other.commandOff}`);
135
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Off Command not set, commandOff: ${this.device.other.commandOff}`);
135
136
  }
136
137
  } else {
137
- this.errorLog(`Other: ${this.accessory.displayName} Off Command not set, other: ${this.device.other}`);
138
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Off Command not set, other: ${this.device.other}`);
138
139
  }
139
140
  } else {
140
- this.errorLog(`Other: ${this.accessory.displayName} Off Command not set.`);
141
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Off Command not set.`);
141
142
  }
142
143
  }
143
144
 
144
145
  async pushChanges(body): Promise<void> {
145
- try {
146
+ if (this.OpenAPI) {
147
+ try {
146
148
  // Make Push On request to the API
147
- const t = Date.now();
148
- const nonce = 'requestID';
149
- const data = this.platform.config.credentials?.token + t + nonce;
150
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
151
- .update(Buffer.from(data, 'utf-8'))
152
- .digest();
153
- const sign = signTerm.toString('base64');
154
- this.debugLog(`Other: ${this.accessory.displayName} sign: ${sign}`);
155
- this.infoLog(`Other: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
156
- const options = {
157
- hostname: HostDomain,
158
- port: 443,
159
- path: `${DevicePath}/${this.device.deviceId}/commands`,
160
- method: 'POST',
161
- headers: {
162
- 'Authorization': this.platform.config.credentials?.token,
163
- 'sign': sign,
164
- 'nonce': nonce,
165
- 't': t,
166
- 'Content-Type': 'application/json',
167
- 'Content-Length': body.length,
168
- },
169
- };
170
- const req = https.request(options, res => {
171
- this.debugLog(`Other: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
172
- this.statusCode({ res });
173
- res.on('data', d => {
174
- this.debugLog(`Other: ${this.accessory.displayName} d: ${d}`);
149
+ const t = Date.now();
150
+ const nonce = 'requestID';
151
+ const data = this.platform.config.credentials?.token + t + nonce;
152
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
153
+ .update(Buffer.from(data, 'utf-8'))
154
+ .digest();
155
+ const sign = signTerm.toString('base64');
156
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
157
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
158
+ const options = {
159
+ hostname: HostDomain,
160
+ port: 443,
161
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
162
+ method: 'POST',
163
+ headers: {
164
+ 'Authorization': this.platform.config.credentials?.token,
165
+ 'sign': sign,
166
+ 'nonce': nonce,
167
+ 't': t,
168
+ 'Content-Type': 'application/json',
169
+ 'Content-Length': body.length,
170
+ },
171
+ };
172
+ const req = https.request(options, res => {
173
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
174
+ this.statusCode({ res });
175
+ res.on('data', d => {
176
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
177
+ });
175
178
  });
176
- });
177
- req.on('error', (e: any) => {
178
- this.errorLog(`Other: ${this.accessory.displayName} error message: ${e.message}`);
179
- });
180
- req.write(body);
181
- req.end();
182
- this.debugLog(`Other: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
183
- this.updateHomeKitCharacteristics();
184
- } catch (e: any) {
185
- this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
186
- if (this.deviceLogging.includes('debug')) {
187
- this.errorLog(
188
- `Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${superStringify(e.message)}`,
189
- );
179
+ req.on('error', (e: any) => {
180
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
181
+ });
182
+ req.write(body);
183
+ req.end();
184
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
185
+ this.updateHomeKitCharacteristics();
186
+ } catch (e: any) {
187
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
188
+ if (this.deviceLogging.includes('debug')) {
189
+ this.errorLog(
190
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
191
+ + ` Error Message: ${superStringify(e.message)}`,
192
+ );
193
+ }
194
+ this.apiError(e);
190
195
  }
191
- this.apiError(e);
192
196
  }
193
197
  }
194
198
 
195
199
  async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
196
200
  switch (res.statusCode) {
197
201
  case 151:
198
- this.errorLog(`Other: ${this.accessory.displayName} Command not supported by this device type.`);
202
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
199
203
  break;
200
204
  case 152:
201
- this.errorLog(`Other: ${this.accessory.displayName} Device not found.`);
205
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
202
206
  break;
203
207
  case 160:
204
- this.errorLog(`Other: ${this.accessory.displayName} Command is not supported.`);
208
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
205
209
  break;
206
210
  case 161:
207
- this.errorLog(`Other: ${this.accessory.displayName} Device is offline.`);
211
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
208
212
  break;
209
213
  case 171:
210
- this.errorLog(`Other: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
214
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
211
215
  break;
212
216
  case 190:
213
217
  this.errorLog(
214
- `Other: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
218
+ `${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
215
219
  ` with server, Or command: ${superStringify(res)} format is invalid`,
216
220
  );
217
221
  break;
218
222
  case 100:
219
- this.debugLog(`Other: ${this.accessory.displayName} Command successfully sent.`);
223
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
220
224
  break;
221
225
  default:
222
- this.debugLog(`Other: ${this.accessory.displayName} Unknown statusCode.`);
226
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
223
227
  }
224
228
  }
225
229
 
@@ -232,13 +236,22 @@ export class Others {
232
236
  if (device.other?.deviceType) {
233
237
  this.otherDeviceType = this.accessory.context.deviceType = device.other.deviceType;
234
238
  if (this.deviceLogging.includes('debug') || this.deviceLogging === 'standard') {
235
- this.warnLog(`Other: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}`);
239
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}`);
236
240
  }
237
241
  } else {
238
- this.errorLog(`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.other?.deviceType}`);
242
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.other?.deviceType}`);
239
243
  }
240
244
  }
241
245
 
246
+ async openAPI() {
247
+ if (!this.device.openAPI) {
248
+ this.OpenAPI = true;
249
+ } else {
250
+ this.OpenAPI = this.device.openAPI;
251
+ }
252
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
253
+ }
254
+
242
255
  async config(device: irdevice & irDevicesConfig): Promise<void> {
243
256
  let config = {};
244
257
  if (device.other) {
@@ -247,24 +260,27 @@ export class Others {
247
260
  if (device.logging !== undefined) {
248
261
  config['logging'] = device.logging;
249
262
  }
263
+ if (device.openAPI !== undefined) {
264
+ config['openAPI'] = device.openAPI;
265
+ }
250
266
  if (Object.entries(config).length !== 0) {
251
- this.infoLog(`Other: ${this.accessory.displayName} Config: ${superStringify(config)}`);
267
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
252
268
  }
253
269
  }
254
270
 
255
271
  async logs(device: irdevice & irDevicesConfig): Promise<void> {
256
272
  if (this.platform.debugMode) {
257
273
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
258
- this.debugLog(`Other: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
274
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
259
275
  } else if (device.logging) {
260
276
  this.deviceLogging = this.accessory.context.logging = device.logging;
261
- this.debugLog(`Other: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
277
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
262
278
  } else if (this.platform.config.options?.logging) {
263
279
  this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
264
- this.debugLog(`Other: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
280
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
265
281
  } else {
266
282
  this.deviceLogging = this.accessory.context.logging = 'standard';
267
- this.debugLog(`Other: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
283
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
268
284
  }
269
285
  }
270
286
 
@@ -26,6 +26,7 @@ export class TV {
26
26
 
27
27
  // Config
28
28
  deviceLogging!: string;
29
+ OpenAPI?: boolean;
29
30
 
30
31
  constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
31
32
  // default placeholders
@@ -229,12 +230,12 @@ export class TV {
229
230
  /**
230
231
  * Pushes the requested changes to the SwitchBot API
231
232
  * deviceType commandType Command command parameter Description
232
- * TV: "command" "turnOff" "default" = set to OFF state
233
- * TV: "command" "turnOn" "default" = set to ON state
234
- * TV: "command" "volumeAdd" "default" = volume up
235
- * TV: "command" "volumeSub" "default" = volume down
236
- * TV: "command" "channelAdd" "default" = next channel
237
- * TV: "command" "channelSub" "default" = previous channel
233
+ * TV - "command" "turnOff" "default" = set to OFF state
234
+ * TV - "command" "turnOn" "default" = set to ON state
235
+ * TV - "command" "volumeAdd" "default" = volume up
236
+ * TV - "command" "volumeSub" "default" = volume down
237
+ * TV - "command" "channelAdd" "default" = next channel
238
+ * TV - "command" "channelSub" "default" = previous channel
238
239
  */
239
240
  async pushTvOnChanges(): Promise<void> {
240
241
  if (this.Active !== 1) {
@@ -338,54 +339,57 @@ export class TV {
338
339
  }
339
340
 
340
341
  async pushTVChanges(body): Promise<void> {
341
- try {
342
- // Make Push On request to the API
343
- const t = Date.now();
344
- const nonce = 'requestID';
345
- const data = this.platform.config.credentials?.token + t + nonce;
346
- const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
347
- .update(Buffer.from(data, 'utf-8'))
348
- .digest();
349
- const sign = signTerm.toString('base64');
350
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
351
- this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
352
- const options = {
353
- hostname: HostDomain,
354
- port: 443,
355
- path: `${DevicePath}/${this.device.deviceId}/commands`,
356
- method: 'POST',
357
- headers: {
358
- 'Authorization': this.platform.config.credentials?.token,
359
- 'sign': sign,
360
- 'nonce': nonce,
361
- 't': t,
362
- 'Content-Type': 'application/json',
363
- 'Content-Length': body.length,
364
- },
365
- };
366
- const req = https.request(options, res => {
367
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
368
- this.statusCode({ res });
369
- res.on('data', d => {
370
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
371
- });
372
- });
373
- req.on('error', (e: any) => {
374
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
375
- });
376
- req.write(body);
377
- req.end();
378
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
379
- this.updateHomeKitCharacteristics();
380
- } catch (e: any) {
381
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
382
- if (this.deviceLogging.includes('debug')) {
383
- this.errorLog(
384
- `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
342
+ if (this.OpenAPI) {
343
+ {
344
+ try {
345
+ // Make Push On request to the API
346
+ const t = Date.now();
347
+ const nonce = 'requestID';
348
+ const data = this.platform.config.credentials?.token + t + nonce;
349
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
350
+ .update(Buffer.from(data, 'utf-8'))
351
+ .digest();
352
+ const sign = signTerm.toString('base64');
353
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
354
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
355
+ const options = {
356
+ hostname: HostDomain,
357
+ port: 443,
358
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
359
+ method: 'POST',
360
+ headers: {
361
+ 'Authorization': this.platform.config.credentials?.token,
362
+ 'sign': sign,
363
+ 'nonce': nonce,
364
+ 't': t,
365
+ 'Content-Type': 'application/json',
366
+ 'Content-Length': body.length,
367
+ },
368
+ };
369
+ const req = https.request(options, res => {
370
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
371
+ this.statusCode({ res });
372
+ res.on('data', d => {
373
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
374
+ });
375
+ });
376
+ req.on('error', (e: any) => {
377
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
378
+ });
379
+ req.write(body);
380
+ req.end();
381
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
382
+ this.updateHomeKitCharacteristics();
383
+ } catch (e: any) {
384
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
385
+ if (this.deviceLogging.includes('debug')) {
386
+ this.errorLog(
387
+ `${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
385
388
  ` Error Message: ${superStringify(e.message)}`,
386
- );
387
- }
388
- this.apiError(e);
389
+ );
390
+ }
391
+ this.apiError(e);
392
+ }}
389
393
  }
390
394
  }
391
395
 
@@ -427,6 +431,15 @@ export class TV {
427
431
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
428
432
  }
429
433
 
434
+ async openAPI() {
435
+ if (!this.device.openAPI) {
436
+ this.OpenAPI = true;
437
+ } else {
438
+ this.OpenAPI = this.device.openAPI;
439
+ }
440
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
441
+ }
442
+
430
443
  async config(device: irdevice & irDevicesConfig): Promise<void> {
431
444
  let config = {};
432
445
  if (device.irtv) {
@@ -435,6 +448,9 @@ export class TV {
435
448
  if (device.logging !== undefined) {
436
449
  config['logging'] = device.logging;
437
450
  }
451
+ if (device.openAPI !== undefined) {
452
+ config['openAPI'] = device.openAPI;
453
+ }
438
454
  if (Object.entries(config).length !== 0) {
439
455
  this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
440
456
  }