@switchbot/homebridge-switchbot 2.0.0-beta.18 → 2.0.0-beta.19
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/CHANGELOG.md +1 -1
- package/config.schema.json +11 -2
- package/dist/device/bot.d.ts +2 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +201 -163
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -218
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +85 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +166 -136
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +126 -115
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +156 -130
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +2 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +85 -64
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +2 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +78 -59
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +76 -57
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +133 -107
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +2 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +224 -195
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +127 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -0
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +83 -66
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -6
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +83 -68
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -5
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +90 -75
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -6
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +83 -68
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -6
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +93 -78
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -6
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +68 -52
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +83 -69
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -0
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +75 -60
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +12 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +200 -163
- package/src/device/colorbulb.ts +252 -221
- package/src/device/contact.ts +85 -66
- package/src/device/curtain.ts +165 -136
- package/src/device/humidifier.ts +126 -115
- package/src/device/lock.ts +156 -131
- package/src/device/meter.ts +85 -64
- package/src/device/meterplus.ts +78 -59
- package/src/device/motion.ts +76 -57
- package/src/device/plug.ts +132 -107
- package/src/device/striplight.ts +226 -198
- package/src/irdevice/airconditioner.ts +126 -103
- package/src/irdevice/airpurifier.ts +84 -66
- package/src/irdevice/camera.ts +84 -68
- package/src/irdevice/fan.ts +91 -75
- package/src/irdevice/light.ts +84 -68
- package/src/irdevice/other.ts +94 -78
- package/src/irdevice/tv.ts +69 -53
- package/src/irdevice/vacuumcleaner.ts +83 -68
- package/src/irdevice/waterheater.ts +76 -60
- package/src/settings.ts +12 -11
package/src/device/colorbulb.ts
CHANGED
|
@@ -48,6 +48,7 @@ export class ColorBulb {
|
|
|
48
48
|
deviceLogging!: string;
|
|
49
49
|
deviceRefreshRate!: number;
|
|
50
50
|
adaptiveLightingShift?: number;
|
|
51
|
+
OpenAPI?: boolean;
|
|
51
52
|
|
|
52
53
|
// Adaptive Lighting
|
|
53
54
|
AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
|
|
@@ -64,6 +65,7 @@ export class ColorBulb {
|
|
|
64
65
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
65
66
|
// default placeholders
|
|
66
67
|
this.logs(device);
|
|
68
|
+
this.openAPI();
|
|
67
69
|
this.scan(device);
|
|
68
70
|
this.refreshRate(device);
|
|
69
71
|
this.adaptiveLighting(device);
|
|
@@ -105,7 +107,7 @@ export class ColorBulb {
|
|
|
105
107
|
this.accessory.removeService(this.lightBulbService);
|
|
106
108
|
this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
107
109
|
this.accessory.context.adaptiveLighting = false;
|
|
108
|
-
this.debugLog(
|
|
110
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -134,7 +136,7 @@ export class ColorBulb {
|
|
|
134
136
|
.onSet(this.BrightnessSet.bind(this));
|
|
135
137
|
|
|
136
138
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
137
|
-
this.debugLog(
|
|
139
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add ColorTemperature Characteristic`);
|
|
138
140
|
this.lightBulbService
|
|
139
141
|
.getCharacteristic(this.platform.Characteristic.ColorTemperature)
|
|
140
142
|
.setProps({
|
|
@@ -173,7 +175,7 @@ export class ColorBulb {
|
|
|
173
175
|
})
|
|
174
176
|
.onSet(this.SaturationSet.bind(this));
|
|
175
177
|
|
|
176
|
-
this.debugLog(
|
|
178
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
177
179
|
if (this.adaptiveLightingShift !== -1) {
|
|
178
180
|
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
|
|
179
181
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
@@ -181,7 +183,7 @@ export class ColorBulb {
|
|
|
181
183
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
182
184
|
this.accessory.context.adaptiveLighting = true;
|
|
183
185
|
this.debugLog(
|
|
184
|
-
|
|
186
|
+
`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
185
187
|
` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
186
188
|
);
|
|
187
189
|
}
|
|
@@ -209,9 +211,10 @@ export class ColorBulb {
|
|
|
209
211
|
try {
|
|
210
212
|
await this.pushChanges();
|
|
211
213
|
} catch (e: any) {
|
|
212
|
-
this.errorLog(
|
|
214
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
|
|
213
215
|
if (this.deviceLogging.includes('debug')) {
|
|
214
|
-
this.errorLog(
|
|
216
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,`
|
|
217
|
+
+ ` Error Message: ${superStringify(e.message)}`);
|
|
215
218
|
}
|
|
216
219
|
this.apiError(e);
|
|
217
220
|
}
|
|
@@ -235,7 +238,7 @@ export class ColorBulb {
|
|
|
235
238
|
}
|
|
236
239
|
|
|
237
240
|
async BLEparseStatus(): Promise<void> {
|
|
238
|
-
this.debugLog(
|
|
241
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
|
|
239
242
|
// State
|
|
240
243
|
switch (this.state) {
|
|
241
244
|
case 'on':
|
|
@@ -244,7 +247,7 @@ export class ColorBulb {
|
|
|
244
247
|
default:
|
|
245
248
|
this.On = false;
|
|
246
249
|
}
|
|
247
|
-
this.debugLog(
|
|
250
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
248
251
|
}
|
|
249
252
|
|
|
250
253
|
async openAPIparseStatus() {
|
|
@@ -255,41 +258,42 @@ export class ColorBulb {
|
|
|
255
258
|
default:
|
|
256
259
|
this.On = false;
|
|
257
260
|
}
|
|
258
|
-
this.debugLog(
|
|
261
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
259
262
|
|
|
260
263
|
// Brightness
|
|
261
264
|
this.Brightness = Number(this.brightness);
|
|
262
|
-
this.debugLog(
|
|
265
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
263
266
|
|
|
264
267
|
// Color, Hue & Brightness
|
|
265
268
|
if (this.color) {
|
|
266
|
-
this.debugLog(
|
|
269
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${superStringify(this.color)}`);
|
|
267
270
|
const [red, green, blue] = this.color!.split(':');
|
|
268
|
-
this.debugLog(
|
|
269
|
-
this.debugLog(
|
|
270
|
-
this.debugLog(
|
|
271
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${superStringify(red)}`);
|
|
272
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${superStringify(green)}`);
|
|
273
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${superStringify(blue)}`);
|
|
271
274
|
|
|
272
275
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
273
|
-
this.debugLog(
|
|
276
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
277
|
+
+ ` hs: ${superStringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
274
278
|
|
|
275
279
|
// Hue
|
|
276
280
|
this.Hue = hue;
|
|
277
|
-
this.debugLog(
|
|
281
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
278
282
|
|
|
279
283
|
// Saturation
|
|
280
284
|
this.Saturation = saturation;
|
|
281
|
-
this.debugLog(
|
|
285
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
282
286
|
}
|
|
283
287
|
|
|
284
288
|
// ColorTemperature
|
|
285
289
|
if (!Number.isNaN(this.colorTemperature)) {
|
|
286
|
-
this.debugLog(
|
|
290
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
|
|
287
291
|
const mired = Math.round(1000000 / this.colorTemperature!);
|
|
288
292
|
|
|
289
293
|
this.ColorTemperature = Number(mired);
|
|
290
294
|
|
|
291
295
|
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
292
|
-
this.debugLog(
|
|
296
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
293
297
|
}
|
|
294
298
|
}
|
|
295
299
|
|
|
@@ -302,14 +306,14 @@ export class ColorBulb {
|
|
|
302
306
|
}
|
|
303
307
|
|
|
304
308
|
async BLERefreshStatus(): Promise<void> {
|
|
305
|
-
this.debugLog(
|
|
309
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE refreshStatus`);
|
|
306
310
|
const switchbot = await this.platform.connectBLE();
|
|
307
311
|
// Convert to BLE Address
|
|
308
312
|
this.device.bleMac = this.device
|
|
309
313
|
.deviceId!.match(/.{1,2}/g)!
|
|
310
314
|
.join(':')
|
|
311
315
|
.toLowerCase();
|
|
312
|
-
this.debugLog(
|
|
316
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
313
317
|
this.getCustomBLEAddress(switchbot);
|
|
314
318
|
// Start to monitor advertisement packets
|
|
315
319
|
if (switchbot !== false) {
|
|
@@ -325,10 +329,10 @@ export class ColorBulb {
|
|
|
325
329
|
if (this.deviceLogging.includes('debug')) {
|
|
326
330
|
this.infoLog(this.address);
|
|
327
331
|
this.infoLog(this.device.bleMac);
|
|
328
|
-
this.infoLog(
|
|
329
|
-
this.infoLog(
|
|
332
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
333
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
330
334
|
}
|
|
331
|
-
this.debugLog(
|
|
335
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
332
336
|
this.serviceData = ad.serviceData;
|
|
333
337
|
//this.state = ad.serviceData.state;
|
|
334
338
|
//this.delay = ad.serviceData.delay;
|
|
@@ -337,19 +341,19 @@ export class ColorBulb {
|
|
|
337
341
|
//this.wifiRssi = ad.serviceData.wifiRssi;
|
|
338
342
|
//this.overload = ad.serviceData.overload;
|
|
339
343
|
//this.currentPower = ad.serviceData.currentPower;
|
|
340
|
-
this.debugLog(
|
|
344
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
341
345
|
/*this.debugLog(
|
|
342
|
-
|
|
346
|
+
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
343
347
|
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
344
348
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
345
349
|
);*/
|
|
346
350
|
|
|
347
351
|
if (this.serviceData) {
|
|
348
352
|
this.connected = true;
|
|
349
|
-
this.debugLog(
|
|
353
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
350
354
|
} else {
|
|
351
355
|
this.connected = false;
|
|
352
|
-
this.debugLog(
|
|
356
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
353
357
|
}
|
|
354
358
|
};
|
|
355
359
|
// Wait 2 seconds
|
|
@@ -362,23 +366,24 @@ export class ColorBulb {
|
|
|
362
366
|
this.parseStatus();
|
|
363
367
|
this.updateHomeKitCharacteristics();
|
|
364
368
|
} else {
|
|
365
|
-
this.errorLog(
|
|
369
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
366
370
|
if (this.platform.config.credentials?.token) {
|
|
367
|
-
this.warnLog(
|
|
371
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
368
372
|
this.SwitchToOpenAPI = true;
|
|
369
373
|
await this.openAPIRefreshStatus();
|
|
370
374
|
}
|
|
371
375
|
}
|
|
372
376
|
})
|
|
373
377
|
.catch(async (e: any) => {
|
|
374
|
-
this.errorLog(
|
|
378
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
375
379
|
if (this.deviceLogging.includes('debug')) {
|
|
376
380
|
this.errorLog(
|
|
377
|
-
|
|
381
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
382
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
378
383
|
);
|
|
379
384
|
}
|
|
380
385
|
if (this.platform.config.credentials?.token) {
|
|
381
|
-
this.warnLog(
|
|
386
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
382
387
|
this.SwitchToOpenAPI = true;
|
|
383
388
|
await this.openAPIRefreshStatus();
|
|
384
389
|
}
|
|
@@ -391,7 +396,7 @@ export class ColorBulb {
|
|
|
391
396
|
|
|
392
397
|
async getCustomBLEAddress(switchbot: any) {
|
|
393
398
|
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
394
|
-
this.debugLog(
|
|
399
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
|
|
395
400
|
(async () => {
|
|
396
401
|
// Start to monitor advertisement packets
|
|
397
402
|
await switchbot.startScan({
|
|
@@ -399,7 +404,7 @@ export class ColorBulb {
|
|
|
399
404
|
});
|
|
400
405
|
// Set an event handler
|
|
401
406
|
switchbot.onadvertisement = (ad: any) => {
|
|
402
|
-
this.warnLog(
|
|
407
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
403
408
|
};
|
|
404
409
|
await switchbot.wait(10000);
|
|
405
410
|
// Stop to monitor
|
|
@@ -409,69 +414,74 @@ export class ColorBulb {
|
|
|
409
414
|
}
|
|
410
415
|
|
|
411
416
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
412
|
-
this.errorLog(
|
|
417
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
413
418
|
if (this.platform.config.credentials?.token) {
|
|
414
|
-
this.warnLog(
|
|
419
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
415
420
|
this.SwitchToOpenAPI = true;
|
|
416
421
|
await this.openAPIRefreshStatus();
|
|
417
422
|
}
|
|
418
423
|
}
|
|
419
424
|
|
|
420
425
|
async openAPIRefreshStatus() {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
426
|
+
if (this.OpenAPI) {
|
|
427
|
+
try {
|
|
428
|
+
const t = Date.now();
|
|
429
|
+
const nonce = 'requestID';
|
|
430
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
431
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
432
|
+
const sign = signTerm.toString('base64');
|
|
433
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
434
|
+
const options = {
|
|
435
|
+
hostname: HostDomain,
|
|
436
|
+
port: 443,
|
|
437
|
+
path: `${DevicePath}/${this.device.deviceId}/status`,
|
|
438
|
+
method: 'GET',
|
|
439
|
+
headers: {
|
|
440
|
+
Authorization: this.platform.config.credentials?.token,
|
|
441
|
+
sign: sign,
|
|
442
|
+
nonce: nonce,
|
|
443
|
+
t: t,
|
|
444
|
+
'Content-Type': 'application/json',
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
const req = https.request(options, (res) => {
|
|
448
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Refresh statusCode: ${res.statusCode}`);
|
|
449
|
+
let rawData = '';
|
|
450
|
+
res.on('data', (d) => {
|
|
451
|
+
rawData += d;
|
|
452
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
453
|
+
});
|
|
454
|
+
res.on('end', () => {
|
|
455
|
+
try {
|
|
456
|
+
this.deviceStatus = JSON.parse(rawData);
|
|
457
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
458
|
+
this.power = this.deviceStatus.body.power;
|
|
459
|
+
this.color = this.deviceStatus.body.color;
|
|
460
|
+
this.brightness = this.deviceStatus.body.brightness;
|
|
461
|
+
this.colorTemperature = this.deviceStatus.body.colorTemperature;
|
|
462
|
+
this.parseStatus();
|
|
463
|
+
this.updateHomeKitCharacteristics();
|
|
464
|
+
} catch (e: any) {
|
|
465
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
447
468
|
});
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
451
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
452
|
-
this.power = this.deviceStatus.body.power;
|
|
453
|
-
this.color = this.deviceStatus.body.color;
|
|
454
|
-
this.brightness = this.deviceStatus.body.brightness;
|
|
455
|
-
this.colorTemperature = this.deviceStatus.body.colorTemperature;
|
|
456
|
-
this.parseStatus();
|
|
457
|
-
this.updateHomeKitCharacteristics();
|
|
458
|
-
} catch (e: any) {
|
|
459
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
|
|
460
|
-
}
|
|
469
|
+
req.on('error', (e: any) => {
|
|
470
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
461
471
|
});
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
this.errorLog(
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
);
|
|
472
|
+
req.end();
|
|
473
|
+
} catch (e: any) {
|
|
474
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
475
|
+
if (this.deviceLogging.includes('debug')) {
|
|
476
|
+
this.errorLog(
|
|
477
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
478
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
this.apiError(e);
|
|
473
482
|
}
|
|
474
|
-
|
|
483
|
+
} else {
|
|
484
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
475
485
|
}
|
|
476
486
|
}
|
|
477
487
|
|
|
@@ -487,91 +497,96 @@ export class ColorBulb {
|
|
|
487
497
|
*
|
|
488
498
|
*/
|
|
489
499
|
async pushChanges(): Promise<void> {
|
|
490
|
-
|
|
491
|
-
|
|
500
|
+
if (this.OpenAPI) {
|
|
501
|
+
try {
|
|
502
|
+
if (this.On !== this.accessory.context.On) {
|
|
492
503
|
// Make Push On request to the API
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
504
|
+
const t = Date.now();
|
|
505
|
+
const nonce = 'requestID';
|
|
506
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
507
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
508
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
509
|
+
.digest();
|
|
510
|
+
const sign = signTerm.toString('base64');
|
|
511
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
512
|
+
|
|
513
|
+
let command = '';
|
|
514
|
+
if (this.On) {
|
|
515
|
+
command = 'turnOn';
|
|
516
|
+
} else {
|
|
517
|
+
command = 'turnOff';
|
|
518
|
+
}
|
|
519
|
+
const body = superStringify({
|
|
520
|
+
'command': `${command}`,
|
|
521
|
+
'parameter': 'default',
|
|
522
|
+
'commandType': 'command',
|
|
523
|
+
});
|
|
524
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
525
|
+
const options = {
|
|
526
|
+
hostname: HostDomain,
|
|
527
|
+
port: 443,
|
|
528
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
529
|
+
method: 'POST',
|
|
530
|
+
headers: {
|
|
531
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
532
|
+
'sign': sign,
|
|
533
|
+
'nonce': nonce,
|
|
534
|
+
't': t,
|
|
535
|
+
'Content-Type': 'application/json',
|
|
536
|
+
'Content-Length': body.length,
|
|
537
|
+
},
|
|
538
|
+
};
|
|
539
|
+
const req = https.request(options, res => {
|
|
540
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
541
|
+
this.statusCode({ res });
|
|
542
|
+
res.on('data', d => {
|
|
543
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
req.on('error', (e: any) => {
|
|
547
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
548
|
+
});
|
|
549
|
+
req.write(body);
|
|
550
|
+
req.end();
|
|
551
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${superStringify(req)}`);
|
|
552
|
+
}
|
|
553
|
+
// Push Brightness Update
|
|
503
554
|
if (this.On) {
|
|
504
|
-
|
|
505
|
-
} else {
|
|
506
|
-
command = 'turnOff';
|
|
555
|
+
await this.pushBrightnessChanges();
|
|
507
556
|
}
|
|
508
|
-
const body = superStringify({
|
|
509
|
-
'command': `${command}`,
|
|
510
|
-
'parameter': 'default',
|
|
511
|
-
'commandType': 'command',
|
|
512
|
-
});
|
|
513
|
-
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
514
|
-
const options = {
|
|
515
|
-
hostname: HostDomain,
|
|
516
|
-
port: 443,
|
|
517
|
-
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
518
|
-
method: 'POST',
|
|
519
|
-
headers: {
|
|
520
|
-
'Authorization': this.platform.config.credentials?.token,
|
|
521
|
-
'sign': sign,
|
|
522
|
-
'nonce': nonce,
|
|
523
|
-
't': t,
|
|
524
|
-
'Content-Type': 'application/json',
|
|
525
|
-
'Content-Length': body.length,
|
|
526
|
-
},
|
|
527
|
-
};
|
|
528
|
-
const req = https.request(options, res => {
|
|
529
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
530
|
-
this.statusCode({ res });
|
|
531
|
-
res.on('data', d => {
|
|
532
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} d: ${d}`);
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
req.on('error', (e: any) => {
|
|
536
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} error message: ${e.message}`);
|
|
537
|
-
});
|
|
538
|
-
req.write(body);
|
|
539
|
-
req.end();
|
|
540
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${superStringify(req)}`);
|
|
541
|
-
}
|
|
542
|
-
// Push Brightness Update
|
|
543
|
-
if (this.On) {
|
|
544
|
-
await this.pushBrightnessChanges();
|
|
545
|
-
}
|
|
546
557
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
558
|
+
// Push ColorTemperature Update
|
|
559
|
+
if (this.On) {
|
|
560
|
+
await this.pushColorTemperatureChanges();
|
|
561
|
+
}
|
|
551
562
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
563
|
+
// Push Hue & Saturation Update
|
|
564
|
+
if (this.On) {
|
|
565
|
+
await this.pushHueSaturationChanges();
|
|
566
|
+
}
|
|
567
|
+
} catch (e: any) {
|
|
568
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
569
|
+
if (this.deviceLogging.includes('debug')) {
|
|
570
|
+
this.errorLog(
|
|
571
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
572
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
this.apiError(e);
|
|
562
576
|
}
|
|
563
|
-
|
|
577
|
+
} else {
|
|
578
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
564
579
|
}
|
|
565
580
|
}
|
|
566
581
|
|
|
567
582
|
async pushHueSaturationChanges(): Promise<void> {
|
|
568
583
|
try {
|
|
569
584
|
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
570
|
-
this.debugLog(
|
|
571
|
-
this.debugLog(
|
|
585
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${superStringify(this.Hue)}`);
|
|
586
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${superStringify(this.Saturation)}`);
|
|
572
587
|
|
|
573
588
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
574
|
-
this.debugLog(
|
|
589
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${superStringify([red, green, blue])}`);
|
|
575
590
|
|
|
576
591
|
// Make Push Hue/Saturation request to the API
|
|
577
592
|
const t = Date.now();
|
|
@@ -581,13 +596,13 @@ export class ColorBulb {
|
|
|
581
596
|
.update(Buffer.from(data, 'utf-8'))
|
|
582
597
|
.digest();
|
|
583
598
|
const sign = signTerm.toString('base64');
|
|
584
|
-
this.debugLog(
|
|
599
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
585
600
|
const body = superStringify({
|
|
586
601
|
'command': 'setColor',
|
|
587
602
|
'parameter': `${red}:${green}:${blue}`,
|
|
588
603
|
'commandType': 'command',
|
|
589
604
|
});
|
|
590
|
-
this.infoLog(
|
|
605
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
591
606
|
const options = {
|
|
592
607
|
hostname: HostDomain,
|
|
593
608
|
port: 443,
|
|
@@ -603,29 +618,30 @@ export class ColorBulb {
|
|
|
603
618
|
},
|
|
604
619
|
};
|
|
605
620
|
const req = https.request(options, res => {
|
|
606
|
-
this.debugLog(
|
|
621
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
607
622
|
res.on('data', d => {
|
|
608
|
-
this.debugLog(
|
|
623
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
609
624
|
});
|
|
610
625
|
});
|
|
611
626
|
req.on('error', (e: any) => {
|
|
612
|
-
this.errorLog(
|
|
627
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
613
628
|
});
|
|
614
629
|
req.write(body);
|
|
615
630
|
req.end();
|
|
616
|
-
this.debugLog(
|
|
631
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges: ${superStringify(req)}`);
|
|
617
632
|
} else {
|
|
618
633
|
this.debugLog(
|
|
619
|
-
|
|
634
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
620
635
|
`Hue: ${this.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation},`
|
|
621
636
|
+` SaturationCached: ${this.accessory.context.Saturation}`,
|
|
622
637
|
);
|
|
623
638
|
}
|
|
624
639
|
} catch (e: any) {
|
|
625
|
-
this.errorLog(
|
|
640
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
626
641
|
if (this.deviceLogging.includes('debug')) {
|
|
627
642
|
this.errorLog(
|
|
628
|
-
|
|
643
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
644
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
629
645
|
);
|
|
630
646
|
}
|
|
631
647
|
this.apiError(e);
|
|
@@ -646,13 +662,13 @@ export class ColorBulb {
|
|
|
646
662
|
.update(Buffer.from(data, 'utf-8'))
|
|
647
663
|
.digest();
|
|
648
664
|
const sign = signTerm.toString('base64');
|
|
649
|
-
this.debugLog(
|
|
665
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
650
666
|
const body = superStringify({
|
|
651
667
|
'command': 'setColorTemperature',
|
|
652
668
|
'parameter': `${kelvin}`,
|
|
653
669
|
'commandType': 'command',
|
|
654
670
|
});
|
|
655
|
-
this.infoLog(
|
|
671
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
656
672
|
const options = {
|
|
657
673
|
hostname: HostDomain,
|
|
658
674
|
port: 443,
|
|
@@ -668,30 +684,31 @@ export class ColorBulb {
|
|
|
668
684
|
},
|
|
669
685
|
};
|
|
670
686
|
const req = https.request(options, res => {
|
|
671
|
-
this.debugLog(
|
|
687
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
672
688
|
res.on('data', d => {
|
|
673
|
-
this.debugLog(
|
|
689
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
674
690
|
});
|
|
675
691
|
});
|
|
676
692
|
req.on('error', (e: any) => {
|
|
677
|
-
this.errorLog(
|
|
693
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
678
694
|
});
|
|
679
695
|
req.write(body);
|
|
680
696
|
req.end();
|
|
681
697
|
|
|
682
|
-
this.debugLog(
|
|
698
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges: ${superStringify(req)}`);
|
|
683
699
|
this.accessory.context.ColorTemperature = this.ColorTemperature;
|
|
684
700
|
} else {
|
|
685
701
|
this.debugLog(
|
|
686
|
-
|
|
702
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
687
703
|
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`,
|
|
688
704
|
);
|
|
689
705
|
}
|
|
690
706
|
} catch (e: any) {
|
|
691
|
-
this.errorLog(
|
|
707
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
692
708
|
if (this.deviceLogging.includes('debug')) {
|
|
693
709
|
this.errorLog(
|
|
694
|
-
|
|
710
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
711
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
695
712
|
);
|
|
696
713
|
}
|
|
697
714
|
this.apiError(e);
|
|
@@ -709,13 +726,13 @@ export class ColorBulb {
|
|
|
709
726
|
.update(Buffer.from(data, 'utf-8'))
|
|
710
727
|
.digest();
|
|
711
728
|
const sign = signTerm.toString('base64');
|
|
712
|
-
this.debugLog(
|
|
729
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
713
730
|
const body = superStringify({
|
|
714
731
|
'command': 'setBrightness',
|
|
715
732
|
'parameter': `${this.Brightness}`,
|
|
716
733
|
'commandType': 'command',
|
|
717
734
|
});
|
|
718
|
-
this.infoLog(
|
|
735
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
719
736
|
const options = {
|
|
720
737
|
hostname: HostDomain,
|
|
721
738
|
port: 443,
|
|
@@ -731,28 +748,29 @@ export class ColorBulb {
|
|
|
731
748
|
},
|
|
732
749
|
};
|
|
733
750
|
const req = https.request(options, res => {
|
|
734
|
-
this.debugLog(
|
|
751
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
735
752
|
res.on('data', d => {
|
|
736
|
-
this.debugLog(
|
|
753
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
737
754
|
});
|
|
738
755
|
});
|
|
739
756
|
req.on('error', (e: any) => {
|
|
740
|
-
this.errorLog(
|
|
757
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
741
758
|
});
|
|
742
759
|
req.write(body);
|
|
743
760
|
req.end();
|
|
744
|
-
this.debugLog(
|
|
761
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges: ${superStringify(req)}`);
|
|
745
762
|
} else {
|
|
746
763
|
this.debugLog(
|
|
747
|
-
|
|
764
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, `
|
|
748
765
|
+`BrightnessCached: ${this.accessory.context.Brightness}`,
|
|
749
766
|
);
|
|
750
767
|
}
|
|
751
768
|
} catch (e: any) {
|
|
752
|
-
this.errorLog(
|
|
769
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
753
770
|
if (this.deviceLogging.includes('debug')) {
|
|
754
771
|
this.errorLog(
|
|
755
|
-
|
|
772
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
773
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
756
774
|
);
|
|
757
775
|
}
|
|
758
776
|
this.apiError(e);
|
|
@@ -761,40 +779,40 @@ export class ColorBulb {
|
|
|
761
779
|
|
|
762
780
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
763
781
|
if (this.On === undefined) {
|
|
764
|
-
this.debugLog(
|
|
782
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
765
783
|
} else {
|
|
766
784
|
this.accessory.context.On = this.On;
|
|
767
785
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
768
|
-
this.debugLog(
|
|
786
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
769
787
|
}
|
|
770
788
|
if (this.Brightness === undefined) {
|
|
771
|
-
this.debugLog(
|
|
789
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
772
790
|
} else {
|
|
773
791
|
this.accessory.context.Brightness = this.Brightness;
|
|
774
792
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
775
|
-
this.debugLog(
|
|
793
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
776
794
|
}
|
|
777
795
|
if (this.ColorTemperature === undefined) {
|
|
778
|
-
this.debugLog(
|
|
796
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
779
797
|
} else {
|
|
780
798
|
|
|
781
799
|
this.accessory.context.ColorTemperature = this.ColorTemperature;
|
|
782
800
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
783
|
-
this.debugLog(
|
|
801
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
784
802
|
}
|
|
785
803
|
if (this.Hue === undefined) {
|
|
786
|
-
this.debugLog(
|
|
804
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
787
805
|
} else {
|
|
788
806
|
this.accessory.context.Hue = this.Hue;
|
|
789
807
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
790
|
-
this.debugLog(
|
|
808
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
791
809
|
}
|
|
792
810
|
if (this.Saturation === undefined) {
|
|
793
|
-
this.debugLog(
|
|
811
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
794
812
|
} else {
|
|
795
813
|
this.accessory.context.Saturation = this.Saturation;
|
|
796
814
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
797
|
-
this.debugLog(
|
|
815
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
798
816
|
}
|
|
799
817
|
}
|
|
800
818
|
|
|
@@ -810,36 +828,36 @@ export class ColorBulb {
|
|
|
810
828
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
811
829
|
switch (res.statusCode) {
|
|
812
830
|
case 151:
|
|
813
|
-
this.errorLog(
|
|
831
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
814
832
|
break;
|
|
815
833
|
case 152:
|
|
816
|
-
this.errorLog(
|
|
834
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
817
835
|
break;
|
|
818
836
|
case 160:
|
|
819
|
-
this.errorLog(
|
|
837
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
820
838
|
break;
|
|
821
839
|
case 161:
|
|
822
|
-
this.errorLog(
|
|
840
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
823
841
|
this.offlineOff();
|
|
824
842
|
break;
|
|
825
843
|
case 171:
|
|
826
|
-
this.errorLog(
|
|
844
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
827
845
|
this.offlineOff();
|
|
828
846
|
break;
|
|
829
847
|
case 190:
|
|
830
848
|
this.errorLog(
|
|
831
|
-
|
|
849
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
832
850
|
` Or command: ${superStringify(res)} format is invalid`,
|
|
833
851
|
);
|
|
834
852
|
break;
|
|
835
853
|
case 100:
|
|
836
854
|
if (this.platform.debugMode) {
|
|
837
|
-
this.debugLog(
|
|
855
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
838
856
|
}
|
|
839
857
|
break;
|
|
840
858
|
default:
|
|
841
859
|
if (this.platform.debugMode) {
|
|
842
|
-
this.debugLog(
|
|
860
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
843
861
|
}
|
|
844
862
|
}
|
|
845
863
|
}
|
|
@@ -855,7 +873,7 @@ export class ColorBulb {
|
|
|
855
873
|
* Handle requests to set the value of the "On" characteristic
|
|
856
874
|
*/
|
|
857
875
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
858
|
-
this.debugLog(
|
|
876
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${value}`);
|
|
859
877
|
|
|
860
878
|
this.On = value;
|
|
861
879
|
this.doColorBulbUpdate.next();
|
|
@@ -865,7 +883,7 @@ export class ColorBulb {
|
|
|
865
883
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
866
884
|
*/
|
|
867
885
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
868
|
-
this.debugLog(
|
|
886
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${value}`);
|
|
869
887
|
|
|
870
888
|
this.Brightness = value;
|
|
871
889
|
this.doColorBulbUpdate.next();
|
|
@@ -875,7 +893,7 @@ export class ColorBulb {
|
|
|
875
893
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
876
894
|
*/
|
|
877
895
|
async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
878
|
-
this.debugLog(
|
|
896
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${value}`);
|
|
879
897
|
|
|
880
898
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
881
899
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
@@ -900,7 +918,7 @@ export class ColorBulb {
|
|
|
900
918
|
* Handle requests to set the value of the "Hue" characteristic
|
|
901
919
|
*/
|
|
902
920
|
async HueSet(value: CharacteristicValue): Promise<void> {
|
|
903
|
-
this.debugLog(
|
|
921
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${value}`);
|
|
904
922
|
|
|
905
923
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
906
924
|
|
|
@@ -912,7 +930,7 @@ export class ColorBulb {
|
|
|
912
930
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
913
931
|
*/
|
|
914
932
|
async SaturationSet(value: CharacteristicValue): Promise<void> {
|
|
915
|
-
this.debugLog(
|
|
933
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${value}`);
|
|
916
934
|
|
|
917
935
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
918
936
|
|
|
@@ -928,6 +946,9 @@ export class ColorBulb {
|
|
|
928
946
|
if (device.ble) {
|
|
929
947
|
config['ble'] = device.ble;
|
|
930
948
|
}
|
|
949
|
+
if (device.openAPI !== undefined) {
|
|
950
|
+
config['openAPI'] = device.openAPI;
|
|
951
|
+
}
|
|
931
952
|
if (device.logging !== undefined) {
|
|
932
953
|
config['logging'] = device.logging;
|
|
933
954
|
}
|
|
@@ -941,18 +962,27 @@ export class ColorBulb {
|
|
|
941
962
|
config['offline'] = device.offline;
|
|
942
963
|
}
|
|
943
964
|
if (Object.entries(config).length !== 0) {
|
|
944
|
-
this.infoLog(
|
|
965
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
945
966
|
}
|
|
946
967
|
}
|
|
947
968
|
|
|
948
969
|
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
949
970
|
if (device.refreshRate) {
|
|
950
971
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
951
|
-
this.debugLog(
|
|
972
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
952
973
|
} else if (this.platform.config.options!.refreshRate) {
|
|
953
974
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
954
|
-
this.debugLog(
|
|
975
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
async openAPI() {
|
|
980
|
+
if (!this.device.openAPI) {
|
|
981
|
+
this.OpenAPI = true;
|
|
982
|
+
} else {
|
|
983
|
+
this.OpenAPI = this.device.openAPI;
|
|
955
984
|
}
|
|
985
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
956
986
|
}
|
|
957
987
|
|
|
958
988
|
async scan(device: device & devicesConfig): Promise<void> {
|
|
@@ -972,24 +1002,25 @@ export class ColorBulb {
|
|
|
972
1002
|
async logs(device: device & devicesConfig): Promise<void> {
|
|
973
1003
|
if (this.platform.debugMode) {
|
|
974
1004
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
975
|
-
this.debugLog(
|
|
1005
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
976
1006
|
} else if (device.logging) {
|
|
977
1007
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
978
|
-
this.debugLog(
|
|
1008
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
979
1009
|
} else if (this.platform.config.options?.logging) {
|
|
980
1010
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
981
|
-
this.debugLog(
|
|
1011
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
982
1012
|
} else {
|
|
983
1013
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
984
|
-
this.debugLog(
|
|
1014
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
985
1015
|
}
|
|
986
1016
|
}
|
|
987
1017
|
|
|
988
1018
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
989
1019
|
let FirmwareRevision: string;
|
|
990
|
-
this.debugLog(
|
|
991
|
-
|
|
992
|
-
this.debugLog(
|
|
1020
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
1021
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
1022
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
1023
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
993
1024
|
if (accessory.context.FirmwareRevision) {
|
|
994
1025
|
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
995
1026
|
} else if (device.firmware) {
|
|
@@ -1003,10 +1034,10 @@ export class ColorBulb {
|
|
|
1003
1034
|
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
1004
1035
|
if (device.colorbulb?.adaptiveLightingShift) {
|
|
1005
1036
|
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
1006
|
-
this.debugLog(
|
|
1037
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
1007
1038
|
} else {
|
|
1008
1039
|
this.adaptiveLightingShift = 0;
|
|
1009
|
-
this.debugLog(
|
|
1040
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
1010
1041
|
}
|
|
1011
1042
|
}
|
|
1012
1043
|
|