@switchbot/homebridge-switchbot 1.15.1-beta.6 → 1.15.1-beta.8

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 (112) hide show
  1. package/.prettierrc +1 -1
  2. package/dist/device/bot.d.ts +8 -7
  3. package/dist/device/bot.d.ts.map +1 -1
  4. package/dist/device/bot.js +83 -11
  5. package/dist/device/bot.js.map +1 -1
  6. package/dist/device/colorbulb.d.ts +8 -7
  7. package/dist/device/colorbulb.d.ts.map +1 -1
  8. package/dist/device/colorbulb.js +182 -23
  9. package/dist/device/colorbulb.js.map +1 -1
  10. package/dist/device/contact.d.ts +3 -3
  11. package/dist/device/contact.d.ts.map +1 -1
  12. package/dist/device/contact.js +50 -7
  13. package/dist/device/contact.js.map +1 -1
  14. package/dist/device/curtain.d.ts +9 -8
  15. package/dist/device/curtain.d.ts.map +1 -1
  16. package/dist/device/curtain.js +86 -14
  17. package/dist/device/curtain.js.map +1 -1
  18. package/dist/device/humidifier.d.ts +8 -7
  19. package/dist/device/humidifier.d.ts.map +1 -1
  20. package/dist/device/humidifier.js +152 -27
  21. package/dist/device/humidifier.js.map +1 -1
  22. package/dist/device/lock.d.ts +8 -7
  23. package/dist/device/lock.d.ts.map +1 -1
  24. package/dist/device/lock.js +84 -12
  25. package/dist/device/lock.js.map +1 -1
  26. package/dist/device/meter.d.ts +4 -4
  27. package/dist/device/meter.d.ts.map +1 -1
  28. package/dist/device/meter.js +51 -8
  29. package/dist/device/meter.js.map +1 -1
  30. package/dist/device/meterplus.d.ts +3 -3
  31. package/dist/device/meterplus.d.ts.map +1 -1
  32. package/dist/device/meterplus.js +49 -6
  33. package/dist/device/meterplus.js.map +1 -1
  34. package/dist/device/motion.d.ts +3 -3
  35. package/dist/device/motion.d.ts.map +1 -1
  36. package/dist/device/motion.js +49 -9
  37. package/dist/device/motion.js.map +1 -1
  38. package/dist/device/plug.d.ts +8 -7
  39. package/dist/device/plug.d.ts.map +1 -1
  40. package/dist/device/plug.js +83 -11
  41. package/dist/device/plug.js.map +1 -1
  42. package/dist/device/striplight.d.ts +8 -7
  43. package/dist/device/striplight.d.ts.map +1 -1
  44. package/dist/device/striplight.js +149 -19
  45. package/dist/device/striplight.js.map +1 -1
  46. package/dist/irdevice/airconditioner.d.ts +5 -4
  47. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  48. package/dist/irdevice/airconditioner.js +40 -6
  49. package/dist/irdevice/airconditioner.js.map +1 -1
  50. package/dist/irdevice/airpurifier.d.ts +5 -4
  51. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  52. package/dist/irdevice/airpurifier.js +40 -6
  53. package/dist/irdevice/airpurifier.js.map +1 -1
  54. package/dist/irdevice/camera.d.ts +5 -4
  55. package/dist/irdevice/camera.d.ts.map +1 -1
  56. package/dist/irdevice/camera.js +40 -6
  57. package/dist/irdevice/camera.js.map +1 -1
  58. package/dist/irdevice/fan.d.ts +7 -6
  59. package/dist/irdevice/fan.d.ts.map +1 -1
  60. package/dist/irdevice/fan.js +40 -6
  61. package/dist/irdevice/fan.js.map +1 -1
  62. package/dist/irdevice/light.d.ts +5 -4
  63. package/dist/irdevice/light.d.ts.map +1 -1
  64. package/dist/irdevice/light.js +40 -6
  65. package/dist/irdevice/light.js.map +1 -1
  66. package/dist/irdevice/other.d.ts +5 -4
  67. package/dist/irdevice/other.d.ts.map +1 -1
  68. package/dist/irdevice/other.js +40 -6
  69. package/dist/irdevice/other.js.map +1 -1
  70. package/dist/irdevice/tv.d.ts +7 -6
  71. package/dist/irdevice/tv.d.ts.map +1 -1
  72. package/dist/irdevice/tv.js +40 -6
  73. package/dist/irdevice/tv.js.map +1 -1
  74. package/dist/irdevice/vacuumcleaner.d.ts +5 -4
  75. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  76. package/dist/irdevice/vacuumcleaner.js +40 -6
  77. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  78. package/dist/irdevice/waterheater.d.ts +5 -4
  79. package/dist/irdevice/waterheater.d.ts.map +1 -1
  80. package/dist/irdevice/waterheater.js +40 -6
  81. package/dist/irdevice/waterheater.js.map +1 -1
  82. package/dist/platform.d.ts +3 -5
  83. package/dist/platform.d.ts.map +1 -1
  84. package/dist/platform.js +142 -92
  85. package/dist/platform.js.map +1 -1
  86. package/dist/settings.d.ts +2 -16
  87. package/dist/settings.d.ts.map +1 -1
  88. package/dist/settings.js +3 -3
  89. package/dist/settings.js.map +1 -1
  90. package/package.json +6 -7
  91. package/src/device/bot.ts +87 -15
  92. package/src/device/colorbulb.ts +186 -41
  93. package/src/device/contact.ts +49 -10
  94. package/src/device/curtain.ts +92 -19
  95. package/src/device/humidifier.ts +164 -30
  96. package/src/device/lock.ts +88 -16
  97. package/src/device/meter.ts +51 -12
  98. package/src/device/meterplus.ts +48 -9
  99. package/src/device/motion.ts +48 -12
  100. package/src/device/plug.ts +87 -15
  101. package/src/device/striplight.ts +161 -24
  102. package/src/irdevice/airconditioner.ts +43 -8
  103. package/src/irdevice/airpurifier.ts +43 -8
  104. package/src/irdevice/camera.ts +43 -8
  105. package/src/irdevice/fan.ts +44 -9
  106. package/src/irdevice/light.ts +43 -8
  107. package/src/irdevice/other.ts +43 -8
  108. package/src/irdevice/tv.ts +44 -9
  109. package/src/irdevice/vacuumcleaner.ts +43 -8
  110. package/src/irdevice/waterheater.ts +43 -8
  111. package/src/platform.ts +155 -105
  112. package/src/settings.ts +6 -10
