@switchbot/homebridge-switchbot 1.4.1-beta.1 → 1.4.1-beta.2
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 +14 -0
- package/config.schema.json +82 -10
- package/dist/devices/bots.d.ts +12 -2
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +140 -89
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +12 -2
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +138 -84
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +12 -2
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +101 -52
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +13 -4
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +173 -124
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +12 -2
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +156 -108
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +12 -2
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +98 -49
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +12 -2
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +86 -37
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +12 -2
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +80 -31
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +10 -2
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +77 -37
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +10 -2
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +65 -25
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +10 -2
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +61 -21
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +10 -2
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +71 -30
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +10 -2
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +62 -22
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +10 -2
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +68 -28
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +10 -2
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +78 -38
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +10 -2
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +61 -21
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +10 -2
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +61 -21
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +9 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +264 -285
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +1 -1
- package/src/devices/bots.ts +146 -89
- package/src/devices/colorbulb.ts +146 -86
- package/src/devices/contact.ts +107 -52
- package/src/devices/curtains.ts +182 -129
- package/src/devices/humidifiers.ts +162 -109
- package/src/devices/meters.ts +104 -49
- package/src/devices/motion.ts +91 -36
- package/src/devices/plugs.ts +84 -31
- package/src/irdevices/airconditioners.ts +81 -36
- package/src/irdevices/airpurifiers.ts +69 -24
- package/src/irdevices/cameras.ts +65 -20
- package/src/irdevices/fans.ts +75 -30
- package/src/irdevices/lights.ts +66 -21
- package/src/irdevices/others.ts +72 -27
- package/src/irdevices/tvs.ts +82 -37
- package/src/irdevices/vacuumcleaners.ts +65 -20
- package/src/irdevices/waterheaters.ts +65 -20
- package/src/platform.ts +267 -290
- package/src/settings.ts +4 -1
- package/dist/devices/indoorcam.d.ts +0 -64
- package/dist/devices/indoorcam.d.ts.map +0 -1
- package/dist/devices/indoorcam.js +0 -249
- package/dist/devices/indoorcam.js.map +0 -1
- package/src/devices/indoorcam.ts +0 -309
package/src/devices/colorbulb.ts
CHANGED
|
@@ -34,8 +34,8 @@ export class ColorBulb {
|
|
|
34
34
|
|
|
35
35
|
// Config
|
|
36
36
|
set_minStep?: number;
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
deviceLogging!: string;
|
|
38
|
+
deviceRefreshRate!: number;
|
|
39
39
|
|
|
40
40
|
// Adaptive Lighting
|
|
41
41
|
AdaptiveLightingController: ControllerConstructor | Controller<ControllerServiceMap>;
|
|
@@ -52,10 +52,9 @@ export class ColorBulb {
|
|
|
52
52
|
private accessory: PlatformAccessory,
|
|
53
53
|
public device: device & devicesConfig,
|
|
54
54
|
) {
|
|
55
|
-
// ColorBulb Config
|
|
56
|
-
this.platform.device(`Color Bulb: ${this.accessory.displayName} Config: (ble: ${device.ble}, set_minStep: ${device.colorbulb?.set_minStep}`);
|
|
57
|
-
|
|
58
55
|
// default placeholders
|
|
56
|
+
this.refreshRate();
|
|
57
|
+
this.logs();
|
|
59
58
|
if (this.On === undefined) {
|
|
60
59
|
this.On = false;
|
|
61
60
|
} else {
|
|
@@ -68,6 +67,9 @@ export class ColorBulb {
|
|
|
68
67
|
this.minKelvin = 2000;
|
|
69
68
|
this.maxKelvin = 9000;
|
|
70
69
|
|
|
70
|
+
// ColorBulb Config
|
|
71
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Config: (ble: ${device.ble}, set_minStep: ${device.colorbulb?.set_minStep}`);
|
|
72
|
+
|
|
71
73
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
72
74
|
this.doColorBulbUpdate = new Subject();
|
|
73
75
|
this.colorBulbUpdateInProgress = false;
|
|
@@ -161,7 +163,7 @@ export class ColorBulb {
|
|
|
161
163
|
this.updateHomeKitCharacteristics();
|
|
162
164
|
|
|
163
165
|
// Start an update interval
|
|
164
|
-
interval(this.
|
|
166
|
+
interval(this.deviceRefreshRate * 1000)
|
|
165
167
|
.pipe(skipWhile(() => this.colorBulbUpdateInProgress))
|
|
166
168
|
.subscribe(() => {
|
|
167
169
|
this.refreshStatus();
|
|
@@ -180,13 +182,13 @@ export class ColorBulb {
|
|
|
180
182
|
try {
|
|
181
183
|
await this.pushChanges();
|
|
182
184
|
} catch (e: any) {
|
|
183
|
-
this.
|
|
184
|
-
if (this.
|
|
185
|
-
this.
|
|
185
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges`);
|
|
186
|
+
if (this.deviceLogging === 'debug') {
|
|
187
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,`
|
|
186
188
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
187
189
|
}
|
|
188
|
-
if (this.
|
|
189
|
-
this.
|
|
190
|
+
if (this.platform.debugMode) {
|
|
191
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,`
|
|
190
192
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
191
193
|
}
|
|
192
194
|
this.apiError();
|
|
@@ -195,7 +197,25 @@ export class ColorBulb {
|
|
|
195
197
|
});
|
|
196
198
|
}
|
|
197
199
|
|
|
198
|
-
|
|
200
|
+
refreshRate() {
|
|
201
|
+
if (this.device.refreshRate) {
|
|
202
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
203
|
+
} else if (this.platform.config.options!.refreshRate) {
|
|
204
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
logs() {
|
|
209
|
+
if (this.device.logging) {
|
|
210
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
211
|
+
} else if (this.platform.config.options?.logging) {
|
|
212
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
213
|
+
} else {
|
|
214
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private minStep(): number {
|
|
199
219
|
if (this.device.colorbulb?.set_minStep) {
|
|
200
220
|
this.set_minStep = this.device.colorbulb?.set_minStep;
|
|
201
221
|
} else {
|
|
@@ -212,58 +232,58 @@ export class ColorBulb {
|
|
|
212
232
|
default:
|
|
213
233
|
this.On = false;
|
|
214
234
|
}
|
|
215
|
-
this.
|
|
235
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
|
|
216
236
|
|
|
217
237
|
// Brightness
|
|
218
238
|
this.Brightness = Number(this.deviceStatus.body.brightness);
|
|
219
|
-
this.
|
|
239
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
220
240
|
|
|
221
241
|
// Color, Hue & Brightness
|
|
222
242
|
if (this.deviceStatus.body.color) {
|
|
223
|
-
this.
|
|
243
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.deviceStatus.body.color)}`);
|
|
224
244
|
const [red, green, blue] = this.deviceStatus.body.color!.split(':');
|
|
225
|
-
this.
|
|
226
|
-
this.
|
|
227
|
-
this.
|
|
245
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
246
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
247
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
228
248
|
|
|
229
249
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
230
|
-
this.
|
|
250
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
231
251
|
|
|
232
252
|
// Hue
|
|
233
253
|
this.Hue = hue;
|
|
234
|
-
this.
|
|
254
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
235
255
|
|
|
236
256
|
// Saturation
|
|
237
257
|
this.Saturation = saturation;
|
|
238
|
-
this.
|
|
258
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
239
259
|
}
|
|
240
260
|
|
|
241
261
|
// ColorTemperature
|
|
242
262
|
if (!Number.isNaN(this.deviceStatus.body.colorTemperature)) {
|
|
243
|
-
this.
|
|
263
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.deviceStatus.body.colorTemperature}`);
|
|
244
264
|
const mired = Math.round(1000000 / this.deviceStatus.body.colorTemperature!);
|
|
245
265
|
|
|
246
266
|
this.ColorTemperature = Number(mired);
|
|
247
267
|
|
|
248
268
|
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
249
|
-
this.
|
|
269
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
250
270
|
}
|
|
251
271
|
}
|
|
252
272
|
|
|
253
273
|
async refreshStatus() {
|
|
254
274
|
try {
|
|
255
275
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
256
|
-
this.
|
|
276
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
257
277
|
this.parseStatus();
|
|
258
278
|
this.updateHomeKitCharacteristics();
|
|
259
279
|
} catch (e: any) {
|
|
260
|
-
this.
|
|
261
|
-
if (this.
|
|
262
|
-
this.
|
|
280
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
281
|
+
if (this.deviceLogging === 'debug') {
|
|
282
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
263
283
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
264
284
|
}
|
|
265
|
-
if (this.
|
|
266
|
-
this.
|
|
285
|
+
if (this.platform.debugMode) {
|
|
286
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
267
287
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
268
288
|
}
|
|
269
289
|
this.apiError();
|
|
@@ -295,12 +315,12 @@ export class ColorBulb {
|
|
|
295
315
|
payload.command = 'turnOff';
|
|
296
316
|
}
|
|
297
317
|
|
|
298
|
-
this.
|
|
318
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
299
319
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
300
320
|
|
|
301
321
|
// Make the API request
|
|
302
322
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
303
|
-
this.
|
|
323
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
304
324
|
this.statusCode(push);
|
|
305
325
|
this.OnCached = this.On;
|
|
306
326
|
this.accessory.context.On = this.OnCached;
|
|
@@ -321,13 +341,13 @@ export class ColorBulb {
|
|
|
321
341
|
}
|
|
322
342
|
|
|
323
343
|
} catch (e: any) {
|
|
324
|
-
this.
|
|
325
|
-
if (this.
|
|
326
|
-
this.
|
|
344
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
345
|
+
if (this.deviceLogging === 'debug') {
|
|
346
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
327
347
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
328
348
|
}
|
|
329
|
-
if (this.
|
|
330
|
-
this.
|
|
349
|
+
if (this.platform.debugMode) {
|
|
350
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
331
351
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
332
352
|
}
|
|
333
353
|
this.apiError();
|
|
@@ -337,11 +357,11 @@ export class ColorBulb {
|
|
|
337
357
|
private async pushHueSaturationChanges() {
|
|
338
358
|
try {
|
|
339
359
|
if ((this.Hue !== this.HueCached) || (this.Saturation !== this.SaturationCached)) {
|
|
340
|
-
this.
|
|
341
|
-
this.
|
|
360
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
361
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
342
362
|
|
|
343
363
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
344
|
-
this.
|
|
364
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
345
365
|
|
|
346
366
|
const payload = {
|
|
347
367
|
commandType: 'command',
|
|
@@ -349,27 +369,27 @@ export class ColorBulb {
|
|
|
349
369
|
parameter: `${red}:${green}:${blue}`,
|
|
350
370
|
} as payload;
|
|
351
371
|
|
|
352
|
-
this.
|
|
372
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
353
373
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
354
374
|
|
|
355
375
|
// Make the API request
|
|
356
376
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
357
|
-
this.
|
|
377
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
358
378
|
this.statusCode(push);
|
|
359
379
|
this.HueCached = this.Hue;
|
|
360
380
|
this.SaturationCached = this.Saturation;
|
|
361
381
|
} else {
|
|
362
|
-
this.
|
|
382
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
363
383
|
+ `Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`);
|
|
364
384
|
}
|
|
365
385
|
} catch (e: any) {
|
|
366
|
-
this.
|
|
367
|
-
if (this.
|
|
368
|
-
this.
|
|
386
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
387
|
+
if (this.deviceLogging === 'debug') {
|
|
388
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
369
389
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
370
390
|
}
|
|
371
|
-
if (this.
|
|
372
|
-
this.
|
|
391
|
+
if (this.platform.debugMode) {
|
|
392
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
373
393
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
374
394
|
}
|
|
375
395
|
this.apiError();
|
|
@@ -388,26 +408,26 @@ export class ColorBulb {
|
|
|
388
408
|
parameter: `${kelvin}`,
|
|
389
409
|
} as payload;
|
|
390
410
|
|
|
391
|
-
this.
|
|
411
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
392
412
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
393
413
|
|
|
394
414
|
// Make the API request
|
|
395
415
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
396
|
-
this.
|
|
416
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
397
417
|
this.statusCode(push);
|
|
398
418
|
this.ColorTemperatureCached = this.ColorTemperature;
|
|
399
419
|
} else {
|
|
400
|
-
this.
|
|
420
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
401
421
|
+ `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`);
|
|
402
422
|
}
|
|
403
423
|
} catch (e: any) {
|
|
404
|
-
this.
|
|
405
|
-
if (this.
|
|
406
|
-
this.
|
|
424
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
425
|
+
if (this.deviceLogging === 'debug') {
|
|
426
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
407
427
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
408
428
|
}
|
|
409
|
-
if (this.
|
|
410
|
-
this.
|
|
429
|
+
if (this.platform.debugMode) {
|
|
430
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
411
431
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
412
432
|
}
|
|
413
433
|
this.apiError();
|
|
@@ -423,26 +443,26 @@ export class ColorBulb {
|
|
|
423
443
|
parameter: `${this.Brightness}`,
|
|
424
444
|
} as payload;
|
|
425
445
|
|
|
426
|
-
this.
|
|
446
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
427
447
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
428
448
|
|
|
429
449
|
// Make the API request
|
|
430
450
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
431
|
-
this.
|
|
451
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
432
452
|
this.statusCode(push);
|
|
433
453
|
this.BrightnessCached = this.Brightness;
|
|
434
454
|
} else {
|
|
435
|
-
this.
|
|
455
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
436
456
|
+ `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`);
|
|
437
457
|
}
|
|
438
458
|
} catch (e: any) {
|
|
439
|
-
this.
|
|
440
|
-
if (this.
|
|
441
|
-
this.
|
|
459
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
460
|
+
if (this.deviceLogging === 'debug') {
|
|
461
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
442
462
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
443
463
|
}
|
|
444
|
-
if (this.
|
|
445
|
-
this.
|
|
464
|
+
if (this.platform.debugMode) {
|
|
465
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
446
466
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
447
467
|
}
|
|
448
468
|
this.apiError();
|
|
@@ -451,34 +471,34 @@ export class ColorBulb {
|
|
|
451
471
|
|
|
452
472
|
updateHomeKitCharacteristics() {
|
|
453
473
|
if (this.On === undefined) {
|
|
454
|
-
this.
|
|
474
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
|
|
455
475
|
} else {
|
|
456
476
|
this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
457
|
-
this.
|
|
477
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
458
478
|
}
|
|
459
479
|
if (this.Brightness === undefined) {
|
|
460
|
-
this.
|
|
480
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
461
481
|
} else {
|
|
462
482
|
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
463
|
-
this.
|
|
483
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
464
484
|
}
|
|
465
485
|
if (this.ColorTemperature === undefined) {
|
|
466
|
-
this.
|
|
486
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
467
487
|
} else {
|
|
468
488
|
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
469
|
-
this.
|
|
489
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
470
490
|
}
|
|
471
491
|
if (this.Hue === undefined) {
|
|
472
|
-
this.
|
|
492
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
473
493
|
} else {
|
|
474
494
|
this.service.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
475
|
-
this.
|
|
495
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
476
496
|
}
|
|
477
497
|
if (this.Saturation === undefined) {
|
|
478
|
-
this.
|
|
498
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
479
499
|
} else {
|
|
480
500
|
this.service.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
481
|
-
this.
|
|
501
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
482
502
|
}
|
|
483
503
|
}
|
|
484
504
|
|
|
@@ -489,31 +509,35 @@ export class ColorBulb {
|
|
|
489
509
|
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
490
510
|
switch (push.data.statusCode) {
|
|
491
511
|
case 151:
|
|
492
|
-
this.
|
|
512
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
493
513
|
break;
|
|
494
514
|
case 152:
|
|
495
|
-
this.
|
|
515
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device not found.`);
|
|
496
516
|
break;
|
|
497
517
|
case 160:
|
|
498
|
-
this.
|
|
518
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Command is not supported.`);
|
|
499
519
|
break;
|
|
500
520
|
case 161:
|
|
501
|
-
this.
|
|
521
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device is offline.`);
|
|
502
522
|
this.offlineOff();
|
|
503
523
|
break;
|
|
504
524
|
case 171:
|
|
505
|
-
this.
|
|
525
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
506
526
|
this.offlineOff();
|
|
507
527
|
break;
|
|
508
528
|
case 190:
|
|
509
|
-
this.
|
|
529
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
510
530
|
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
511
531
|
break;
|
|
512
532
|
case 100:
|
|
513
|
-
this.platform.
|
|
533
|
+
if (this.platform.debugMode) {
|
|
534
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Command successfully sent.`);
|
|
535
|
+
}
|
|
514
536
|
break;
|
|
515
537
|
default:
|
|
516
|
-
this.platform.
|
|
538
|
+
if (this.platform.debugMode) {
|
|
539
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Unknown statusCode.`);
|
|
540
|
+
}
|
|
517
541
|
}
|
|
518
542
|
}
|
|
519
543
|
|
|
@@ -528,7 +552,7 @@ export class ColorBulb {
|
|
|
528
552
|
* Handle requests to set the value of the "On" characteristic
|
|
529
553
|
*/
|
|
530
554
|
OnSet(value: CharacteristicValue) {
|
|
531
|
-
this.
|
|
555
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${value}`);
|
|
532
556
|
|
|
533
557
|
this.On = value;
|
|
534
558
|
this.doColorBulbUpdate.next();
|
|
@@ -538,7 +562,7 @@ export class ColorBulb {
|
|
|
538
562
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
539
563
|
*/
|
|
540
564
|
BrightnessSet(value: CharacteristicValue) {
|
|
541
|
-
this.
|
|
565
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${value}`);
|
|
542
566
|
|
|
543
567
|
this.Brightness = value;
|
|
544
568
|
this.doColorBulbUpdate.next();
|
|
@@ -548,7 +572,8 @@ export class ColorBulb {
|
|
|
548
572
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
549
573
|
*/
|
|
550
574
|
ColorTemperatureSet(value: CharacteristicValue) {
|
|
551
|
-
this.
|
|
575
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${value}`);
|
|
576
|
+
|
|
552
577
|
|
|
553
578
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
554
579
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
@@ -573,7 +598,7 @@ export class ColorBulb {
|
|
|
573
598
|
* Handle requests to set the value of the "Hue" characteristic
|
|
574
599
|
*/
|
|
575
600
|
HueSet(value: CharacteristicValue) {
|
|
576
|
-
this.
|
|
601
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${value}`);
|
|
577
602
|
|
|
578
603
|
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
579
604
|
|
|
@@ -585,12 +610,47 @@ export class ColorBulb {
|
|
|
585
610
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
586
611
|
*/
|
|
587
612
|
SaturationSet(value: CharacteristicValue) {
|
|
588
|
-
this.
|
|
613
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`);
|
|
589
614
|
|
|
590
615
|
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
591
616
|
|
|
592
617
|
this.Saturation = value;
|
|
593
618
|
this.doColorBulbUpdate.next();
|
|
594
619
|
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Logging for Device
|
|
623
|
+
*/
|
|
624
|
+
infoLog(...log: any[]) {
|
|
625
|
+
if (this.enablingDeviceLogging()) {
|
|
626
|
+
this.platform.log.info(String(...log));
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
warnLog(...log: any[]) {
|
|
631
|
+
if (this.enablingDeviceLogging()) {
|
|
632
|
+
this.platform.log.warn(String(...log));
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
errorLog(...log: any[]) {
|
|
637
|
+
if (this.enablingDeviceLogging()) {
|
|
638
|
+
this.platform.log.error(String(...log));
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
debugLog(...log: any[]) {
|
|
643
|
+
if (this.enablingDeviceLogging()) {
|
|
644
|
+
if (this.deviceLogging === 'debug') {
|
|
645
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
646
|
+
} else {
|
|
647
|
+
this.platform.log.debug(String(...log));
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
enablingDeviceLogging(): boolean {
|
|
653
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
654
|
+
}
|
|
595
655
|
}
|
|
596
656
|
|