@switchbot/homebridge-switchbot 1.4.1-beta.0 → 1.4.1-beta.4
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 +20 -0
- package/config.schema.json +83 -11
- package/dist/devices/bots.d.ts +12 -2
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +155 -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 +153 -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 +116 -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 +191 -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 +171 -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 +113 -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 +101 -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 +95 -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 +10 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +290 -307
- 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 +10 -6
- package/src/devices/bots.ts +161 -89
- package/src/devices/colorbulb.ts +161 -86
- package/src/devices/contact.ts +122 -52
- package/src/devices/curtains.ts +199 -128
- package/src/devices/humidifiers.ts +177 -109
- package/src/devices/meters.ts +119 -49
- package/src/devices/motion.ts +106 -36
- package/src/devices/plugs.ts +99 -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 +285 -302
- 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,40 @@ 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
|
+
if (this.platform.debugMode) {
|
|
204
|
+
this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
205
|
+
}
|
|
206
|
+
} else if (this.platform.config.options!.refreshRate) {
|
|
207
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
208
|
+
if (this.platform.debugMode) {
|
|
209
|
+
this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
logs() {
|
|
215
|
+
if (this.device.logging) {
|
|
216
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
217
|
+
if (this.platform.debugMode) {
|
|
218
|
+
this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
|
|
219
|
+
}
|
|
220
|
+
} else if (this.platform.config.options?.logging) {
|
|
221
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
222
|
+
if (this.platform.debugMode) {
|
|
223
|
+
this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
227
|
+
if (this.platform.debugMode) {
|
|
228
|
+
this.warnLog('Using Device Standard Logging');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private minStep(): number {
|
|
199
234
|
if (this.device.colorbulb?.set_minStep) {
|
|
200
235
|
this.set_minStep = this.device.colorbulb?.set_minStep;
|
|
201
236
|
} else {
|
|
@@ -212,58 +247,58 @@ export class ColorBulb {
|
|
|
212
247
|
default:
|
|
213
248
|
this.On = false;
|
|
214
249
|
}
|
|
215
|
-
this.
|
|
250
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
|
|
216
251
|
|
|
217
252
|
// Brightness
|
|
218
253
|
this.Brightness = Number(this.deviceStatus.body.brightness);
|
|
219
|
-
this.
|
|
254
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
220
255
|
|
|
221
256
|
// Color, Hue & Brightness
|
|
222
257
|
if (this.deviceStatus.body.color) {
|
|
223
|
-
this.
|
|
258
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.deviceStatus.body.color)}`);
|
|
224
259
|
const [red, green, blue] = this.deviceStatus.body.color!.split(':');
|
|
225
|
-
this.
|
|
226
|
-
this.
|
|
227
|
-
this.
|
|
260
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
261
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
262
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
228
263
|
|
|
229
264
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
230
|
-
this.
|
|
265
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
231
266
|
|
|
232
267
|
// Hue
|
|
233
268
|
this.Hue = hue;
|
|
234
|
-
this.
|
|
269
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
235
270
|
|
|
236
271
|
// Saturation
|
|
237
272
|
this.Saturation = saturation;
|
|
238
|
-
this.
|
|
273
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
239
274
|
}
|
|
240
275
|
|
|
241
276
|
// ColorTemperature
|
|
242
277
|
if (!Number.isNaN(this.deviceStatus.body.colorTemperature)) {
|
|
243
|
-
this.
|
|
278
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.deviceStatus.body.colorTemperature}`);
|
|
244
279
|
const mired = Math.round(1000000 / this.deviceStatus.body.colorTemperature!);
|
|
245
280
|
|
|
246
281
|
this.ColorTemperature = Number(mired);
|
|
247
282
|
|
|
248
283
|
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
249
|
-
this.
|
|
284
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
250
285
|
}
|
|
251
286
|
}
|
|
252
287
|
|
|
253
288
|
async refreshStatus() {
|
|
254
289
|
try {
|
|
255
290
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
256
|
-
this.
|
|
291
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
257
292
|
this.parseStatus();
|
|
258
293
|
this.updateHomeKitCharacteristics();
|
|
259
294
|
} catch (e: any) {
|
|
260
|
-
this.
|
|
261
|
-
if (this.
|
|
262
|
-
this.
|
|
295
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
296
|
+
if (this.deviceLogging === 'debug') {
|
|
297
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
263
298
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
264
299
|
}
|
|
265
|
-
if (this.
|
|
266
|
-
this.
|
|
300
|
+
if (this.platform.debugMode) {
|
|
301
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
267
302
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
268
303
|
}
|
|
269
304
|
this.apiError();
|
|
@@ -295,12 +330,12 @@ export class ColorBulb {
|
|
|
295
330
|
payload.command = 'turnOff';
|
|
296
331
|
}
|
|
297
332
|
|
|
298
|
-
this.
|
|
333
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
299
334
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
300
335
|
|
|
301
336
|
// Make the API request
|
|
302
337
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
303
|
-
this.
|
|
338
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
304
339
|
this.statusCode(push);
|
|
305
340
|
this.OnCached = this.On;
|
|
306
341
|
this.accessory.context.On = this.OnCached;
|
|
@@ -321,13 +356,13 @@ export class ColorBulb {
|
|
|
321
356
|
}
|
|
322
357
|
|
|
323
358
|
} catch (e: any) {
|
|
324
|
-
this.
|
|
325
|
-
if (this.
|
|
326
|
-
this.
|
|
359
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
360
|
+
if (this.deviceLogging === 'debug') {
|
|
361
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
327
362
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
328
363
|
}
|
|
329
|
-
if (this.
|
|
330
|
-
this.
|
|
364
|
+
if (this.platform.debugMode) {
|
|
365
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
331
366
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
332
367
|
}
|
|
333
368
|
this.apiError();
|
|
@@ -337,11 +372,11 @@ export class ColorBulb {
|
|
|
337
372
|
private async pushHueSaturationChanges() {
|
|
338
373
|
try {
|
|
339
374
|
if ((this.Hue !== this.HueCached) || (this.Saturation !== this.SaturationCached)) {
|
|
340
|
-
this.
|
|
341
|
-
this.
|
|
375
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
376
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
342
377
|
|
|
343
378
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
344
|
-
this.
|
|
379
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
345
380
|
|
|
346
381
|
const payload = {
|
|
347
382
|
commandType: 'command',
|
|
@@ -349,27 +384,27 @@ export class ColorBulb {
|
|
|
349
384
|
parameter: `${red}:${green}:${blue}`,
|
|
350
385
|
} as payload;
|
|
351
386
|
|
|
352
|
-
this.
|
|
387
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
353
388
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
354
389
|
|
|
355
390
|
// Make the API request
|
|
356
391
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
357
|
-
this.
|
|
392
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
358
393
|
this.statusCode(push);
|
|
359
394
|
this.HueCached = this.Hue;
|
|
360
395
|
this.SaturationCached = this.Saturation;
|
|
361
396
|
} else {
|
|
362
|
-
this.
|
|
397
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
363
398
|
+ `Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`);
|
|
364
399
|
}
|
|
365
400
|
} catch (e: any) {
|
|
366
|
-
this.
|
|
367
|
-
if (this.
|
|
368
|
-
this.
|
|
401
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
402
|
+
if (this.deviceLogging === 'debug') {
|
|
403
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
369
404
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
370
405
|
}
|
|
371
|
-
if (this.
|
|
372
|
-
this.
|
|
406
|
+
if (this.platform.debugMode) {
|
|
407
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
373
408
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
374
409
|
}
|
|
375
410
|
this.apiError();
|
|
@@ -388,26 +423,26 @@ export class ColorBulb {
|
|
|
388
423
|
parameter: `${kelvin}`,
|
|
389
424
|
} as payload;
|
|
390
425
|
|
|
391
|
-
this.
|
|
426
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
392
427
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
393
428
|
|
|
394
429
|
// Make the API request
|
|
395
430
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
396
|
-
this.
|
|
431
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
397
432
|
this.statusCode(push);
|
|
398
433
|
this.ColorTemperatureCached = this.ColorTemperature;
|
|
399
434
|
} else {
|
|
400
|
-
this.
|
|
435
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
401
436
|
+ `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`);
|
|
402
437
|
}
|
|
403
438
|
} catch (e: any) {
|
|
404
|
-
this.
|
|
405
|
-
if (this.
|
|
406
|
-
this.
|
|
439
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
440
|
+
if (this.deviceLogging === 'debug') {
|
|
441
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
407
442
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
408
443
|
}
|
|
409
|
-
if (this.
|
|
410
|
-
this.
|
|
444
|
+
if (this.platform.debugMode) {
|
|
445
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
411
446
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
412
447
|
}
|
|
413
448
|
this.apiError();
|
|
@@ -423,26 +458,26 @@ export class ColorBulb {
|
|
|
423
458
|
parameter: `${this.Brightness}`,
|
|
424
459
|
} as payload;
|
|
425
460
|
|
|
426
|
-
this.
|
|
461
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
427
462
|
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
428
463
|
|
|
429
464
|
// Make the API request
|
|
430
465
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
431
|
-
this.
|
|
466
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
432
467
|
this.statusCode(push);
|
|
433
468
|
this.BrightnessCached = this.Brightness;
|
|
434
469
|
} else {
|
|
435
|
-
this.
|
|
470
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
436
471
|
+ `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`);
|
|
437
472
|
}
|
|
438
473
|
} catch (e: any) {
|
|
439
|
-
this.
|
|
440
|
-
if (this.
|
|
441
|
-
this.
|
|
474
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
475
|
+
if (this.deviceLogging === 'debug') {
|
|
476
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
442
477
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
443
478
|
}
|
|
444
|
-
if (this.
|
|
445
|
-
this.
|
|
479
|
+
if (this.platform.debugMode) {
|
|
480
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
446
481
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
447
482
|
}
|
|
448
483
|
this.apiError();
|
|
@@ -451,34 +486,34 @@ export class ColorBulb {
|
|
|
451
486
|
|
|
452
487
|
updateHomeKitCharacteristics() {
|
|
453
488
|
if (this.On === undefined) {
|
|
454
|
-
this.
|
|
489
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
|
|
455
490
|
} else {
|
|
456
491
|
this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
457
|
-
this.
|
|
492
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
458
493
|
}
|
|
459
494
|
if (this.Brightness === undefined) {
|
|
460
|
-
this.
|
|
495
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
461
496
|
} else {
|
|
462
497
|
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
463
|
-
this.
|
|
498
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
464
499
|
}
|
|
465
500
|
if (this.ColorTemperature === undefined) {
|
|
466
|
-
this.
|
|
501
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
467
502
|
} else {
|
|
468
503
|
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
469
|
-
this.
|
|
504
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
470
505
|
}
|
|
471
506
|
if (this.Hue === undefined) {
|
|
472
|
-
this.
|
|
507
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
473
508
|
} else {
|
|
474
509
|
this.service.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
475
|
-
this.
|
|
510
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
476
511
|
}
|
|
477
512
|
if (this.Saturation === undefined) {
|
|
478
|
-
this.
|
|
513
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
479
514
|
} else {
|
|
480
515
|
this.service.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
481
|
-
this.
|
|
516
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
482
517
|
}
|
|
483
518
|
}
|
|
484
519
|
|
|
@@ -489,31 +524,35 @@ export class ColorBulb {
|
|
|
489
524
|
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
490
525
|
switch (push.data.statusCode) {
|
|
491
526
|
case 151:
|
|
492
|
-
this.
|
|
527
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
493
528
|
break;
|
|
494
529
|
case 152:
|
|
495
|
-
this.
|
|
530
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device not found.`);
|
|
496
531
|
break;
|
|
497
532
|
case 160:
|
|
498
|
-
this.
|
|
533
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Command is not supported.`);
|
|
499
534
|
break;
|
|
500
535
|
case 161:
|
|
501
|
-
this.
|
|
536
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device is offline.`);
|
|
502
537
|
this.offlineOff();
|
|
503
538
|
break;
|
|
504
539
|
case 171:
|
|
505
|
-
this.
|
|
540
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
506
541
|
this.offlineOff();
|
|
507
542
|
break;
|
|
508
543
|
case 190:
|
|
509
|
-
this.
|
|
544
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
510
545
|
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
511
546
|
break;
|
|
512
547
|
case 100:
|
|
513
|
-
this.platform.
|
|
548
|
+
if (this.platform.debugMode) {
|
|
549
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Command successfully sent.`);
|
|
550
|
+
}
|
|
514
551
|
break;
|
|
515
552
|
default:
|
|
516
|
-
this.platform.
|
|
553
|
+
if (this.platform.debugMode) {
|
|
554
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Unknown statusCode.`);
|
|
555
|
+
}
|
|
517
556
|
}
|
|
518
557
|
}
|
|
519
558
|
|
|
@@ -528,7 +567,7 @@ export class ColorBulb {
|
|
|
528
567
|
* Handle requests to set the value of the "On" characteristic
|
|
529
568
|
*/
|
|
530
569
|
OnSet(value: CharacteristicValue) {
|
|
531
|
-
this.
|
|
570
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${value}`);
|
|
532
571
|
|
|
533
572
|
this.On = value;
|
|
534
573
|
this.doColorBulbUpdate.next();
|
|
@@ -538,7 +577,7 @@ export class ColorBulb {
|
|
|
538
577
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
539
578
|
*/
|
|
540
579
|
BrightnessSet(value: CharacteristicValue) {
|
|
541
|
-
this.
|
|
580
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${value}`);
|
|
542
581
|
|
|
543
582
|
this.Brightness = value;
|
|
544
583
|
this.doColorBulbUpdate.next();
|
|
@@ -548,7 +587,8 @@ export class ColorBulb {
|
|
|
548
587
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
549
588
|
*/
|
|
550
589
|
ColorTemperatureSet(value: CharacteristicValue) {
|
|
551
|
-
this.
|
|
590
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${value}`);
|
|
591
|
+
|
|
552
592
|
|
|
553
593
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
554
594
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
@@ -573,7 +613,7 @@ export class ColorBulb {
|
|
|
573
613
|
* Handle requests to set the value of the "Hue" characteristic
|
|
574
614
|
*/
|
|
575
615
|
HueSet(value: CharacteristicValue) {
|
|
576
|
-
this.
|
|
616
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${value}`);
|
|
577
617
|
|
|
578
618
|
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
579
619
|
|
|
@@ -585,12 +625,47 @@ export class ColorBulb {
|
|
|
585
625
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
586
626
|
*/
|
|
587
627
|
SaturationSet(value: CharacteristicValue) {
|
|
588
|
-
this.
|
|
628
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`);
|
|
589
629
|
|
|
590
630
|
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
591
631
|
|
|
592
632
|
this.Saturation = value;
|
|
593
633
|
this.doColorBulbUpdate.next();
|
|
594
634
|
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Logging for Device
|
|
638
|
+
*/
|
|
639
|
+
infoLog(...log: any[]) {
|
|
640
|
+
if (this.enablingDeviceLogging()) {
|
|
641
|
+
this.platform.log.info(String(...log));
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
warnLog(...log: any[]) {
|
|
646
|
+
if (this.enablingDeviceLogging()) {
|
|
647
|
+
this.platform.log.warn(String(...log));
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
errorLog(...log: any[]) {
|
|
652
|
+
if (this.enablingDeviceLogging()) {
|
|
653
|
+
this.platform.log.error(String(...log));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
debugLog(...log: any[]) {
|
|
658
|
+
if (this.enablingDeviceLogging()) {
|
|
659
|
+
if (this.deviceLogging === 'debug') {
|
|
660
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
661
|
+
} else {
|
|
662
|
+
this.platform.log.debug(String(...log));
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
enablingDeviceLogging(): boolean {
|
|
668
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
669
|
+
}
|
|
595
670
|
}
|
|
596
671
|
|