@switchbot/homebridge-switchbot 1.4.0 → 1.4.1-beta.3
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 +18 -0
- package/config.schema.json +83 -11
- package/dist/devices/bots.d.ts +13 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +162 -105
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +13 -3
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +161 -96
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +13 -3
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +117 -63
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +14 -5
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +198 -140
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +13 -3
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +180 -127
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +13 -3
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +121 -63
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +13 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +104 -45
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +13 -3
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +99 -35
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +11 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +80 -45
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +11 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +68 -31
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +11 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +64 -24
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +11 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +74 -35
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +11 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +65 -25
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +11 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +71 -31
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +11 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +81 -42
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +11 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +64 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +11 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +64 -24
- 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 +70 -66
- package/src/devices/bots.ts +169 -105
- package/src/devices/colorbulb.ts +170 -99
- package/src/devices/contact.ts +124 -64
- package/src/devices/curtains.ts +207 -145
- package/src/devices/humidifiers.ts +187 -129
- package/src/devices/meters.ts +128 -64
- package/src/devices/motion.ts +110 -45
- package/src/devices/plugs.ts +104 -36
- package/src/irdevices/airconditioners.ts +85 -45
- package/src/irdevices/airpurifiers.ts +73 -31
- package/src/irdevices/cameras.ts +69 -24
- package/src/irdevices/fans.ts +79 -36
- package/src/irdevices/lights.ts +70 -25
- package/src/irdevices/others.ts +76 -31
- package/src/irdevices/tvs.ts +86 -42
- package/src/irdevices/vacuumcleaners.ts +69 -24
- package/src/irdevices/waterheaters.ts +69 -24
- 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
|
@@ -2,7 +2,7 @@ import { AxiosResponse } from 'axios';
|
|
|
2
2
|
import { interval, Subject } from 'rxjs';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
4
|
import { debounceTime, skipWhile, tap } from 'rxjs/operators';
|
|
5
|
-
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
5
|
+
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap, HAPStatus } from 'homebridge';
|
|
6
6
|
import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs, m2hs } from '../settings';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -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,22 +182,55 @@ 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
|
-
this.apiError(
|
|
194
|
+
this.apiError();
|
|
193
195
|
}
|
|
194
196
|
this.colorBulbUpdateInProgress = false;
|
|
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,61 +247,61 @@ 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
|
-
this.apiError(
|
|
304
|
+
this.apiError();
|
|
270
305
|
}
|
|
271
306
|
}
|
|
272
307
|
|
|
@@ -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,27 +356,27 @@ 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
|
-
this.apiError(
|
|
368
|
+
this.apiError();
|
|
334
369
|
}
|
|
335
370
|
}
|
|
336
371
|
|
|
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,30 +384,30 @@ 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
|
-
this.apiError(
|
|
410
|
+
this.apiError();
|
|
376
411
|
}
|
|
377
412
|
}
|
|
378
413
|
|
|
@@ -388,29 +423,29 @@ 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
|
-
this.apiError(
|
|
448
|
+
this.apiError();
|
|
414
449
|
}
|
|
415
450
|
}
|
|
416
451
|
|
|
@@ -423,101 +458,101 @@ 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
|
-
this.apiError(
|
|
483
|
+
this.apiError();
|
|
449
484
|
}
|
|
450
485
|
}
|
|
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
|
|
|
485
|
-
public apiError(
|
|
486
|
-
this.
|
|
487
|
-
this.service.updateCharacteristic(this.platform.Characteristic.Hue, e);
|
|
488
|
-
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, e);
|
|
489
|
-
this.service.updateCharacteristic(this.platform.Characteristic.Saturation, e);
|
|
490
|
-
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
|
|
520
|
+
public apiError() {
|
|
521
|
+
throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
491
522
|
}
|
|
492
523
|
|
|
493
524
|
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
494
525
|
switch (push.data.statusCode) {
|
|
495
526
|
case 151:
|
|
496
|
-
this.
|
|
527
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
497
528
|
break;
|
|
498
529
|
case 152:
|
|
499
|
-
this.
|
|
530
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device not found.`);
|
|
500
531
|
break;
|
|
501
532
|
case 160:
|
|
502
|
-
this.
|
|
533
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Command is not supported.`);
|
|
503
534
|
break;
|
|
504
535
|
case 161:
|
|
505
|
-
this.
|
|
536
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device is offline.`);
|
|
506
537
|
this.offlineOff();
|
|
507
538
|
break;
|
|
508
539
|
case 171:
|
|
509
|
-
this.
|
|
540
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
510
541
|
this.offlineOff();
|
|
511
542
|
break;
|
|
512
543
|
case 190:
|
|
513
|
-
this.
|
|
544
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
514
545
|
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
515
546
|
break;
|
|
516
547
|
case 100:
|
|
517
|
-
this.platform.
|
|
548
|
+
if (this.platform.debugMode) {
|
|
549
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Command successfully sent.`);
|
|
550
|
+
}
|
|
518
551
|
break;
|
|
519
552
|
default:
|
|
520
|
-
this.platform.
|
|
553
|
+
if (this.platform.debugMode) {
|
|
554
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Unknown statusCode.`);
|
|
555
|
+
}
|
|
521
556
|
}
|
|
522
557
|
}
|
|
523
558
|
|
|
@@ -532,7 +567,7 @@ export class ColorBulb {
|
|
|
532
567
|
* Handle requests to set the value of the "On" characteristic
|
|
533
568
|
*/
|
|
534
569
|
OnSet(value: CharacteristicValue) {
|
|
535
|
-
this.
|
|
570
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${value}`);
|
|
536
571
|
|
|
537
572
|
this.On = value;
|
|
538
573
|
this.doColorBulbUpdate.next();
|
|
@@ -542,7 +577,7 @@ export class ColorBulb {
|
|
|
542
577
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
543
578
|
*/
|
|
544
579
|
BrightnessSet(value: CharacteristicValue) {
|
|
545
|
-
this.
|
|
580
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${value}`);
|
|
546
581
|
|
|
547
582
|
this.Brightness = value;
|
|
548
583
|
this.doColorBulbUpdate.next();
|
|
@@ -552,7 +587,8 @@ export class ColorBulb {
|
|
|
552
587
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
553
588
|
*/
|
|
554
589
|
ColorTemperatureSet(value: CharacteristicValue) {
|
|
555
|
-
this.
|
|
590
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${value}`);
|
|
591
|
+
|
|
556
592
|
|
|
557
593
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
558
594
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
@@ -577,7 +613,7 @@ export class ColorBulb {
|
|
|
577
613
|
* Handle requests to set the value of the "Hue" characteristic
|
|
578
614
|
*/
|
|
579
615
|
HueSet(value: CharacteristicValue) {
|
|
580
|
-
this.
|
|
616
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${value}`);
|
|
581
617
|
|
|
582
618
|
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
583
619
|
|
|
@@ -589,12 +625,47 @@ export class ColorBulb {
|
|
|
589
625
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
590
626
|
*/
|
|
591
627
|
SaturationSet(value: CharacteristicValue) {
|
|
592
|
-
this.
|
|
628
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`);
|
|
593
629
|
|
|
594
630
|
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
595
631
|
|
|
596
632
|
this.Saturation = value;
|
|
597
633
|
this.doColorBulbUpdate.next();
|
|
598
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
|
+
}
|
|
599
670
|
}
|
|
600
671
|
|