@switchbot/homebridge-switchbot 1.15.1-beta.7 → 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.
- package/.prettierrc +1 -1
- package/dist/device/bot.d.ts +8 -7
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +83 -11
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +8 -7
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +182 -23
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +3 -3
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +50 -7
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +9 -8
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +86 -14
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +8 -7
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +152 -27
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +8 -7
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +84 -12
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +4 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +51 -8
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +3 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +49 -6
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +3 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +49 -9
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +8 -7
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +83 -11
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +8 -7
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +149 -19
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +5 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +40 -6
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -4
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +40 -6
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +5 -4
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +40 -6
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -6
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +40 -6
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +5 -4
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +40 -6
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +5 -4
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -6
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -6
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +40 -6
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -4
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +40 -6
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -4
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +40 -6
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +3 -5
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +141 -95
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -16
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +3 -3
- package/dist/settings.js.map +1 -1
- package/package.json +6 -7
- package/src/device/bot.ts +87 -15
- package/src/device/colorbulb.ts +186 -41
- package/src/device/contact.ts +49 -10
- package/src/device/curtain.ts +92 -19
- package/src/device/humidifier.ts +164 -30
- package/src/device/lock.ts +88 -16
- package/src/device/meter.ts +51 -12
- package/src/device/meterplus.ts +48 -9
- package/src/device/motion.ts +48 -12
- package/src/device/plug.ts +87 -15
- package/src/device/striplight.ts +161 -24
- package/src/irdevice/airconditioner.ts +43 -8
- package/src/irdevice/airpurifier.ts +43 -8
- package/src/irdevice/camera.ts +43 -8
- package/src/irdevice/fan.ts +44 -9
- package/src/irdevice/light.ts +43 -8
- package/src/irdevice/other.ts +43 -8
- package/src/irdevice/tv.ts +44 -9
- package/src/irdevice/vacuumcleaner.ts +43 -8
- package/src/irdevice/waterheater.ts +43 -8
- package/src/platform.ts +154 -108
- package/src/settings.ts +6 -10
package/src/irdevice/fan.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
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 {
|
|
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!:
|
|
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
|
|
243
|
-
|
|
244
|
-
this.
|
|
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(
|
|
258
|
-
switch (
|
|
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(
|
|
312
|
+
` with server, Or command: ${JSON.stringify(res)} format is invalid`,
|
|
278
313
|
);
|
|
279
314
|
break;
|
|
280
315
|
case 100:
|
package/src/irdevice/light.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import https from 'https';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import { IncomingMessage } from 'http';
|
|
2
4
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { irDevicesConfig,
|
|
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
|
|
149
|
-
|
|
150
|
-
this.
|
|
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(
|
|
166
|
-
switch (
|
|
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(
|
|
220
|
+
` with server, Or command: ${JSON.stringify(res)} format is invalid`,
|
|
186
221
|
);
|
|
187
222
|
break;
|
|
188
223
|
case 100:
|
package/src/irdevice/other.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import https from 'https';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import { IncomingMessage } from 'http';
|
|
2
4
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { irDevicesConfig,
|
|
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
|
|
150
|
-
|
|
151
|
-
this.
|
|
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(
|
|
165
|
-
switch (
|
|
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(
|
|
219
|
+
` with server, Or command: ${JSON.stringify(res)} format is invalid`,
|
|
185
220
|
);
|
|
186
221
|
break;
|
|
187
222
|
case 100:
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
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 {
|
|
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!:
|
|
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
|
|
346
|
-
|
|
347
|
-
this.
|
|
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(
|
|
362
|
-
switch (
|
|
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(
|
|
417
|
+
` Or command: ${JSON.stringify(res)} format is invalid`,
|
|
383
418
|
);
|
|
384
419
|
break;
|
|
385
420
|
case 100:
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import https from 'https';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import { IncomingMessage } from 'http';
|
|
2
4
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { irDevicesConfig,
|
|
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
|
|
116
|
-
|
|
117
|
-
this.
|
|
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(
|
|
134
|
-
switch (
|
|
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(
|
|
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
|
|
1
|
+
import https from 'https';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import { IncomingMessage } from 'http';
|
|
2
4
|
import { SwitchBotPlatform } from '../platform';
|
|
3
|
-
import { irDevicesConfig,
|
|
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
|
|
123
|
-
|
|
124
|
-
this.
|
|
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(
|
|
138
|
-
switch (
|
|
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(
|
|
192
|
+
` with server, Or command: ${JSON.stringify(res)} format is invalid`,
|
|
158
193
|
);
|
|
159
194
|
break;
|
|
160
195
|
case 100:
|