@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
package/src/device/plug.ts
CHANGED
|
@@ -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 Plug {
|
|
14
11
|
// Services
|
|
@@ -118,7 +115,7 @@ export class Plug {
|
|
|
118
115
|
} catch (e: any) {
|
|
119
116
|
this.apiError(e);
|
|
120
117
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
121
|
-
|
|
118
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
122
119
|
}
|
|
123
120
|
this.plugUpdateInProgress = false;
|
|
124
121
|
});
|
|
@@ -137,7 +134,7 @@ export class Plug {
|
|
|
137
134
|
} else {
|
|
138
135
|
await this.offlineOff();
|
|
139
136
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
140
|
-
|
|
137
|
+
+ ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
141
138
|
}
|
|
142
139
|
}
|
|
143
140
|
|
|
@@ -179,7 +176,7 @@ export class Plug {
|
|
|
179
176
|
} else {
|
|
180
177
|
await this.offlineOff();
|
|
181
178
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
182
|
-
|
|
179
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
183
180
|
}
|
|
184
181
|
}
|
|
185
182
|
|
|
@@ -205,7 +202,7 @@ export class Plug {
|
|
|
205
202
|
switchbot.onadvertisement = async (ad: any) => {
|
|
206
203
|
this.address = ad.address;
|
|
207
204
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
208
|
-
|
|
205
|
+
+ ` BLE Address Found: ${this.address}`);
|
|
209
206
|
this.serviceData = ad.serviceData;
|
|
210
207
|
this.state = ad.serviceData.state;
|
|
211
208
|
this.delay = ad.serviceData.delay;
|
|
@@ -214,11 +211,11 @@ export class Plug {
|
|
|
214
211
|
this.wifiRssi = ad.serviceData.wifiRssi;
|
|
215
212
|
this.overload = ad.serviceData.overload;
|
|
216
213
|
this.currentPower = ad.serviceData.currentPower;
|
|
217
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
214
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
218
215
|
this.debugLog(
|
|
219
216
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
220
|
-
|
|
221
|
-
|
|
217
|
+
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
218
|
+
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
222
219
|
);
|
|
223
220
|
|
|
224
221
|
if (this.serviceData) {
|
|
@@ -240,7 +237,7 @@ export class Plug {
|
|
|
240
237
|
.catch(async (e: any) => {
|
|
241
238
|
this.apiError(e);
|
|
242
239
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
243
|
-
|
|
240
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
244
241
|
await this.BLERefreshConnection(switchbot);
|
|
245
242
|
});
|
|
246
243
|
} else {
|
|
@@ -251,53 +248,24 @@ export class Plug {
|
|
|
251
248
|
async openAPIRefreshStatus() {
|
|
252
249
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
253
250
|
try {
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
257
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
258
|
-
const sign = signTerm.toString('base64');
|
|
259
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
260
|
-
const options = {
|
|
261
|
-
hostname: HostDomain,
|
|
262
|
-
port: 443,
|
|
263
|
-
path: `${DevicePath}/${this.device.deviceId}/status`,
|
|
264
|
-
method: 'GET',
|
|
265
|
-
headers: {
|
|
266
|
-
Authorization: this.platform.config.credentials?.token,
|
|
267
|
-
sign: sign,
|
|
268
|
-
nonce: nonce,
|
|
269
|
-
t: t,
|
|
270
|
-
'Content-Type': 'application/json',
|
|
271
|
-
},
|
|
272
|
-
};
|
|
273
|
-
const req = https.request(options, (res) => {
|
|
274
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
275
|
-
this.statusCode({ res });
|
|
276
|
-
let rawData = '';
|
|
277
|
-
res.on('data', (d) => {
|
|
278
|
-
rawData += d;
|
|
279
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
280
|
-
});
|
|
281
|
-
res.on('end', () => {
|
|
282
|
-
try {
|
|
283
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
284
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
285
|
-
this.power = this.deviceStatus.body.power;
|
|
286
|
-
this.openAPIparseStatus();
|
|
287
|
-
this.updateHomeKitCharacteristics();
|
|
288
|
-
} catch (e: any) {
|
|
289
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
req.on('error', (e: any) => {
|
|
294
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
251
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
252
|
+
headers: this.platform.generateHeaders(),
|
|
295
253
|
});
|
|
296
|
-
|
|
254
|
+
const deviceStatus = await body.json();
|
|
255
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
256
|
+
this.statusCode(statusCode);
|
|
257
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
258
|
+
this.debugLog(
|
|
259
|
+
`${this.device.deviceType}: ${this.accessory.displayName
|
|
260
|
+
} refreshStatus: ${JSON.stringify(deviceStatus)}`,
|
|
261
|
+
);
|
|
262
|
+
this.power = deviceStatus.body.power;
|
|
263
|
+
this.openAPIparseStatus();
|
|
264
|
+
this.updateHomeKitCharacteristics();
|
|
297
265
|
} catch (e: any) {
|
|
298
266
|
this.apiError(e);
|
|
299
267
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
300
|
-
|
|
268
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
301
269
|
}
|
|
302
270
|
}
|
|
303
271
|
|
|
@@ -321,7 +289,7 @@ export class Plug {
|
|
|
321
289
|
} else {
|
|
322
290
|
await this.offlineOff();
|
|
323
291
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
324
|
-
|
|
292
|
+
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
325
293
|
}
|
|
326
294
|
// Refresh the status from the API
|
|
327
295
|
interval(15000)
|
|
@@ -368,81 +336,50 @@ export class Plug {
|
|
|
368
336
|
.catch(async (e: any) => {
|
|
369
337
|
this.apiError(e);
|
|
370
338
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
371
|
-
|
|
339
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
372
340
|
await this.BLEPushConnection();
|
|
373
341
|
});
|
|
374
342
|
} else {
|
|
375
343
|
this.debugLog(
|
|
376
344
|
`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
|
|
377
|
-
|
|
345
|
+
+ `OnCached: ${this.accessory.context.On}`,
|
|
378
346
|
);
|
|
379
347
|
}
|
|
380
348
|
}
|
|
381
349
|
|
|
382
350
|
async openAPIpushChanges() {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
} else {
|
|
400
|
-
command = 'turnOff';
|
|
401
|
-
}
|
|
402
|
-
const body = superStringify({
|
|
403
|
-
'command': `${command}`,
|
|
404
|
-
'parameter': 'default',
|
|
405
|
-
'commandType': 'command',
|
|
406
|
-
});
|
|
407
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
408
|
-
const options = {
|
|
409
|
-
hostname: HostDomain,
|
|
410
|
-
port: 443,
|
|
411
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
351
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
352
|
+
if (this.On !== this.accessory.context.On) {
|
|
353
|
+
let command = '';
|
|
354
|
+
if (this.On) {
|
|
355
|
+
command = 'turnOn';
|
|
356
|
+
} else {
|
|
357
|
+
command = 'turnOff';
|
|
358
|
+
}
|
|
359
|
+
const body = JSON.stringify({
|
|
360
|
+
'command': `${command}`,
|
|
361
|
+
'parameter': 'default',
|
|
362
|
+
'commandType': 'command',
|
|
363
|
+
});
|
|
364
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
365
|
+
try {
|
|
366
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
412
367
|
method: 'POST',
|
|
413
|
-
headers:
|
|
414
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
415
|
-
'sign': sign,
|
|
416
|
-
'nonce': nonce,
|
|
417
|
-
't': t,
|
|
418
|
-
'Content-Type': 'application/json',
|
|
419
|
-
'Content-Length': body.length,
|
|
420
|
-
},
|
|
421
|
-
};
|
|
422
|
-
const req = https.request(options, res => {
|
|
423
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
424
|
-
this.statusCode({ res });
|
|
425
|
-
res.on('data', d => {
|
|
426
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
req.on('error', (e: any) => {
|
|
430
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
368
|
+
headers: this.platform.generateHeaders(),
|
|
431
369
|
});
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
this.
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
370
|
+
const deviceStatus = await body.json();
|
|
371
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
372
|
+
this.statusCode(statusCode);
|
|
373
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
374
|
+
} catch (e: any) {
|
|
375
|
+
this.apiError(e);
|
|
376
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
377
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
439
378
|
);
|
|
440
379
|
}
|
|
441
|
-
}
|
|
442
|
-
this.
|
|
443
|
-
|
|
444
|
-
+ ` Connection, Error Message: ${superStringify(e.message)}`,
|
|
445
|
-
);
|
|
380
|
+
} else {
|
|
381
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
|
|
382
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
446
383
|
}
|
|
447
384
|
}
|
|
448
385
|
|
|
@@ -497,7 +434,7 @@ export class Plug {
|
|
|
497
434
|
});
|
|
498
435
|
// Set an event handler
|
|
499
436
|
switchbot.onadvertisement = (ad: any) => {
|
|
500
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${
|
|
437
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
501
438
|
};
|
|
502
439
|
await sleep(10000);
|
|
503
440
|
// Stop to monitor
|
|
@@ -567,36 +504,41 @@ export class Plug {
|
|
|
567
504
|
}
|
|
568
505
|
}
|
|
569
506
|
|
|
570
|
-
async statusCode(
|
|
571
|
-
switch (
|
|
507
|
+
async statusCode(statusCode: number): Promise<void> {
|
|
508
|
+
switch (statusCode) {
|
|
572
509
|
case 151:
|
|
573
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this
|
|
510
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
574
511
|
break;
|
|
575
512
|
case 152:
|
|
576
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found
|
|
513
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
577
514
|
break;
|
|
578
515
|
case 160:
|
|
579
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported
|
|
516
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
580
517
|
break;
|
|
581
518
|
case 161:
|
|
582
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline
|
|
583
|
-
|
|
519
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
520
|
+
this.offlineOff();
|
|
584
521
|
break;
|
|
585
522
|
case 171:
|
|
586
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline
|
|
587
|
-
|
|
523
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
|
|
524
|
+
+ `Hub: ${this.device.hubDeviceId}`);
|
|
525
|
+
this.offlineOff();
|
|
588
526
|
break;
|
|
589
527
|
case 190:
|
|
590
528
|
this.errorLog(
|
|
591
529
|
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
592
|
-
|
|
530
|
+
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
593
531
|
);
|
|
594
532
|
break;
|
|
595
533
|
case 100:
|
|
596
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent
|
|
534
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
535
|
+
break;
|
|
536
|
+
case 200:
|
|
537
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
597
538
|
break;
|
|
598
539
|
default:
|
|
599
|
-
this.
|
|
540
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
|
|
541
|
+
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
600
542
|
}
|
|
601
543
|
}
|
|
602
544
|
|
|
@@ -614,7 +556,7 @@ export class Plug {
|
|
|
614
556
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
615
557
|
let FirmwareRevision: string;
|
|
616
558
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
617
|
-
|
|
559
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
618
560
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
619
561
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
620
562
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -672,7 +614,7 @@ export class Plug {
|
|
|
672
614
|
config['maxRetry'] = device.maxRetry;
|
|
673
615
|
}
|
|
674
616
|
if (Object.entries(config).length !== 0) {
|
|
675
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${
|
|
617
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
676
618
|
}
|
|
677
619
|
}
|
|
678
620
|
|