@switchbot/homebridge-switchbot 2.6.0-beta.4 → 2.6.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.
- package/.vscode/tasks.json +13 -0
- package/CHANGELOG.md +4 -2
- package/README.md +18 -9
- package/dist/device/blindtilt.d.ts +1 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +80 -140
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +79 -138
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +2 -6
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +157 -304
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -6
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +164 -311
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +1 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +36 -72
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +78 -138
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +2 -6
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +30 -63
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +1 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +115 -228
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +38 -74
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/{striplight.d.ts → lightstrip.d.ts} +2 -10
- package/dist/device/lightstrip.d.ts.map +1 -0
- package/dist/device/{striplight.js → lightstrip.js} +138 -194
- package/dist/device/lightstrip.js.map +1 -0
- package/dist/device/lock.d.ts +1 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +66 -126
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +1 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +38 -74
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +39 -75
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +1 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +35 -72
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +65 -126
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +79 -151
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +3 -7
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +34 -62
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +3 -7
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +31 -59
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -5
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +30 -57
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -6
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +39 -66
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -5
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +32 -59
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -5
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +30 -57
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +3 -7
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +46 -76
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +30 -58
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -23
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +41 -74
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -5
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +156 -149
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +5 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +122 -181
- package/src/device/bot.ts +96 -149
- package/src/device/ceilinglight.ts +172 -315
- package/src/device/colorbulb.ts +178 -324
- package/src/device/contact.ts +48 -78
- package/src/device/curtain.ts +93 -148
- package/src/device/hub.ts +34 -63
- package/src/device/humidifier.ts +135 -243
- package/src/device/iosensor.ts +49 -79
- package/src/device/{striplight.ts → lightstrip.ts} +148 -200
- package/src/device/lock.ts +78 -134
- package/src/device/meter.ts +48 -78
- package/src/device/meterplus.ts +50 -80
- package/src/device/motion.ts +46 -77
- package/src/device/plug.ts +76 -134
- package/src/device/robotvacuumcleaner.ts +91 -159
- package/src/irdevice/airconditioner.ts +56 -81
- package/src/irdevice/airpurifier.ts +41 -67
- package/src/irdevice/camera.ts +35 -60
- package/src/irdevice/fan.ts +46 -71
- package/src/irdevice/light.ts +38 -63
- package/src/irdevice/other.ts +35 -60
- package/src/irdevice/tv.ts +52 -80
- package/src/irdevice/vacuumcleaner.ts +36 -62
- package/src/irdevice/waterheater.ts +46 -76
- package/src/platform.ts +144 -158
- package/src/settings.ts +5 -0
- package/.github/npm-version-script.js +0 -81
- package/dist/device/striplight.d.ts.map +0 -1
- package/dist/device/striplight.js.map +0 -1
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import https from 'https';
|
|
2
|
-
import crypto from 'crypto';
|
|
3
1
|
import { Context } from 'vm';
|
|
4
|
-
import {
|
|
2
|
+
import { request } from 'undici';
|
|
3
|
+
import { sleep } from '../utils';
|
|
5
4
|
import { interval, Subject } from 'rxjs';
|
|
6
|
-
import superStringify from 'super-stringify';
|
|
7
5
|
import { SwitchBotPlatform } from '../platform';
|
|
8
6
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
9
7
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
10
|
-
import { device, devicesConfig, deviceStatus, ad, serviceData, switchbot,
|
|
11
|
-
import { sleep } from '../utils';
|
|
8
|
+
import { device, devicesConfig, deviceStatus, ad, serviceData, switchbot, Devices } from '../settings';
|
|
12
9
|
|
|
13
10
|
export class RobotVacuumCleaner {
|
|
14
11
|
// Services
|
|
@@ -130,13 +127,13 @@ export class RobotVacuumCleaner {
|
|
|
130
127
|
if (this.On !== this.accessory.context.On) {
|
|
131
128
|
await this.pushChanges();
|
|
132
129
|
}
|
|
133
|
-
if (this.On && (this.Brightness !== this.accessory.context.Brightness)
|
|
130
|
+
if (this.On && (this.Brightness !== this.accessory.context.Brightness)) {
|
|
134
131
|
await this.openAPIpushBrightnessChanges();
|
|
135
132
|
}
|
|
136
133
|
} catch (e: any) {
|
|
137
134
|
this.apiError(e);
|
|
138
135
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
139
|
-
|
|
136
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
140
137
|
}
|
|
141
138
|
this.robotVacuumCleanerUpdateInProgress = false;
|
|
142
139
|
});
|
|
@@ -155,7 +152,7 @@ export class RobotVacuumCleaner {
|
|
|
155
152
|
} else {
|
|
156
153
|
await this.offlineOff();
|
|
157
154
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
158
|
-
|
|
155
|
+
+ ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
159
156
|
}
|
|
160
157
|
}
|
|
161
158
|
|
|
@@ -197,7 +194,7 @@ export class RobotVacuumCleaner {
|
|
|
197
194
|
} else {
|
|
198
195
|
await this.offlineOff();
|
|
199
196
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
200
|
-
|
|
197
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
201
198
|
}
|
|
202
199
|
}
|
|
203
200
|
|
|
@@ -223,14 +220,14 @@ export class RobotVacuumCleaner {
|
|
|
223
220
|
switchbot.onadvertisement = async (ad: any) => {
|
|
224
221
|
this.address = ad.address;
|
|
225
222
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
226
|
-
|
|
223
|
+
+ ` BLE Address Found: ${this.address}`);
|
|
227
224
|
this.serviceData = ad.serviceData;
|
|
228
225
|
this.state = ad.serviceData.state;
|
|
229
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
226
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
230
227
|
this.debugLog(
|
|
231
228
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
230
|
+
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
234
231
|
);
|
|
235
232
|
|
|
236
233
|
if (this.serviceData) {
|
|
@@ -252,7 +249,7 @@ export class RobotVacuumCleaner {
|
|
|
252
249
|
.catch(async (e: any) => {
|
|
253
250
|
this.apiError(e);
|
|
254
251
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
255
|
-
|
|
252
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
256
253
|
await this.BLERefreshConnection(switchbot);
|
|
257
254
|
});
|
|
258
255
|
} else {
|
|
@@ -263,53 +260,24 @@ export class RobotVacuumCleaner {
|
|
|
263
260
|
async openAPIRefreshStatus() {
|
|
264
261
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
265
262
|
try {
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
269
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
270
|
-
const sign = signTerm.toString('base64');
|
|
271
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
272
|
-
const options = {
|
|
273
|
-
hostname: HostDomain,
|
|
274
|
-
port: 443,
|
|
275
|
-
path: `${DevicePath}/${this.device.deviceId}/status`,
|
|
276
|
-
method: 'GET',
|
|
277
|
-
headers: {
|
|
278
|
-
Authorization: this.platform.config.credentials?.token,
|
|
279
|
-
sign: sign,
|
|
280
|
-
nonce: nonce,
|
|
281
|
-
t: t,
|
|
282
|
-
'Content-Type': 'application/json',
|
|
283
|
-
},
|
|
284
|
-
};
|
|
285
|
-
const req = https.request(options, (res) => {
|
|
286
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
287
|
-
this.statusCode({ res });
|
|
288
|
-
let rawData = '';
|
|
289
|
-
res.on('data', (d) => {
|
|
290
|
-
rawData += d;
|
|
291
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
292
|
-
});
|
|
293
|
-
res.on('end', () => {
|
|
294
|
-
try {
|
|
295
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
296
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
297
|
-
this.power = this.deviceStatus.body.power;
|
|
298
|
-
this.openAPIparseStatus();
|
|
299
|
-
this.updateHomeKitCharacteristics();
|
|
300
|
-
} catch (e: any) {
|
|
301
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
req.on('error', (e: any) => {
|
|
306
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
263
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
264
|
+
headers: this.platform.generateHeaders(),
|
|
307
265
|
});
|
|
308
|
-
|
|
266
|
+
const deviceStatus = await body.json();
|
|
267
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
268
|
+
this.statusCode(statusCode);
|
|
269
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
270
|
+
this.debugLog(
|
|
271
|
+
`${this.device.deviceType}: ${this.accessory.displayName
|
|
272
|
+
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
273
|
+
);
|
|
274
|
+
this.power = deviceStatus.body.power;
|
|
275
|
+
this.openAPIparseStatus();
|
|
276
|
+
this.updateHomeKitCharacteristics();
|
|
309
277
|
} catch (e: any) {
|
|
310
278
|
this.apiError(e);
|
|
311
279
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
312
|
-
|
|
280
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
313
281
|
}
|
|
314
282
|
}
|
|
315
283
|
|
|
@@ -332,7 +300,7 @@ export class RobotVacuumCleaner {
|
|
|
332
300
|
} else {
|
|
333
301
|
await this.offlineOff();
|
|
334
302
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
335
|
-
|
|
303
|
+
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
336
304
|
}
|
|
337
305
|
// Refresh the status from the API
|
|
338
306
|
interval(15000)
|
|
@@ -379,111 +347,70 @@ export class RobotVacuumCleaner {
|
|
|
379
347
|
.catch(async (e: any) => {
|
|
380
348
|
this.apiError(e);
|
|
381
349
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
382
|
-
|
|
350
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
383
351
|
await this.BLEPushConnection();
|
|
384
352
|
});
|
|
385
353
|
} else {
|
|
386
354
|
this.debugLog(
|
|
387
355
|
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
|
|
388
|
-
|
|
356
|
+
+ `OnCached: ${this.accessory.context.On}`,
|
|
389
357
|
);
|
|
390
358
|
}
|
|
391
359
|
}
|
|
392
360
|
|
|
393
361
|
async openAPIpushChanges() {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
362
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
363
|
+
if (this.On !== this.accessory.context.On) {
|
|
364
|
+
let command = '';
|
|
365
|
+
if (this.On) {
|
|
366
|
+
command = 'turnOn';
|
|
367
|
+
} else {
|
|
368
|
+
command = 'turnOff';
|
|
369
|
+
}
|
|
370
|
+
const body = JSON.stringify({
|
|
371
|
+
'command': `${command}`,
|
|
372
|
+
'parameter': 'default',
|
|
373
|
+
'commandType': 'command',
|
|
374
|
+
});
|
|
406
375
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
method: 'POST',
|
|
412
|
-
headers: {
|
|
413
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
414
|
-
'sign': sign,
|
|
415
|
-
'nonce': nonce,
|
|
416
|
-
't': t,
|
|
417
|
-
'Content-Type': 'application/json',
|
|
418
|
-
'Content-Length': body.length,
|
|
419
|
-
},
|
|
420
|
-
};
|
|
421
|
-
const req = https.request(options, res => {
|
|
422
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
423
|
-
this.statusCode({ res });
|
|
424
|
-
res.on('data', d => {
|
|
425
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
376
|
+
try {
|
|
377
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
378
|
+
method: 'POST',
|
|
379
|
+
headers: this.platform.generateHeaders(),
|
|
426
380
|
});
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
this.
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
381
|
+
const deviceStatus = await body.json();
|
|
382
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
383
|
+
this.statusCode(statusCode);
|
|
384
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
385
|
+
} catch (e: any) {
|
|
386
|
+
this.apiError(e);
|
|
387
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
388
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
} else {
|
|
392
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
|
|
393
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
439
394
|
}
|
|
440
395
|
}
|
|
441
396
|
|
|
442
397
|
async openAPIpushBrightnessChanges() {
|
|
398
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushBrightnessChanges`);
|
|
399
|
+
const body = await this.brightnessCommands();
|
|
400
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
443
401
|
try {
|
|
444
|
-
|
|
445
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
446
|
-
const t = Date.now();
|
|
447
|
-
const nonce = 'requestID';
|
|
448
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
449
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
450
|
-
.update(Buffer.from(data, 'utf-8'))
|
|
451
|
-
.digest();
|
|
452
|
-
const sign = signTerm.toString('base64');
|
|
453
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
454
|
-
const body = await this.brightnessCommands();
|
|
455
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
456
|
-
const options = {
|
|
457
|
-
hostname: HostDomain,
|
|
458
|
-
port: 443,
|
|
459
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
402
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
460
403
|
method: 'POST',
|
|
461
|
-
headers:
|
|
462
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
463
|
-
'sign': sign,
|
|
464
|
-
'nonce': nonce,
|
|
465
|
-
't': t,
|
|
466
|
-
'Content-Type': 'application/json',
|
|
467
|
-
'Content-Length': body.length,
|
|
468
|
-
},
|
|
469
|
-
};
|
|
470
|
-
const req = https.request(options, res => {
|
|
471
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
472
|
-
this.statusCode({ res });
|
|
473
|
-
res.on('data', d => {
|
|
474
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
req.on('error', (e: any) => {
|
|
478
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
404
|
+
headers: this.platform.generateHeaders(),
|
|
479
405
|
});
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
this.
|
|
406
|
+
const deviceStatus = await body.json();
|
|
407
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
408
|
+
this.statusCode(statusCode);
|
|
409
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
483
410
|
} catch (e: any) {
|
|
484
411
|
this.apiError(e);
|
|
485
412
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
486
|
-
+ ` Connection, Error Message: ${
|
|
413
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
487
414
|
);
|
|
488
415
|
}
|
|
489
416
|
}
|
|
@@ -498,7 +425,7 @@ export class RobotVacuumCleaner {
|
|
|
498
425
|
command = 'dock';
|
|
499
426
|
parameter = 'default';
|
|
500
427
|
}
|
|
501
|
-
const body =
|
|
428
|
+
const body = JSON.stringify({
|
|
502
429
|
'command': `${command}`,
|
|
503
430
|
'parameter': `${parameter}`,
|
|
504
431
|
'commandType': 'command',
|
|
@@ -525,7 +452,7 @@ export class RobotVacuumCleaner {
|
|
|
525
452
|
command = 'dock';
|
|
526
453
|
parameter = 'default';
|
|
527
454
|
}
|
|
528
|
-
const body =
|
|
455
|
+
const body = JSON.stringify({
|
|
529
456
|
'command': `${command}`,
|
|
530
457
|
'parameter': `${parameter}`,
|
|
531
458
|
'commandType': 'command',
|
|
@@ -621,7 +548,7 @@ export class RobotVacuumCleaner {
|
|
|
621
548
|
});
|
|
622
549
|
// Set an event handler
|
|
623
550
|
switchbot.onadvertisement = (ad: any) => {
|
|
624
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${
|
|
551
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
625
552
|
};
|
|
626
553
|
await sleep(10000);
|
|
627
554
|
// Stop to monitor
|
|
@@ -691,36 +618,41 @@ export class RobotVacuumCleaner {
|
|
|
691
618
|
}
|
|
692
619
|
}
|
|
693
620
|
|
|
694
|
-
async statusCode(
|
|
695
|
-
switch (
|
|
621
|
+
async statusCode(statusCode: number): Promise<void> {
|
|
622
|
+
switch (statusCode) {
|
|
696
623
|
case 151:
|
|
697
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this
|
|
624
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
698
625
|
break;
|
|
699
626
|
case 152:
|
|
700
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found
|
|
627
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
701
628
|
break;
|
|
702
629
|
case 160:
|
|
703
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported
|
|
630
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
704
631
|
break;
|
|
705
632
|
case 161:
|
|
706
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline
|
|
707
|
-
|
|
633
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
634
|
+
this.offlineOff();
|
|
708
635
|
break;
|
|
709
636
|
case 171:
|
|
710
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline
|
|
711
|
-
|
|
637
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
|
|
638
|
+
+ `Hub: ${this.device.hubDeviceId}`);
|
|
639
|
+
this.offlineOff();
|
|
712
640
|
break;
|
|
713
641
|
case 190:
|
|
714
642
|
this.errorLog(
|
|
715
643
|
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
716
|
-
|
|
644
|
+
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
717
645
|
);
|
|
718
646
|
break;
|
|
719
647
|
case 100:
|
|
720
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent
|
|
648
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
649
|
+
break;
|
|
650
|
+
case 200:
|
|
651
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
721
652
|
break;
|
|
722
653
|
default:
|
|
723
|
-
this.
|
|
654
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
|
|
655
|
+
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
724
656
|
}
|
|
725
657
|
}
|
|
726
658
|
|
|
@@ -738,7 +670,7 @@ export class RobotVacuumCleaner {
|
|
|
738
670
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
739
671
|
let FirmwareRevision: string;
|
|
740
672
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
741
|
-
|
|
673
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
742
674
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
743
675
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
744
676
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -801,7 +733,7 @@ export class RobotVacuumCleaner {
|
|
|
801
733
|
config['maxRetry'] = device.maxRetry;
|
|
802
734
|
}
|
|
803
735
|
if (Object.entries(config).length !== 0) {
|
|
804
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${
|
|
736
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
805
737
|
}
|
|
806
738
|
}
|
|
807
739
|
|