@@ -1,7 +1,9 @@
1
- import { AxiosResponse } from 'axios';
1
+ import https from 'https';
2
+ import crypto from 'crypto';
3
+ import { IncomingMessage } from 'http';
2
4
  import { SwitchBotPlatform } from '../platform';
3
5
  import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
- import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
6
+ import { irdevice, irDevicesConfig, payload, HostDomain, DevicePath } from '../settings';
5
7
 
6
8
  /**
7
9
  * Platform Accessory
@@ -21,7 +23,7 @@ export class Fan {
21
23
  RotationDirection!: CharacteristicValue;
22
24
 
23
25
  // Others
24
- deviceStatus!: deviceStatusResponse;
26
+ deviceStatus!: any;
25
27
 
26
28
  // Config
27
29
  minStep?: number;
@@ -239,9 +241,42 @@ export class Fan {
239
241
  );
240
242
 
241
243
  // Make the API request
242
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
243
- this.debugLog(`Fan: ${this.accessory.displayName} pushTVChanges: ${push.data}`);
244
- this.statusCode(push);
244
+ const t = Date.now();
245
+ const nonce = 'requestID';
246
+ const data = this.platform.config.credentials?.token + t + nonce;
247
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
248
+ const sign = signTerm.toString('base64');
249
+ this.debugLog(`Fan: ${this.accessory.displayName} sign: ${sign}`);
250
+ const options = {
251
+ hostname: HostDomain,
252
+ port: 443,
253
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
254
+ method: 'POST',
255
+ headers: {
256
+ Authorization: this.platform.config.credentials?.token,
257
+ sign: sign,
258
+ nonce: nonce,
259
+ t: t,
260
+ 'Content-Type': 'application/json',
261
+ },
262
+ };
263
+
264
+ const req = https.request(options, (res) => {
265
+ this.debugLog(`Fan: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
266
+ this.statusCode({ res });
267
+ res.on('data', (d) => {
268
+ this.debugLog(`an: ${this.accessory.displayName} d: ${d}`);
269
+ });
270
+ });
271
+
272
+ req.on('error', (error) => {
273
+ this.errorLog(`Fan: ${this.accessory.displayName} error: ${error}`);
274
+ });
275
+
276
+ req.write(payload);
277
+ req.end();
278
+
279
+ this.debugLog(`Fan: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
245
280
  this.updateHomeKitCharacteristics();
246
281
  } catch (e: any) {
247
282
  this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
@@ -254,8 +289,8 @@ export class Fan {
254
289
  }
255
290
  }
256
291
 
257
- async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
258
- switch (push.data.statusCode) {
292
+ async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
293
+ switch (res.statusCode) {
259
294
  case 151:
260
295
  this.errorLog(`Fan: ${this.accessory.displayName} Command not supported by this device type.`);
261
296
  break;
@@ -274,7 +309,7 @@ export class Fan {
274
309
  case 190:
275
310
  this.errorLog(
276
311
  `Fan: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
277
- ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
312
+ ` with server, Or command: ${JSON.stringify(res)} format is invalid`,
278
313
  );
279
314
  break;
280
315
  case 100:
@@ -1,6 +1,8 @@
1
- import { AxiosResponse } from 'axios';
1
+ import https from 'https';
2
+ import crypto from 'crypto';
3
+ import { IncomingMessage } from 'http';
2
4
  import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
5
+ import { irDevicesConfig, irdevice, payload, HostDomain, DevicePath } from '../settings';
4
6
  import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
7
 
6
8
  /**
@@ -145,9 +147,42 @@ export class Light {
145
147
  );
146
148
 
147
149
  // Make the API request
148
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
149
- this.debugLog(`Light: ${this.accessory.displayName} pushChanges: ${push.data}`);
150
- this.statusCode(push);
150
+ const t = Date.now();
151
+ const nonce = 'requestID';
152
+ const data = this.platform.config.credentials?.token + t + nonce;
153
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
154
+ const sign = signTerm.toString('base64');
155
+ this.debugLog(`Light: ${this.accessory.displayName} sign: ${sign}`);
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
+ },
168
+ };
169
+
170
+ const req = https.request(options, (res) => {
171
+ this.debugLog(`Light: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
172
+ this.statusCode({ res });
173
+ res.on('data', (d) => {
174
+ this.debugLog(`Light: ${this.accessory.displayName} d: ${d}`);
175
+ });
176
+ });
177
+
178
+ req.on('error', (error) => {
179
+ this.errorLog(`Light: ${this.accessory.displayName} error: ${error}`);
180
+ });
181
+
182
+ req.write(payload);
183
+ req.end();
184
+
185
+ this.debugLog(`Light: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
151
186
  this.OnCached = this.On;
152
187
  this.accessory.context.On = this.OnCached;
153
188
  this.updateHomeKitCharacteristics();
@@ -162,8 +197,8 @@ export class Light {
162
197
  }
163
198
  }
164
199
 
165
- async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
166
- switch (push.data.statusCode) {
200
+ async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
201
+ switch (res.statusCode) {
167
202
  case 151:
168
203
  this.errorLog(`Light: ${this.accessory.displayName} Command not supported by this device type.`);
169
204
  break;
@@ -182,7 +217,7 @@ export class Light {
182
217
  case 190:
183
218
  this.errorLog(
184
219
  `Light: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
185
- ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
220
+ ` with server, Or command: ${JSON.stringify(res)} format is invalid`,
186
221
  );
187
222
  break;
188
223
  case 100:
@@ -1,6 +1,8 @@
1
- import { AxiosResponse } from 'axios';
1
+ import https from 'https';
2
+ import crypto from 'crypto';
3
+ import { IncomingMessage } from 'http';
2
4
  import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
5
+ import { irDevicesConfig, irdevice, payload, HostDomain, DevicePath } from '../settings';
4
6
  import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
7
 
6
8
  /**
@@ -146,9 +148,42 @@ export class Others {
146
148
  );
147
149
 
148
150
  // Make the API request
149
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
150
- this.debugLog(`Other: ${this.accessory.displayName} pushChanges: ${push.data}`);
151
- this.statusCode(push);
151
+ const t = Date.now();
152
+ const nonce = 'requestID';
153
+ const data = this.platform.config.credentials?.token + t + nonce;
154
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
155
+ const sign = signTerm.toString('base64');
156
+ this.debugLog(`Other: ${this.accessory.displayName} sign: ${sign}`);
157
+ const options = {
158
+ hostname: HostDomain,
159
+ port: 443,
160
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
161
+ method: 'POST',
162
+ headers: {
163
+ Authorization: this.platform.config.credentials?.token,
164
+ sign: sign,
165
+ nonce: nonce,
166
+ t: t,
167
+ 'Content-Type': 'application/json',
168
+ },
169
+ };
170
+
171
+ const req = https.request(options, (res) => {
172
+ this.debugLog(`Other: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
173
+ this.statusCode({ res });
174
+ res.on('data', (d) => {
175
+ this.debugLog(`Other: ${this.accessory.displayName} d: ${d}`);
176
+ });
177
+ });
178
+
179
+ req.on('error', (error) => {
180
+ this.errorLog(`Other: ${this.accessory.displayName} error: ${error}`);
181
+ });
182
+
183
+ req.write(payload);
184
+ req.end();
185
+
186
+ this.debugLog(`Other: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
152
187
  this.updateHomeKitCharacteristics();
153
188
  } catch (e: any) {
154
189
  this.errorLog(`Other: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
@@ -161,8 +196,8 @@ export class Others {
161
196
  }
162
197
  }
163
198
 
164
- async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
165
- switch (push.data.statusCode) {
199
+ async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
200
+ switch (res.statusCode) {
166
201
  case 151:
167
202
  this.errorLog(`Other: ${this.accessory.displayName} Command not supported by this device type.`);
168
203
  break;
@@ -181,7 +216,7 @@ export class Others {
181
216
  case 190:
182
217
  this.errorLog(
183
218
  `Other: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
184
- ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
219
+ ` with server, Or command: ${JSON.stringify(res)} format is invalid`,
185
220
  );
186
221
  break;
187
222
  case 100:
@@ -1,7 +1,9 @@
1
- import { AxiosResponse } from 'axios';
1
+ import https from 'https';
2
+ import crypto from 'crypto';
3
+ import { IncomingMessage } from 'http';
2
4
  import { SwitchBotPlatform } from '../platform';
3
5
  import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
- import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
6
+ import { irdevice, irDevicesConfig, payload, HostDomain, DevicePath } from '../settings';
5
7
 
6
8
  /**
7
9
  * Platform Accessory
@@ -19,7 +21,7 @@ export class TV {
19
21
  ActiveIdentifier!: CharacteristicValue;
20
22
 
21
23
  // Others
22
- deviceStatus!: deviceStatusResponse;
24
+ deviceStatus!: any;
23
25
 
24
26
  // Config
25
27
  deviceLogging!: string;
@@ -342,9 +344,42 @@ export class TV {
342
344
  );
343
345
 
344
346
  // Make the API request
345
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
346
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges: ${push.data}`);
347
- this.statusCode(push);
347
+ const t = Date.now();
348
+ const nonce = 'requestID';
349
+ const data = this.platform.config.credentials?.token + t + nonce;
350
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
351
+ const sign = signTerm.toString('base64');
352
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
353
+ const options = {
354
+ hostname: HostDomain,
355
+ port: 443,
356
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
357
+ method: 'POST',
358
+ headers: {
359
+ Authorization: this.platform.config.credentials?.token,
360
+ sign: sign,
361
+ nonce: nonce,
362
+ t: t,
363
+ 'Content-Type': 'application/json',
364
+ },
365
+ };
366
+
367
+ const req = https.request(options, (res) => {
368
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
369
+ this.statusCode({ res });
370
+ res.on('data', (d) => {
371
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
372
+ });
373
+ });
374
+
375
+ req.on('error', (error) => {
376
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error: ${error}`);
377
+ });
378
+
379
+ req.write(payload);
380
+ req.end();
381
+
382
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
348
383
  this.updateHomeKitCharacteristics();
349
384
  } catch (e: any) {
350
385
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
@@ -358,8 +393,8 @@ export class TV {
358
393
  }
359
394
  }
360
395
 
361
- async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
362
- switch (push.data.statusCode) {
396
+ async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
397
+ switch (res.statusCode) {
363
398
  case 151:
364
399
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
365
400
  break;
@@ -379,7 +414,7 @@ export class TV {
379
414
  this.errorLog(
380
415
  `${this.device.remoteType}: ` +
381
416
  `${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
382
- ` Or command: ${JSON.stringify(push.data)} format is invalid`,
417
+ ` Or command: ${JSON.stringify(res)} format is invalid`,
383
418
  );
384
419
  break;
385
420
  case 100:
@@ -1,6 +1,8 @@
1
- import { AxiosResponse } from 'axios';
1
+ import https from 'https';
2
+ import crypto from 'crypto';
3
+ import { IncomingMessage } from 'http';
2
4
  import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
5
+ import { irDevicesConfig, irdevice, payload, HostDomain, DevicePath } from '../settings';
4
6
  import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
7
 
6
8
  /**
@@ -112,9 +114,42 @@ export class VacuumCleaner {
112
114
  );
113
115
 
114
116
  // Make the API request
115
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
116
- this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} pushChanges: ${push.data}`);
117
- this.statusCode(push);
117
+ const t = Date.now();
118
+ const nonce = 'requestID';
119
+ const data = this.platform.config.credentials?.token + t + nonce;
120
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
121
+ const sign = signTerm.toString('base64');
122
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} sign: ${sign}`);
123
+ const options = {
124
+ hostname: HostDomain,
125
+ port: 443,
126
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
127
+ method: 'POST',
128
+ headers: {
129
+ 'Authorization': this.platform.config.credentials?.token,
130
+ 'sign': sign,
131
+ 'nonce': nonce,
132
+ 't': t,
133
+ 'Content-Type': 'application/json',
134
+ },
135
+ };
136
+
137
+ const req = https.request(options, (res) => {
138
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
139
+ this.statusCode({ res });
140
+ res.on('data', (d) => {
141
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} d: ${d}`);
142
+ });
143
+ });
144
+
145
+ req.on('error', (error) => {
146
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} error: ${error}`);
147
+ });
148
+
149
+ req.write(payload);
150
+ req.end();
151
+
152
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
118
153
  this.OnCached = this.On;
119
154
  this.accessory.context.On = this.OnCached;
120
155
  this.updateHomeKitCharacteristics();
@@ -130,8 +165,8 @@ export class VacuumCleaner {
130
165
  }
131
166
  }
132
167
 
133
- async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
134
- switch (push.data.statusCode) {
168
+ async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
169
+ switch (res.statusCode) {
135
170
  case 151:
136
171
  this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`);
137
172
  break;
@@ -150,7 +185,7 @@ export class VacuumCleaner {
150
185
  case 190:
151
186
  this.errorLog(
152
187
  `Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
153
- ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
188
+ ` with server, Or command: ${JSON.stringify(res)} format is invalid`,
154
189
  );
155
190
  break;
156
191
  case 100:
@@ -1,6 +1,8 @@
1
- import { AxiosResponse } from 'axios';
1
+ import https from 'https';
2
+ import crypto from 'crypto';
3
+ import { IncomingMessage } from 'http';
2
4
  import { SwitchBotPlatform } from '../platform';
3
- import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
5
+ import { irDevicesConfig, irdevice, payload, HostDomain, DevicePath } from '../settings';
4
6
  import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
7
 
6
8
  /**
@@ -119,9 +121,42 @@ export class WaterHeater {
119
121
  );
120
122
 
121
123
  // Make the API request
122
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
123
- this.debugLog(`Water Heater: ${this.accessory.displayName} pushChanges: ${push.data}`);
124
- this.statusCode(push);
124
+ const t = Date.now();
125
+ const nonce = 'requestID';
126
+ const data = this.platform.config.credentials?.token + t + nonce;
127
+ const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
128
+ const sign = signTerm.toString('base64');
129
+ this.debugLog(`Water Heater: ${this.accessory.displayName} sign: ${sign}`);
130
+ const options = {
131
+ hostname: HostDomain,
132
+ port: 443,
133
+ path: `${DevicePath}/${this.device.deviceId}/commands`,
134
+ method: 'POST',
135
+ headers: {
136
+ Authorization: this.platform.config.credentials?.token,
137
+ sign: sign,
138
+ nonce: nonce,
139
+ t: t,
140
+ 'Content-Type': 'application/json',
141
+ },
142
+ };
143
+
144
+ const req = https.request(options, (res) => {
145
+ this.debugLog(`Water Heater: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
146
+ this.statusCode({ res });
147
+ res.on('data', (d) => {
148
+ this.debugLog(`Water Heater: ${this.accessory.displayName} d: ${d}`);
149
+ });
150
+ });
151
+
152
+ req.on('error', (error) => {
153
+ this.errorLog(`Water Heater: ${this.accessory.displayName} error: ${error}`);
154
+ });
155
+
156
+ req.write(payload);
157
+ req.end();
158
+
159
+ this.debugLog(`Water Heater: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
125
160
  this.updateHomeKitCharacteristics();
126
161
  } catch (e: any) {
127
162
  this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
@@ -134,8 +169,8 @@ export class WaterHeater {
134
169
  }
135
170
  }
136
171
 
137
- async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
138
- switch (push.data.statusCode) {
172
+ async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
173
+ switch (res.statusCode) {
139
174
  case 151:
140
175
  this.errorLog(`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`);
141
176
  break;
@@ -154,7 +189,7 @@ export class WaterHeater {
154
189
  case 190:
155
190
  this.errorLog(
156
191
  `Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
157
- ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
192
+ ` with server, Or command: ${JSON.stringify(res)} format is invalid`,
158
193
  );
159
194
  break;
160
195
  case 100: