@switchbot/homebridge-switchbot 2.6.0-beta.4 → 2.6.0-beta.5
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/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/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/device/striplight.d.ts +1 -9
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +137 -193
- package/dist/device/striplight.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 +153 -146
- 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/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/device/striplight.ts +148 -200
- 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 +143 -157
- package/src/settings.ts +5 -0
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.CeilingLight = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const super_stringify_1 = __importDefault(require("super-stringify"));
|
|
4
|
+
const undici_1 = require("undici");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
10
6
|
const rxjs_1 = require("rxjs");
|
|
11
7
|
const operators_1 = require("rxjs/operators");
|
|
12
8
|
const settings_1 = require("../settings");
|
|
13
|
-
const utils_1 = require("../utils");
|
|
14
9
|
/**
|
|
15
10
|
* Platform Accessory
|
|
16
11
|
* An instance of this class is created for each accessory your platform registers
|
|
@@ -146,7 +141,7 @@ class CeilingLight {
|
|
|
146
141
|
catch (e) {
|
|
147
142
|
this.apiError(e);
|
|
148
143
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
149
|
-
+ ` Error Message: ${
|
|
144
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
150
145
|
}
|
|
151
146
|
this.ceilingLightUpdateInProgress = false;
|
|
152
147
|
});
|
|
@@ -209,14 +204,14 @@ class CeilingLight {
|
|
|
209
204
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
210
205
|
// Color, Hue & Brightness
|
|
211
206
|
if (this.color) {
|
|
212
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${
|
|
207
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
|
|
213
208
|
const [red, green, blue] = this.color.split(':');
|
|
214
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${
|
|
215
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${
|
|
216
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${
|
|
209
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
210
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
211
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
217
212
|
const [hue, saturation] = (0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue));
|
|
218
213
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
219
|
-
+ ` hs: ${
|
|
214
|
+
+ ` hs: ${JSON.stringify((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
|
|
220
215
|
// Hue
|
|
221
216
|
this.Hue = hue;
|
|
222
217
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
@@ -274,7 +269,7 @@ class CeilingLight {
|
|
|
274
269
|
this.address = ad.address;
|
|
275
270
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
276
271
|
+ ` BLE Address Found: ${this.address}`);
|
|
277
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
272
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
278
273
|
this.serviceData = ad.serviceData;
|
|
279
274
|
//this.state = ad.serviceData.state;
|
|
280
275
|
//this.delay = ad.serviceData.delay;
|
|
@@ -283,7 +278,7 @@ class CeilingLight {
|
|
|
283
278
|
//this.wifiRssi = ad.serviceData.wifiRssi;
|
|
284
279
|
//this.overload = ad.serviceData.overload;
|
|
285
280
|
//this.currentPower = ad.serviceData.currentPower;
|
|
286
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
281
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
287
282
|
/*this.debugLog(
|
|
288
283
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
289
284
|
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
@@ -309,7 +304,7 @@ class CeilingLight {
|
|
|
309
304
|
.catch(async (e) => {
|
|
310
305
|
this.apiError(e);
|
|
311
306
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
312
|
-
+ ` Connection, Error Message: ${
|
|
307
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
313
308
|
await this.BLERefreshConnection(switchbot);
|
|
314
309
|
});
|
|
315
310
|
}
|
|
@@ -320,58 +315,25 @@ class CeilingLight {
|
|
|
320
315
|
async openAPIRefreshStatus() {
|
|
321
316
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
322
317
|
try {
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
326
|
-
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
327
|
-
const sign = signTerm.toString('base64');
|
|
328
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
329
|
-
const options = {
|
|
330
|
-
hostname: settings_1.HostDomain,
|
|
331
|
-
port: 443,
|
|
332
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
|
|
333
|
-
method: 'GET',
|
|
334
|
-
headers: {
|
|
335
|
-
Authorization: this.platform.config.credentials?.token,
|
|
336
|
-
sign: sign,
|
|
337
|
-
nonce: nonce,
|
|
338
|
-
t: t,
|
|
339
|
-
'Content-Type': 'application/json',
|
|
340
|
-
},
|
|
341
|
-
};
|
|
342
|
-
const req = https_1.default.request(options, (res) => {
|
|
343
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
344
|
-
this.statusCode({ res });
|
|
345
|
-
let rawData = '';
|
|
346
|
-
res.on('data', (d) => {
|
|
347
|
-
rawData += d;
|
|
348
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
349
|
-
});
|
|
350
|
-
res.on('end', () => {
|
|
351
|
-
try {
|
|
352
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
353
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
354
|
-
this.power = this.deviceStatus.body.power;
|
|
355
|
-
this.color = this.deviceStatus.body.color;
|
|
356
|
-
this.brightness = this.deviceStatus.body.brightness;
|
|
357
|
-
this.colorTemperature = this.deviceStatus.body.colorTemperature;
|
|
358
|
-
this.openAPIparseStatus();
|
|
359
|
-
this.updateHomeKitCharacteristics();
|
|
360
|
-
}
|
|
361
|
-
catch (e) {
|
|
362
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
req.on('error', (e) => {
|
|
367
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
318
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/status`, {
|
|
319
|
+
headers: this.platform.generateHeaders(),
|
|
368
320
|
});
|
|
369
|
-
|
|
321
|
+
const deviceStatus = await body.json();
|
|
322
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
323
|
+
this.statusCode(statusCode);
|
|
324
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
325
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
326
|
+
this.power = deviceStatus.body.power;
|
|
327
|
+
this.color = deviceStatus.body.color;
|
|
328
|
+
this.brightness = deviceStatus.body.brightness;
|
|
329
|
+
this.colorTemperature = deviceStatus.body.colorTemperature;
|
|
330
|
+
this.openAPIparseStatus();
|
|
331
|
+
this.updateHomeKitCharacteristics();
|
|
370
332
|
}
|
|
371
333
|
catch (e) {
|
|
372
334
|
this.apiError(e);
|
|
373
335
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
374
|
-
+ ` Connection, Error Message: ${
|
|
336
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
375
337
|
}
|
|
376
338
|
}
|
|
377
339
|
/**
|
|
@@ -444,7 +406,7 @@ class CeilingLight {
|
|
|
444
406
|
.catch(async (e) => {
|
|
445
407
|
this.apiError(e);
|
|
446
408
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
447
|
-
+ ` Connection, Error Message: ${
|
|
409
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
448
410
|
await this.BLEPushConnection();
|
|
449
411
|
});
|
|
450
412
|
}
|
|
@@ -454,258 +416,148 @@ class CeilingLight {
|
|
|
454
416
|
}
|
|
455
417
|
}
|
|
456
418
|
async openAPIpushChanges() {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const nonce = 'requestID';
|
|
463
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
464
|
-
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
465
|
-
.update(Buffer.from(data, 'utf-8'))
|
|
466
|
-
.digest();
|
|
467
|
-
const sign = signTerm.toString('base64');
|
|
468
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
469
|
-
let command = '';
|
|
470
|
-
if (this.On) {
|
|
471
|
-
command = 'turnOn';
|
|
472
|
-
}
|
|
473
|
-
else {
|
|
474
|
-
command = 'turnOff';
|
|
475
|
-
}
|
|
476
|
-
const body = (0, super_stringify_1.default)({
|
|
477
|
-
'command': `${command}`,
|
|
478
|
-
'parameter': 'default',
|
|
479
|
-
'commandType': 'command',
|
|
480
|
-
});
|
|
481
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
482
|
-
const options = {
|
|
483
|
-
hostname: settings_1.HostDomain,
|
|
484
|
-
port: 443,
|
|
485
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
486
|
-
method: 'POST',
|
|
487
|
-
headers: {
|
|
488
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
489
|
-
'sign': sign,
|
|
490
|
-
'nonce': nonce,
|
|
491
|
-
't': t,
|
|
492
|
-
'Content-Type': 'application/json',
|
|
493
|
-
'Content-Length': body.length,
|
|
494
|
-
},
|
|
495
|
-
};
|
|
496
|
-
const req = https_1.default.request(options, res => {
|
|
497
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
498
|
-
this.statusCode({ res });
|
|
499
|
-
res.on('data', d => {
|
|
500
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
501
|
-
});
|
|
502
|
-
});
|
|
503
|
-
req.on('error', (e) => {
|
|
504
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
505
|
-
});
|
|
506
|
-
req.write(body);
|
|
507
|
-
req.end();
|
|
508
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
419
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
420
|
+
if (this.On !== this.accessory.context.On) {
|
|
421
|
+
let command = '';
|
|
422
|
+
if (this.On) {
|
|
423
|
+
command = 'turnOn';
|
|
509
424
|
}
|
|
510
425
|
else {
|
|
511
|
-
|
|
512
|
-
+ `OnCached: ${this.accessory.context.On}`);
|
|
513
|
-
}
|
|
514
|
-
// Push Brightness Update
|
|
515
|
-
if (this.On) {
|
|
516
|
-
await this.pushBrightnessChanges();
|
|
426
|
+
command = 'turnOff';
|
|
517
427
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
428
|
+
const body = JSON.stringify({
|
|
429
|
+
'command': `${command}`,
|
|
430
|
+
'parameter': 'default',
|
|
431
|
+
'commandType': 'command',
|
|
432
|
+
});
|
|
433
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
434
|
+
try {
|
|
435
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
|
|
436
|
+
method: 'POST',
|
|
437
|
+
headers: this.platform.generateHeaders(),
|
|
438
|
+
});
|
|
439
|
+
const deviceStatus = await body.json();
|
|
440
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
441
|
+
this.statusCode(statusCode);
|
|
442
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
521
443
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
444
|
+
catch (e) {
|
|
445
|
+
this.apiError(e);
|
|
446
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
447
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
525
448
|
}
|
|
526
449
|
}
|
|
527
|
-
|
|
528
|
-
this.
|
|
529
|
-
|
|
530
|
-
|
|
450
|
+
else {
|
|
451
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
|
|
452
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
453
|
+
}
|
|
454
|
+
// Push Hue & Saturation Update
|
|
455
|
+
if (this.On) {
|
|
456
|
+
await this.pushHueSaturationChanges();
|
|
457
|
+
}
|
|
458
|
+
// Push ColorTemperature Update
|
|
459
|
+
if (this.On) {
|
|
460
|
+
await this.pushColorTemperatureChanges();
|
|
461
|
+
}
|
|
462
|
+
// Push Brightness Update
|
|
463
|
+
if (this.On) {
|
|
464
|
+
await this.pushBrightnessChanges();
|
|
531
465
|
}
|
|
532
466
|
}
|
|
533
467
|
async pushHueSaturationChanges() {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
const sign = signTerm.toString('base64');
|
|
549
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
550
|
-
const body = (0, super_stringify_1.default)({
|
|
551
|
-
'command': 'setColor',
|
|
552
|
-
'parameter': `${red}:${green}:${blue}`,
|
|
553
|
-
'commandType': 'command',
|
|
554
|
-
});
|
|
555
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
556
|
-
const options = {
|
|
557
|
-
hostname: settings_1.HostDomain,
|
|
558
|
-
port: 443,
|
|
559
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
468
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
|
|
469
|
+
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
470
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
471
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
472
|
+
const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
|
|
473
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
474
|
+
const body = JSON.stringify({
|
|
475
|
+
'command': 'setColor',
|
|
476
|
+
'parameter': `${red}:${green}:${blue}`,
|
|
477
|
+
'commandType': 'command',
|
|
478
|
+
});
|
|
479
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
480
|
+
try {
|
|
481
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
|
|
560
482
|
method: 'POST',
|
|
561
|
-
headers:
|
|
562
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
563
|
-
'sign': sign,
|
|
564
|
-
'nonce': nonce,
|
|
565
|
-
't': t,
|
|
566
|
-
'Content-Type': 'application/json',
|
|
567
|
-
'Content-Length': body.length,
|
|
568
|
-
},
|
|
569
|
-
};
|
|
570
|
-
const req = https_1.default.request(options, res => {
|
|
571
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges statusCode: ${res.statusCode}`);
|
|
572
|
-
res.on('data', d => {
|
|
573
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
574
|
-
});
|
|
575
|
-
});
|
|
576
|
-
req.on('error', (e) => {
|
|
577
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
483
|
+
headers: this.platform.generateHeaders(),
|
|
578
484
|
});
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
this.
|
|
485
|
+
const deviceStatus = await body.json();
|
|
486
|
+
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
487
|
+
this.statusCode(statusCode);
|
|
488
|
+
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
582
489
|
}
|
|
583
|
-
|
|
584
|
-
this.
|
|
585
|
-
|
|
490
|
+
catch (e) {
|
|
491
|
+
this.apiError(e);
|
|
492
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
|
|
493
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
586
494
|
}
|
|
587
495
|
}
|
|
588
|
-
|
|
589
|
-
this.
|
|
590
|
-
|
|
591
|
-
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
496
|
+
else {
|
|
497
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, `
|
|
498
|
+
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
592
499
|
}
|
|
593
500
|
}
|
|
594
501
|
async pushColorTemperatureChanges() {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
const sign = signTerm.toString('base64');
|
|
608
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
609
|
-
const body = (0, super_stringify_1.default)({
|
|
610
|
-
'command': 'setColorTemperature',
|
|
611
|
-
'parameter': `${kelvin}`,
|
|
612
|
-
'commandType': 'command',
|
|
613
|
-
});
|
|
614
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
615
|
-
const options = {
|
|
616
|
-
hostname: settings_1.HostDomain,
|
|
617
|
-
port: 443,
|
|
618
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
502
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges`);
|
|
503
|
+
if (this.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
504
|
+
const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
|
|
505
|
+
this.cacheKelvin = kelvin;
|
|
506
|
+
const body = JSON.stringify({
|
|
507
|
+
'command': 'setColorTemperature',
|
|
508
|
+
'parameter': `${kelvin}`,
|
|
509
|
+
'commandType': 'command',
|
|
510
|
+
});
|
|
511
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
512
|
+
try {
|
|
513
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
|
|
619
514
|
method: 'POST',
|
|
620
|
-
headers:
|
|
621
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
622
|
-
'sign': sign,
|
|
623
|
-
'nonce': nonce,
|
|
624
|
-
't': t,
|
|
625
|
-
'Content-Type': 'application/json',
|
|
626
|
-
'Content-Length': body.length,
|
|
627
|
-
},
|
|
628
|
-
};
|
|
629
|
-
const req = https_1.default.request(options, res => {
|
|
630
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
631
|
-
res.on('data', d => {
|
|
632
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
633
|
-
});
|
|
634
|
-
});
|
|
635
|
-
req.on('error', (e) => {
|
|
636
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
515
|
+
headers: this.platform.generateHeaders(),
|
|
637
516
|
});
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
this.
|
|
641
|
-
this.
|
|
517
|
+
const deviceStatus = await body.json();
|
|
518
|
+
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
519
|
+
this.statusCode(statusCode);
|
|
520
|
+
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
642
521
|
}
|
|
643
|
-
|
|
644
|
-
this.
|
|
645
|
-
|
|
522
|
+
catch (e) {
|
|
523
|
+
this.apiError(e);
|
|
524
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with ${this.device.connectionType}`
|
|
525
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
646
526
|
}
|
|
647
527
|
}
|
|
648
|
-
|
|
649
|
-
this.
|
|
650
|
-
|
|
651
|
-
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
528
|
+
else {
|
|
529
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.` +
|
|
530
|
+
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
652
531
|
}
|
|
653
532
|
}
|
|
654
533
|
async pushBrightnessChanges() {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
const sign = signTerm.toString('base64');
|
|
666
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
667
|
-
const body = (0, super_stringify_1.default)({
|
|
668
|
-
'command': 'setBrightness',
|
|
669
|
-
'parameter': `${this.Brightness}`,
|
|
670
|
-
'commandType': 'command',
|
|
671
|
-
});
|
|
672
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
673
|
-
const options = {
|
|
674
|
-
hostname: settings_1.HostDomain,
|
|
675
|
-
port: 443,
|
|
676
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
534
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
535
|
+
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
536
|
+
const body = JSON.stringify({
|
|
537
|
+
'command': 'setBrightness',
|
|
538
|
+
'parameter': `${this.Brightness}`,
|
|
539
|
+
'commandType': 'command',
|
|
540
|
+
});
|
|
541
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
542
|
+
try {
|
|
543
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
|
|
677
544
|
method: 'POST',
|
|
678
|
-
headers:
|
|
679
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
680
|
-
'sign': sign,
|
|
681
|
-
'nonce': nonce,
|
|
682
|
-
't': t,
|
|
683
|
-
'Content-Type': 'application/json',
|
|
684
|
-
'Content-Length': body.length,
|
|
685
|
-
},
|
|
686
|
-
};
|
|
687
|
-
const req = https_1.default.request(options, res => {
|
|
688
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges statusCode: ${res.statusCode}`);
|
|
689
|
-
res.on('data', d => {
|
|
690
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
691
|
-
});
|
|
692
|
-
});
|
|
693
|
-
req.on('error', (e) => {
|
|
694
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
545
|
+
headers: this.platform.generateHeaders(),
|
|
695
546
|
});
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
this.
|
|
547
|
+
const deviceStatus = await body.json();
|
|
548
|
+
this.debugLog(`Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
549
|
+
this.statusCode(statusCode);
|
|
550
|
+
this.debugLog(`Headers: ${JSON.stringify(headers)}`);
|
|
699
551
|
}
|
|
700
|
-
|
|
701
|
-
this.
|
|
702
|
-
|
|
552
|
+
catch (e) {
|
|
553
|
+
this.apiError(e);
|
|
554
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
|
|
555
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
703
556
|
}
|
|
704
557
|
}
|
|
705
|
-
|
|
706
|
-
this.
|
|
707
|
-
|
|
708
|
-
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
558
|
+
else {
|
|
559
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
|
|
560
|
+
+ `BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
709
561
|
}
|
|
710
562
|
}
|
|
711
563
|
/**
|
|
@@ -870,7 +722,7 @@ class CeilingLight {
|
|
|
870
722
|
});
|
|
871
723
|
// Set an event handler
|
|
872
724
|
switchbot.onadvertisement = (ad) => {
|
|
873
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${
|
|
725
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
874
726
|
};
|
|
875
727
|
await (0, utils_1.sleep)(10000);
|
|
876
728
|
// Stop to monitor
|
|
@@ -933,38 +785,39 @@ class CeilingLight {
|
|
|
933
785
|
}
|
|
934
786
|
}
|
|
935
787
|
}
|
|
936
|
-
async statusCode(
|
|
937
|
-
switch (
|
|
788
|
+
async statusCode(statusCode) {
|
|
789
|
+
switch (statusCode) {
|
|
938
790
|
case 151:
|
|
939
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this
|
|
791
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
940
792
|
break;
|
|
941
793
|
case 152:
|
|
942
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found
|
|
794
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
943
795
|
break;
|
|
944
796
|
case 160:
|
|
945
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported
|
|
797
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
946
798
|
break;
|
|
947
799
|
case 161:
|
|
948
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline
|
|
949
|
-
|
|
800
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
801
|
+
this.offlineOff();
|
|
950
802
|
break;
|
|
951
803
|
case 171:
|
|
952
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline
|
|
953
|
-
|
|
804
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
|
|
805
|
+
+ `Hub: ${this.device.hubDeviceId}`);
|
|
806
|
+
this.offlineOff();
|
|
954
807
|
break;
|
|
955
808
|
case 190:
|
|
956
809
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
957
|
-
` Or command
|
|
810
|
+
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
958
811
|
break;
|
|
959
812
|
case 100:
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
813
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
814
|
+
break;
|
|
815
|
+
case 200:
|
|
816
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
963
817
|
break;
|
|
964
818
|
default:
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
}
|
|
819
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
|
|
820
|
+
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
968
821
|
}
|
|
969
822
|
}
|
|
970
823
|
async offlineOff() {
|
|
@@ -1068,7 +921,7 @@ class CeilingLight {
|
|
|
1068
921
|
config['maxRetry'] = device.maxRetry;
|
|
1069
922
|
}
|
|
1070
923
|
if (Object.entries(config).length !== 0) {
|
|
1071
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${
|
|
924
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1072
925
|
}
|
|
1073
926
|
}
|
|
1074
927
|
async logs(device) {
|