@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/colorbulb.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import https from 'https';
|
|
2
|
-
import crypto from 'crypto';
|
|
3
1
|
import { Context } from 'vm';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
2
|
+
import { request } from 'undici';
|
|
3
|
+
import { sleep } from '../utils';
|
|
6
4
|
import { interval, Subject } from 'rxjs';
|
|
7
5
|
import { SwitchBotPlatform } from '../platform';
|
|
8
6
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
7
|
+
import { device, devicesConfig, deviceStatus, switchbot, hs2rgb, rgb2hs, m2hs, serviceData, ad, Devices } from '../settings';
|
|
9
8
|
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
10
|
-
import { device, devicesConfig, deviceStatus, switchbot, hs2rgb, rgb2hs, m2hs, serviceData, ad, HostDomain, DevicePath } from '../settings';
|
|
11
|
-
import { sleep } from '../utils';
|
|
12
9
|
|
|
13
10
|
/**
|
|
14
11
|
* Platform Accessory
|
|
@@ -188,7 +185,7 @@ export class ColorBulb {
|
|
|
188
185
|
this.accessory.context.adaptiveLighting = true;
|
|
189
186
|
this.debugLog(
|
|
190
187
|
`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
191
|
-
|
|
188
|
+
` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
192
189
|
);
|
|
193
190
|
}
|
|
194
191
|
|
|
@@ -217,7 +214,7 @@ export class ColorBulb {
|
|
|
217
214
|
} catch (e: any) {
|
|
218
215
|
this.apiError(e);
|
|
219
216
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
220
|
-
|
|
217
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
221
218
|
}
|
|
222
219
|
this.colorBulbUpdateInProgress = false;
|
|
223
220
|
});
|
|
@@ -236,7 +233,7 @@ export class ColorBulb {
|
|
|
236
233
|
} else {
|
|
237
234
|
await this.offlineOff();
|
|
238
235
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
239
|
-
|
|
236
|
+
+ ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
240
237
|
}
|
|
241
238
|
}
|
|
242
239
|
|
|
@@ -264,7 +261,7 @@ export class ColorBulb {
|
|
|
264
261
|
|
|
265
262
|
const [hue, saturation] = rgb2hs(Number(this.red), Number(this.green), Number(this.blue));
|
|
266
263
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
267
|
-
+ ` hs: ${
|
|
264
|
+
+ ` hs: ${JSON.stringify(rgb2hs(Number(this.red), Number(this.green), Number(this.blue)))}`);
|
|
268
265
|
|
|
269
266
|
// Hue
|
|
270
267
|
this.Hue = hue;
|
|
@@ -301,15 +298,15 @@ export class ColorBulb {
|
|
|
301
298
|
|
|
302
299
|
// Color, Hue & Brightness
|
|
303
300
|
if (this.color) {
|
|
304
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${
|
|
301
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
|
|
305
302
|
const [red, green, blue] = this.color!.split(':');
|
|
306
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${
|
|
307
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${
|
|
308
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${
|
|
303
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
304
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
305
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
309
306
|
|
|
310
307
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
311
308
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
312
|
-
|
|
309
|
+
+ ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
313
310
|
|
|
314
311
|
// Hue
|
|
315
312
|
this.Hue = hue;
|
|
@@ -345,7 +342,7 @@ export class ColorBulb {
|
|
|
345
342
|
} else {
|
|
346
343
|
await this.offlineOff();
|
|
347
344
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
348
|
-
|
|
345
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
349
346
|
}
|
|
350
347
|
}
|
|
351
348
|
|
|
@@ -371,8 +368,8 @@ export class ColorBulb {
|
|
|
371
368
|
switchbot.onadvertisement = async (ad: any) => {
|
|
372
369
|
this.address = ad.address;
|
|
373
370
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
374
|
-
|
|
375
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
371
|
+
+ ` BLE Address Found: ${this.address}`);
|
|
372
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
376
373
|
this.serviceData = ad.serviceData;
|
|
377
374
|
this.powerState = ad.serviceData.power;
|
|
378
375
|
this.state = ad.serviceData.state;
|
|
@@ -386,7 +383,7 @@ export class ColorBulb {
|
|
|
386
383
|
this.color_mode = ad.serviceData.color_mode;
|
|
387
384
|
this.speed = ad.serviceData.speed;
|
|
388
385
|
this.loop_index = ad.serviceData.loop_index;
|
|
389
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
386
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
390
387
|
/*this.debugLog(
|
|
391
388
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
392
389
|
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
@@ -406,13 +403,13 @@ export class ColorBulb {
|
|
|
406
403
|
return await sleep(this.scanDuration * 1000);
|
|
407
404
|
})
|
|
408
405
|
.then(async () => {
|
|
409
|
-
|
|
406
|
+
// Stop to monitor
|
|
410
407
|
await this.stopScanning(switchbot);
|
|
411
408
|
})
|
|
412
409
|
.catch(async (e: any) => {
|
|
413
410
|
this.apiError(e);
|
|
414
411
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
415
|
-
|
|
412
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
416
413
|
await this.BLERefreshConnection(switchbot);
|
|
417
414
|
});
|
|
418
415
|
} else {
|
|
@@ -423,56 +420,24 @@ export class ColorBulb {
|
|
|
423
420
|
async openAPIRefreshStatus() {
|
|
424
421
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
425
422
|
try {
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
429
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
430
|
-
const sign = signTerm.toString('base64');
|
|
431
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
432
|
-
const options = {
|
|
433
|
-
hostname: HostDomain,
|
|
434
|
-
port: 443,
|
|
435
|
-
path: `${DevicePath}/${this.device.deviceId}/status`,
|
|
436
|
-
method: 'GET',
|
|
437
|
-
headers: {
|
|
438
|
-
Authorization: this.platform.config.credentials?.token,
|
|
439
|
-
sign: sign,
|
|
440
|
-
nonce: nonce,
|
|
441
|
-
t: t,
|
|
442
|
-
'Content-Type': 'application/json',
|
|
443
|
-
},
|
|
444
|
-
};
|
|
445
|
-
const req = https.request(options, (res) => {
|
|
446
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
447
|
-
this.statusCode({ res });
|
|
448
|
-
let rawData = '';
|
|
449
|
-
res.on('data', (d) => {
|
|
450
|
-
rawData += d;
|
|
451
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
452
|
-
});
|
|
453
|
-
res.on('end', () => {
|
|
454
|
-
try {
|
|
455
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
456
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
457
|
-
this.power = this.deviceStatus.body.power;
|
|
458
|
-
this.color = this.deviceStatus.body.color;
|
|
459
|
-
this.brightness = this.deviceStatus.body.brightness;
|
|
460
|
-
this.colorTemperature = this.deviceStatus.body.colorTemperature;
|
|
461
|
-
this.openAPIparseStatus();
|
|
462
|
-
this.updateHomeKitCharacteristics();
|
|
463
|
-
} catch (e: any) {
|
|
464
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
465
|
-
}
|
|
466
|
-
});
|
|
423
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/status`, {
|
|
424
|
+
headers: this.platform.generateHeaders(),
|
|
467
425
|
});
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
426
|
+
const deviceStatus = await body.json();
|
|
427
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
428
|
+
this.statusCode(statusCode);
|
|
429
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
430
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
431
|
+
this.power = deviceStatus.body.power;
|
|
432
|
+
this.color = deviceStatus.body.color;
|
|
433
|
+
this.brightness = deviceStatus.body.brightness;
|
|
434
|
+
this.colorTemperature = deviceStatus.body.colorTemperature;
|
|
435
|
+
this.openAPIparseStatus();
|
|
436
|
+
this.updateHomeKitCharacteristics();
|
|
472
437
|
} catch (e: any) {
|
|
473
438
|
this.apiError(e);
|
|
474
439
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
475
|
-
|
|
440
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
476
441
|
}
|
|
477
442
|
}
|
|
478
443
|
|
|
@@ -497,7 +462,7 @@ export class ColorBulb {
|
|
|
497
462
|
} else {
|
|
498
463
|
await this.offlineOff();
|
|
499
464
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
500
|
-
|
|
465
|
+
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
501
466
|
}
|
|
502
467
|
// Refresh the status from the API
|
|
503
468
|
interval(15000)
|
|
@@ -544,7 +509,7 @@ export class ColorBulb {
|
|
|
544
509
|
.catch(async (e: any) => {
|
|
545
510
|
this.apiError(e);
|
|
546
511
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
547
|
-
|
|
512
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
548
513
|
await this.BLEPushConnection();
|
|
549
514
|
});
|
|
550
515
|
// Push Brightness Update
|
|
@@ -561,7 +526,7 @@ export class ColorBulb {
|
|
|
561
526
|
}
|
|
562
527
|
} else {
|
|
563
528
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
|
|
564
|
-
|
|
529
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
565
530
|
}
|
|
566
531
|
}
|
|
567
532
|
|
|
@@ -591,12 +556,12 @@ export class ColorBulb {
|
|
|
591
556
|
.catch(async (e: any) => {
|
|
592
557
|
this.apiError(e);
|
|
593
558
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}`
|
|
594
|
-
|
|
559
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
595
560
|
await this.BLEPushConnection();
|
|
596
561
|
});
|
|
597
562
|
} else {
|
|
598
563
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
|
|
599
|
-
|
|
564
|
+
+ `BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
600
565
|
}
|
|
601
566
|
}
|
|
602
567
|
|
|
@@ -626,12 +591,12 @@ export class ColorBulb {
|
|
|
626
591
|
.catch(async (e: any) => {
|
|
627
592
|
this.apiError(e);
|
|
628
593
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushColorTemperatureChanges with `
|
|
629
|
-
|
|
594
|
+
+ `${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
630
595
|
await this.BLEPushConnection();
|
|
631
596
|
});
|
|
632
597
|
} else {
|
|
633
598
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushColorTemperatureChanges.` +
|
|
634
|
-
|
|
599
|
+
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
635
600
|
|
|
636
601
|
}
|
|
637
602
|
}
|
|
@@ -639,11 +604,11 @@ export class ColorBulb {
|
|
|
639
604
|
async BLEpushRGBChanges(): Promise<void> {
|
|
640
605
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushRGBChanges`);
|
|
641
606
|
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
642
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${
|
|
643
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${
|
|
607
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
608
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
644
609
|
|
|
645
610
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
646
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${
|
|
611
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
647
612
|
|
|
648
613
|
const switchbot = await this.platform.connectBLE();
|
|
649
614
|
// Convert to BLE Address
|
|
@@ -668,7 +633,7 @@ export class ColorBulb {
|
|
|
668
633
|
.catch(async (e: any) => {
|
|
669
634
|
this.apiError(e);
|
|
670
635
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}`
|
|
671
|
-
|
|
636
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
672
637
|
await this.BLEPushConnection();
|
|
673
638
|
});
|
|
674
639
|
} else {
|
|
@@ -678,258 +643,146 @@ export class ColorBulb {
|
|
|
678
643
|
}
|
|
679
644
|
|
|
680
645
|
async openAPIpushChanges(): Promise<void> {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
} else {
|
|
698
|
-
command = 'turnOff';
|
|
699
|
-
}
|
|
700
|
-
const body = superStringify({
|
|
701
|
-
'command': `${command}`,
|
|
702
|
-
'parameter': 'default',
|
|
703
|
-
'commandType': 'command',
|
|
704
|
-
});
|
|
705
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
706
|
-
const options = {
|
|
707
|
-
hostname: HostDomain,
|
|
708
|
-
port: 443,
|
|
709
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
646
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
647
|
+
if (this.On !== this.accessory.context.On) {
|
|
648
|
+
let command = '';
|
|
649
|
+
if (this.On) {
|
|
650
|
+
command = 'turnOn';
|
|
651
|
+
} else {
|
|
652
|
+
command = 'turnOff';
|
|
653
|
+
}
|
|
654
|
+
const body = JSON.stringify({
|
|
655
|
+
'command': `${command}`,
|
|
656
|
+
'parameter': 'default',
|
|
657
|
+
'commandType': 'command',
|
|
658
|
+
});
|
|
659
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
660
|
+
try {
|
|
661
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
710
662
|
method: 'POST',
|
|
711
|
-
headers:
|
|
712
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
713
|
-
'sign': sign,
|
|
714
|
-
'nonce': nonce,
|
|
715
|
-
't': t,
|
|
716
|
-
'Content-Type': 'application/json',
|
|
717
|
-
'Content-Length': body.length,
|
|
718
|
-
},
|
|
719
|
-
};
|
|
720
|
-
const req = https.request(options, res => {
|
|
721
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
722
|
-
this.statusCode({ res });
|
|
723
|
-
res.on('data', d => {
|
|
724
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
725
|
-
});
|
|
726
|
-
});
|
|
727
|
-
req.on('error', (e: any) => {
|
|
728
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
663
|
+
headers: this.platform.generateHeaders(),
|
|
729
664
|
});
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
this.
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
665
|
+
const deviceStatus = await body.json();
|
|
666
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
667
|
+
this.statusCode(statusCode);
|
|
668
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
669
|
+
} catch (e: any) {
|
|
670
|
+
this.apiError(e);
|
|
671
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
672
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
737
673
|
);
|
|
738
674
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
this.
|
|
754
|
-
+ ` Connection, Error Message: ${superStringify(e.message)}`,
|
|
755
|
-
);
|
|
675
|
+
} else {
|
|
676
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
|
|
677
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
678
|
+
}
|
|
679
|
+
// Push Hue & Saturation Update
|
|
680
|
+
if (this.On) {
|
|
681
|
+
await this.pushHueSaturationChanges();
|
|
682
|
+
}
|
|
683
|
+
// Push ColorTemperature Update
|
|
684
|
+
if (this.On) {
|
|
685
|
+
await this.pushColorTemperatureChanges();
|
|
686
|
+
}
|
|
687
|
+
// Push Brightness Update
|
|
688
|
+
if (this.On) {
|
|
689
|
+
await this.pushBrightnessChanges();
|
|
756
690
|
}
|
|
757
691
|
}
|
|
758
692
|
|
|
759
693
|
async pushHueSaturationChanges(): Promise<void> {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
.digest();
|
|
775
|
-
const sign = signTerm.toString('base64');
|
|
776
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
777
|
-
const body = superStringify({
|
|
778
|
-
'command': 'setColor',
|
|
779
|
-
'parameter': `${red}:${green}:${blue}`,
|
|
780
|
-
'commandType': 'command',
|
|
781
|
-
});
|
|
782
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
783
|
-
const options = {
|
|
784
|
-
hostname: HostDomain,
|
|
785
|
-
port: 443,
|
|
786
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
694
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
|
|
695
|
+
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
696
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
697
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
698
|
+
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
699
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
700
|
+
const body = JSON.stringify({
|
|
701
|
+
'command': 'setColor',
|
|
702
|
+
'parameter': `${red}:${green}:${blue}`,
|
|
703
|
+
'commandType': 'command',
|
|
704
|
+
});
|
|
705
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
706
|
+
try {
|
|
707
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
787
708
|
method: 'POST',
|
|
788
|
-
headers:
|
|
789
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
790
|
-
'sign': sign,
|
|
791
|
-
'nonce': nonce,
|
|
792
|
-
't': t,
|
|
793
|
-
'Content-Type': 'application/json',
|
|
794
|
-
'Content-Length': body.length,
|
|
795
|
-
},
|
|
796
|
-
};
|
|
797
|
-
const req = https.request(options, res => {
|
|
798
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges statusCode: ${res.statusCode}`);
|
|
799
|
-
res.on('data', d => {
|
|
800
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
801
|
-
});
|
|
709
|
+
headers: this.platform.generateHeaders(),
|
|
802
710
|
});
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
this.
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
711
|
+
const deviceStatus = await body.json();
|
|
712
|
+
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
713
|
+
this.statusCode(statusCode);
|
|
714
|
+
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
715
|
+
} catch (e: any) {
|
|
716
|
+
this.apiError(e);
|
|
717
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
|
|
718
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
719
|
+
);
|
|
812
720
|
}
|
|
813
|
-
}
|
|
814
|
-
this.
|
|
815
|
-
|
|
816
|
-
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
721
|
+
} else {
|
|
722
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, `
|
|
723
|
+
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
817
724
|
}
|
|
818
725
|
}
|
|
819
726
|
|
|
820
727
|
async pushColorTemperatureChanges(): Promise<void> {
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
.digest();
|
|
834
|
-
const sign = signTerm.toString('base64');
|
|
835
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
836
|
-
const body = superStringify({
|
|
837
|
-
'command': 'setColorTemperature',
|
|
838
|
-
'parameter': `${kelvin}`,
|
|
839
|
-
'commandType': 'command',
|
|
840
|
-
});
|
|
841
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
842
|
-
const options = {
|
|
843
|
-
hostname: HostDomain,
|
|
844
|
-
port: 443,
|
|
845
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
728
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges`);
|
|
729
|
+
if (this.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
730
|
+
const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
|
|
731
|
+
this.cacheKelvin = kelvin;
|
|
732
|
+
const body = JSON.stringify({
|
|
733
|
+
'command': 'setColorTemperature',
|
|
734
|
+
'parameter': `${kelvin}`,
|
|
735
|
+
'commandType': 'command',
|
|
736
|
+
});
|
|
737
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
738
|
+
try {
|
|
739
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
846
740
|
method: 'POST',
|
|
847
|
-
headers:
|
|
848
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
849
|
-
'sign': sign,
|
|
850
|
-
'nonce': nonce,
|
|
851
|
-
't': t,
|
|
852
|
-
'Content-Type': 'application/json',
|
|
853
|
-
'Content-Length': body.length,
|
|
854
|
-
},
|
|
855
|
-
};
|
|
856
|
-
const req = https.request(options, res => {
|
|
857
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
858
|
-
res.on('data', d => {
|
|
859
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
860
|
-
});
|
|
741
|
+
headers: this.platform.generateHeaders(),
|
|
861
742
|
});
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
this.
|
|
868
|
-
this.
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
743
|
+
const deviceStatus = await body.json();
|
|
744
|
+
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
745
|
+
this.statusCode(statusCode);
|
|
746
|
+
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
747
|
+
} catch (e: any) {
|
|
748
|
+
this.apiError(e);
|
|
749
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with ${this.device.connectionType}`
|
|
750
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
751
|
+
);
|
|
872
752
|
}
|
|
873
|
-
}
|
|
874
|
-
this.
|
|
875
|
-
|
|
876
|
-
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
753
|
+
} else {
|
|
754
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.` +
|
|
755
|
+
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
877
756
|
}
|
|
878
757
|
}
|
|
879
758
|
|
|
880
759
|
async pushBrightnessChanges(): Promise<void> {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
const sign = signTerm.toString('base64');
|
|
892
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
893
|
-
const body = superStringify({
|
|
894
|
-
'command': 'setBrightness',
|
|
895
|
-
'parameter': `${this.Brightness}`,
|
|
896
|
-
'commandType': 'command',
|
|
897
|
-
});
|
|
898
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
899
|
-
const options = {
|
|
900
|
-
hostname: HostDomain,
|
|
901
|
-
port: 443,
|
|
902
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
760
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
761
|
+
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
762
|
+
const body = JSON.stringify({
|
|
763
|
+
'command': 'setBrightness',
|
|
764
|
+
'parameter': `${this.Brightness}`,
|
|
765
|
+
'commandType': 'command',
|
|
766
|
+
});
|
|
767
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
768
|
+
try {
|
|
769
|
+
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
903
770
|
method: 'POST',
|
|
904
|
-
headers:
|
|
905
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
906
|
-
'sign': sign,
|
|
907
|
-
'nonce': nonce,
|
|
908
|
-
't': t,
|
|
909
|
-
'Content-Type': 'application/json',
|
|
910
|
-
'Content-Length': body.length,
|
|
911
|
-
},
|
|
912
|
-
};
|
|
913
|
-
const req = https.request(options, res => {
|
|
914
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges statusCode: ${res.statusCode}`);
|
|
915
|
-
res.on('data', d => {
|
|
916
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
917
|
-
});
|
|
771
|
+
headers: this.platform.generateHeaders(),
|
|
918
772
|
});
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
this.
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
773
|
+
const deviceStatus = await body.json();
|
|
774
|
+
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
775
|
+
this.statusCode(statusCode);
|
|
776
|
+
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
777
|
+
} catch (e: any) {
|
|
778
|
+
this.apiError(e);
|
|
779
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
|
|
780
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
781
|
+
);
|
|
928
782
|
}
|
|
929
|
-
}
|
|
930
|
-
this.
|
|
931
|
-
|
|
932
|
-
+ ` Connection, Error Message: ${superStringify(e.message)}`);
|
|
783
|
+
} else {
|
|
784
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
|
|
785
|
+
+ `BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
933
786
|
}
|
|
934
787
|
}
|
|
935
788
|
|
|
@@ -1098,7 +951,7 @@ export class ColorBulb {
|
|
|
1098
951
|
});
|
|
1099
952
|
// Set an event handler
|
|
1100
953
|
switchbot.onadvertisement = (ad: any) => {
|
|
1101
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${
|
|
954
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
1102
955
|
};
|
|
1103
956
|
await sleep(10000);
|
|
1104
957
|
// Stop to monitor
|
|
@@ -1165,40 +1018,41 @@ export class ColorBulb {
|
|
|
1165
1018
|
}
|
|
1166
1019
|
}
|
|
1167
1020
|
|
|
1168
|
-
async statusCode(
|
|
1169
|
-
switch (
|
|
1021
|
+
async statusCode(statusCode: number): Promise<void> {
|
|
1022
|
+
switch (statusCode) {
|
|
1170
1023
|
case 151:
|
|
1171
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this
|
|
1024
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
1172
1025
|
break;
|
|
1173
1026
|
case 152:
|
|
1174
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found
|
|
1027
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
1175
1028
|
break;
|
|
1176
1029
|
case 160:
|
|
1177
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported
|
|
1030
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
1178
1031
|
break;
|
|
1179
1032
|
case 161:
|
|
1180
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline
|
|
1181
|
-
|
|
1033
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
1034
|
+
this.offlineOff();
|
|
1182
1035
|
break;
|
|
1183
1036
|
case 171:
|
|
1184
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline
|
|
1185
|
-
|
|
1037
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
|
|
1038
|
+
+ `Hub: ${this.device.hubDeviceId}`);
|
|
1039
|
+
this.offlineOff();
|
|
1186
1040
|
break;
|
|
1187
1041
|
case 190:
|
|
1188
1042
|
this.errorLog(
|
|
1189
1043
|
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
1190
|
-
` Or command
|
|
1044
|
+
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
1191
1045
|
);
|
|
1192
1046
|
break;
|
|
1193
1047
|
case 100:
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1048
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
1049
|
+
break;
|
|
1050
|
+
case 200:
|
|
1051
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
1197
1052
|
break;
|
|
1198
1053
|
default:
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
}
|
|
1054
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
|
|
1055
|
+
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
1202
1056
|
}
|
|
1203
1057
|
}
|
|
1204
1058
|
|
|
@@ -1220,7 +1074,7 @@ export class ColorBulb {
|
|
|
1220
1074
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
1221
1075
|
let FirmwareRevision: string;
|
|
1222
1076
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
1223
|
-
|
|
1077
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
1224
1078
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1225
1079
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
1226
1080
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -1300,7 +1154,7 @@ export class ColorBulb {
|
|
|
1300
1154
|
config['maxRetry'] = device.maxRetry;
|
|
1301
1155
|
}
|
|
1302
1156
|
if (Object.entries(config).length !== 0) {
|
|
1303
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${
|
|
1157
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1304
1158
|
}
|
|
1305
1159
|
}
|
|
1306
1160
|
|