@switchbot/homebridge-switchbot 2.6.0-beta.3 → 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/.github/workflows/dependabot.yml +2 -0
- 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.StripLight = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const undici_1 = require("undici");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
9
6
|
const rxjs_1 = require("rxjs");
|
|
10
|
-
const super_stringify_1 = __importDefault(require("super-stringify"));
|
|
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
|
|
@@ -145,7 +140,7 @@ class StripLight {
|
|
|
145
140
|
catch (e) {
|
|
146
141
|
this.apiError(e);
|
|
147
142
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
148
|
-
+ ` Error Message: ${
|
|
143
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
149
144
|
}
|
|
150
145
|
this.stripLightUpdateInProgress = false;
|
|
151
146
|
});
|
|
@@ -196,14 +191,14 @@ class StripLight {
|
|
|
196
191
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
197
192
|
// Color, Hue & Brightness
|
|
198
193
|
if (this.color) {
|
|
199
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${
|
|
194
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
|
|
200
195
|
const [red, green, blue] = this.color.split(':');
|
|
201
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${
|
|
202
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${
|
|
203
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${
|
|
196
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
197
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
198
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
204
199
|
const [hue, saturation] = (0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue));
|
|
205
200
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
206
|
-
+ ` hs: ${
|
|
201
|
+
+ ` hs: ${JSON.stringify((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
|
|
207
202
|
// Hue
|
|
208
203
|
this.Hue = hue;
|
|
209
204
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
@@ -254,7 +249,7 @@ class StripLight {
|
|
|
254
249
|
this.address = ad.address;
|
|
255
250
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
256
251
|
+ ` BLE Address Found: ${this.address}`);
|
|
257
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
252
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
258
253
|
this.serviceData = ad.serviceData;
|
|
259
254
|
//this.state = ad.serviceData.state;
|
|
260
255
|
//this.delay = ad.serviceData.delay;
|
|
@@ -263,7 +258,7 @@ class StripLight {
|
|
|
263
258
|
//this.wifiRssi = ad.serviceData.wifiRssi;
|
|
264
259
|
//this.overload = ad.serviceData.overload;
|
|
265
260
|
//this.currentPower = ad.serviceData.currentPower;
|
|
266
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${
|
|
261
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
267
262
|
/*this.debugLog(
|
|
268
263
|
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
269
264
|
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
@@ -289,7 +284,7 @@ class StripLight {
|
|
|
289
284
|
.catch(async (e) => {
|
|
290
285
|
this.apiError(e);
|
|
291
286
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
292
|
-
+ ` Connection, Error Message: ${
|
|
287
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
293
288
|
await this.BLERefreshConnection(switchbot);
|
|
294
289
|
});
|
|
295
290
|
}
|
|
@@ -300,57 +295,24 @@ class StripLight {
|
|
|
300
295
|
async openAPIRefreshStatus() {
|
|
301
296
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
302
297
|
try {
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
306
|
-
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
307
|
-
const sign = signTerm.toString('base64');
|
|
308
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
309
|
-
const options = {
|
|
310
|
-
hostname: settings_1.HostDomain,
|
|
311
|
-
port: 443,
|
|
312
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
|
|
313
|
-
method: 'GET',
|
|
314
|
-
headers: {
|
|
315
|
-
Authorization: this.platform.config.credentials?.token,
|
|
316
|
-
sign: sign,
|
|
317
|
-
nonce: nonce,
|
|
318
|
-
t: t,
|
|
319
|
-
'Content-Type': 'application/json',
|
|
320
|
-
},
|
|
321
|
-
};
|
|
322
|
-
const req = https_1.default.request(options, (res) => {
|
|
323
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
324
|
-
this.statusCode({ res });
|
|
325
|
-
let rawData = '';
|
|
326
|
-
res.on('data', (d) => {
|
|
327
|
-
rawData += d;
|
|
328
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
329
|
-
});
|
|
330
|
-
res.on('end', () => {
|
|
331
|
-
try {
|
|
332
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
333
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
334
|
-
this.power = this.deviceStatus.body.power;
|
|
335
|
-
this.color = this.deviceStatus.body.color;
|
|
336
|
-
this.brightness = this.deviceStatus.body.brightness;
|
|
337
|
-
this.openAPIparseStatus();
|
|
338
|
-
this.updateHomeKitCharacteristics();
|
|
339
|
-
}
|
|
340
|
-
catch (e) {
|
|
341
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
req.on('error', (e) => {
|
|
346
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
298
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/status`, {
|
|
299
|
+
headers: this.platform.generateHeaders(),
|
|
347
300
|
});
|
|
348
|
-
|
|
301
|
+
const deviceStatus = await body.json();
|
|
302
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
303
|
+
this.statusCode(statusCode);
|
|
304
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
305
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(deviceStatus)}`);
|
|
306
|
+
this.power = deviceStatus.body.power;
|
|
307
|
+
this.color = deviceStatus.body.color;
|
|
308
|
+
this.brightness = deviceStatus.body.brightness;
|
|
309
|
+
this.openAPIparseStatus();
|
|
310
|
+
this.updateHomeKitCharacteristics();
|
|
349
311
|
}
|
|
350
312
|
catch (e) {
|
|
351
313
|
this.apiError(e);
|
|
352
314
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
353
|
-
+ ` Connection, Error Message: ${
|
|
315
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
354
316
|
}
|
|
355
317
|
}
|
|
356
318
|
/**
|
|
@@ -422,7 +384,7 @@ class StripLight {
|
|
|
422
384
|
.catch(async (e) => {
|
|
423
385
|
this.apiError(e);
|
|
424
386
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
425
|
-
+ ` Connection, Error Message: ${
|
|
387
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
426
388
|
await this.BLEPushConnection();
|
|
427
389
|
});
|
|
428
390
|
// Push Brightness Update
|
|
@@ -465,7 +427,7 @@ class StripLight {
|
|
|
465
427
|
.catch(async (e) => {
|
|
466
428
|
this.apiError(e);
|
|
467
429
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushBrightnessChanges with ${this.device.connectionType}`
|
|
468
|
-
+ ` Connection, Error Message: ${
|
|
430
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
469
431
|
await this.BLEPushConnection();
|
|
470
432
|
});
|
|
471
433
|
}
|
|
@@ -477,10 +439,10 @@ class StripLight {
|
|
|
477
439
|
async BLEpushRGBChanges() {
|
|
478
440
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushRGBChanges`);
|
|
479
441
|
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
480
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${
|
|
481
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${
|
|
442
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
443
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
482
444
|
const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
|
|
483
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${
|
|
445
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
484
446
|
const switchbot = await this.platform.connectBLE();
|
|
485
447
|
// Convert to BLE Address
|
|
486
448
|
this.device.bleMac = this.device
|
|
@@ -504,7 +466,7 @@ class StripLight {
|
|
|
504
466
|
.catch(async (e) => {
|
|
505
467
|
this.apiError(e);
|
|
506
468
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushRGBChanges with ${this.device.connectionType}`
|
|
507
|
-
+ ` Connection, Error Message: ${
|
|
469
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
508
470
|
await this.BLEPushConnection();
|
|
509
471
|
});
|
|
510
472
|
}
|
|
@@ -514,133 +476,114 @@ class StripLight {
|
|
|
514
476
|
}
|
|
515
477
|
}
|
|
516
478
|
async openAPIpushChanges() {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
this.
|
|
520
|
-
if (this.On
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
479
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
480
|
+
if (this.On !== this.accessory.context.On) {
|
|
481
|
+
const command = this.On ? 'turnOn' : 'turnOff';
|
|
482
|
+
/*if (this.On) {
|
|
483
|
+
command = 'turnOn';
|
|
484
|
+
} else {
|
|
485
|
+
command = 'turnOff';
|
|
486
|
+
}*/
|
|
487
|
+
const body = JSON.stringify({
|
|
488
|
+
'command': `${command}`,
|
|
489
|
+
'parameter': 'default',
|
|
490
|
+
'commandType': 'command',
|
|
491
|
+
});
|
|
492
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
493
|
+
try {
|
|
494
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
|
|
495
|
+
method: 'POST',
|
|
496
|
+
headers: this.platform.generateHeaders(),
|
|
532
497
|
});
|
|
533
|
-
await
|
|
498
|
+
const deviceStatus = await body.json();
|
|
499
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
500
|
+
this.statusCode(statusCode);
|
|
501
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
534
502
|
}
|
|
535
|
-
|
|
536
|
-
this.
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
// Push Brightness Update
|
|
540
|
-
if (this.On) {
|
|
541
|
-
await this.pushBrightnessChanges();
|
|
542
|
-
}
|
|
543
|
-
// Push Hue & Saturation Update
|
|
544
|
-
if (this.On) {
|
|
545
|
-
await this.pushHueSaturationChanges();
|
|
503
|
+
catch (e) {
|
|
504
|
+
this.apiError(e);
|
|
505
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
506
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
546
507
|
}
|
|
547
508
|
}
|
|
548
|
-
|
|
549
|
-
this.
|
|
550
|
-
|
|
551
|
-
|
|
509
|
+
else {
|
|
510
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
|
|
511
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
512
|
+
}
|
|
513
|
+
// Push Hue & Saturation Update
|
|
514
|
+
if (this.On) {
|
|
515
|
+
await this.pushHueSaturationChanges();
|
|
516
|
+
}
|
|
517
|
+
// Push Brightness Update
|
|
518
|
+
if (this.On) {
|
|
519
|
+
await this.pushBrightnessChanges();
|
|
552
520
|
}
|
|
553
521
|
}
|
|
554
522
|
async pushHueSaturationChanges() {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
523
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
|
|
524
|
+
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
525
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
526
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
527
|
+
const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
|
|
528
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
529
|
+
// Make Push On request to the API
|
|
530
|
+
const body = JSON.stringify({
|
|
531
|
+
'command': 'setColor',
|
|
532
|
+
'parameter': `${red}:${green}:${blue}`,
|
|
533
|
+
'commandType': 'command',
|
|
534
|
+
});
|
|
535
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
536
|
+
try {
|
|
537
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
|
|
538
|
+
method: 'POST',
|
|
539
|
+
headers: this.platform.generateHeaders(),
|
|
568
540
|
});
|
|
569
|
-
await
|
|
541
|
+
const deviceStatus = await body.json();
|
|
542
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
543
|
+
this.statusCode(statusCode);
|
|
544
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
570
545
|
}
|
|
571
|
-
|
|
572
|
-
this.
|
|
573
|
-
|
|
546
|
+
catch (e) {
|
|
547
|
+
this.apiError(e);
|
|
548
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
|
|
549
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
574
550
|
}
|
|
575
551
|
}
|
|
576
|
-
|
|
577
|
-
this.
|
|
578
|
-
|
|
579
|
-
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
552
|
+
else {
|
|
553
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, `
|
|
554
|
+
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
580
555
|
}
|
|
581
556
|
}
|
|
582
557
|
async pushBrightnessChanges() {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
558
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
559
|
+
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
560
|
+
const body = JSON.stringify({
|
|
561
|
+
'command': 'setBrightness',
|
|
562
|
+
'parameter': `${this.Brightness}`,
|
|
563
|
+
'commandType': 'command',
|
|
564
|
+
});
|
|
565
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
566
|
+
try {
|
|
567
|
+
const { body, statusCode, headers } = await (0, undici_1.request)(`${settings_1.Devices}/${this.device.deviceId}/commands`, {
|
|
568
|
+
method: 'POST',
|
|
569
|
+
headers: this.platform.generateHeaders(),
|
|
592
570
|
});
|
|
593
|
-
await
|
|
571
|
+
const deviceStatus = await body.json();
|
|
572
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Devices: ${JSON.stringify(deviceStatus.body)}`);
|
|
573
|
+
this.statusCode(statusCode);
|
|
574
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Headers: ${JSON.stringify(headers)}`);
|
|
594
575
|
}
|
|
595
|
-
|
|
596
|
-
this.
|
|
597
|
-
|
|
576
|
+
catch (e) {
|
|
577
|
+
this.apiError(e);
|
|
578
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
|
|
579
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
598
580
|
}
|
|
599
581
|
}
|
|
600
|
-
|
|
601
|
-
this.
|
|
602
|
-
|
|
603
|
-
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
582
|
+
else {
|
|
583
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges,` + `Brightness: ${this.Brightness}, `
|
|
584
|
+
+ `BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
604
585
|
}
|
|
605
586
|
}
|
|
606
|
-
async request({ body, change }) {
|
|
607
|
-
const t = Date.now();
|
|
608
|
-
const nonce = 'requestID';
|
|
609
|
-
const data = this.platform.config.credentials?.token + t + nonce;
|
|
610
|
-
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
611
|
-
.update(Buffer.from(data, 'utf-8'))
|
|
612
|
-
.digest();
|
|
613
|
-
const sign = signTerm.toString('base64');
|
|
614
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
615
|
-
const options = {
|
|
616
|
-
hostname: settings_1.HostDomain,
|
|
617
|
-
port: 443,
|
|
618
|
-
path: `${settings_1.DevicePath}/${this.device.deviceId}/commands`,
|
|
619
|
-
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
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`);
|
|
630
|
-
const req = https_1.default.request(options, res => {
|
|
631
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${change} statusCode: ${res.statusCode}`);
|
|
632
|
-
this.statusCode({ res });
|
|
633
|
-
res.on('data', d => {
|
|
634
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
635
|
-
});
|
|
636
|
-
});
|
|
637
|
-
req.on('error', (e) => {
|
|
638
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
639
|
-
});
|
|
640
|
-
req.write(body);
|
|
641
|
-
req.end();
|
|
642
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${change} req: ${(0, super_stringify_1.default)(req)}`);
|
|
643
|
-
}
|
|
644
587
|
/**
|
|
645
588
|
* Handle requests to set the value of the "On" characteristic
|
|
646
589
|
*/
|
|
@@ -793,7 +736,7 @@ class StripLight {
|
|
|
793
736
|
});
|
|
794
737
|
// Set an event handler
|
|
795
738
|
switchbot.onadvertisement = (ad) => {
|
|
796
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${
|
|
739
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
797
740
|
};
|
|
798
741
|
await (0, utils_1.sleep)(10000);
|
|
799
742
|
// Stop to monitor
|
|
@@ -866,38 +809,39 @@ class StripLight {
|
|
|
866
809
|
}
|
|
867
810
|
}
|
|
868
811
|
}
|
|
869
|
-
async statusCode(
|
|
870
|
-
switch (
|
|
812
|
+
async statusCode(statusCode) {
|
|
813
|
+
switch (statusCode) {
|
|
871
814
|
case 151:
|
|
872
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this
|
|
815
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
873
816
|
break;
|
|
874
817
|
case 152:
|
|
875
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found
|
|
818
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
876
819
|
break;
|
|
877
820
|
case 160:
|
|
878
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported
|
|
821
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
879
822
|
break;
|
|
880
823
|
case 161:
|
|
881
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline
|
|
882
|
-
|
|
824
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
825
|
+
this.offlineOff();
|
|
883
826
|
break;
|
|
884
827
|
case 171:
|
|
885
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline
|
|
886
|
-
|
|
828
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
|
|
829
|
+
+ `Hub: ${this.device.hubDeviceId}`);
|
|
830
|
+
this.offlineOff();
|
|
887
831
|
break;
|
|
888
832
|
case 190:
|
|
889
833
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
890
|
-
` Or command
|
|
834
|
+
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
891
835
|
break;
|
|
892
836
|
case 100:
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
837
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
838
|
+
break;
|
|
839
|
+
case 200:
|
|
840
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
896
841
|
break;
|
|
897
842
|
default:
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
}
|
|
843
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: `
|
|
844
|
+
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
901
845
|
}
|
|
902
846
|
}
|
|
903
847
|
async offlineOff() {
|
|
@@ -1000,7 +944,7 @@ class StripLight {
|
|
|
1000
944
|
config['maxRetry'] = device.maxRetry;
|
|
1001
945
|
}
|
|
1002
946
|
if (Object.entries(config).length !== 0) {
|
|
1003
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${
|
|
947
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1004
948
|
}
|
|
1005
949
|
}
|
|
1006
950
|
async logs(device) {
|