@switchbot/homebridge-switchbot 1.10.2-beta.8 → 1.11.0
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 +3 -3
- package/config.schema.json +49 -0
- package/dist/device/bot.d.ts +43 -40
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +26 -26
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +25 -21
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +173 -145
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +15 -15
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +14 -13
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +25 -22
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +50 -37
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +23 -20
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -38
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +16 -13
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +14 -14
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +15 -15
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +11 -11
- package/dist/device/meter.js.map +1 -1
- package/dist/device/motion.d.ts +14 -14
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +13 -13
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +10 -7
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +17 -17
- package/dist/device/plug.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/package.json +76 -76
- package/src/device/bot.ts +50 -50
- package/src/device/colorbulb.ts +205 -162
- package/src/device/contact.ts +31 -30
- package/src/device/curtain.ts +68 -57
- package/src/device/humidifier.ts +65 -53
- package/src/device/lock.ts +22 -22
- package/src/device/meter.ts +25 -25
- package/src/device/motion.ts +27 -27
- package/src/device/plug.ts +20 -20
- package/src/settings.ts +5 -1
package/src/device/colorbulb.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payl
|
|
|
12
12
|
*/
|
|
13
13
|
export class ColorBulb {
|
|
14
14
|
// Services
|
|
15
|
-
|
|
15
|
+
lightBulbService!: Service;
|
|
16
16
|
|
|
17
17
|
// Characteristic Values
|
|
18
18
|
On!: CharacteristicValue;
|
|
@@ -23,14 +23,14 @@ export class ColorBulb {
|
|
|
23
23
|
SaturationCached!: CharacteristicValue;
|
|
24
24
|
Brightness!: CharacteristicValue;
|
|
25
25
|
BrightnessCached!: CharacteristicValue;
|
|
26
|
-
ColorTemperature
|
|
27
|
-
ColorTemperatureCached
|
|
26
|
+
ColorTemperature?: CharacteristicValue;
|
|
27
|
+
ColorTemperatureCached?: CharacteristicValue;
|
|
28
28
|
|
|
29
29
|
// OpenAPI Others
|
|
30
30
|
power: deviceStatus['power'];
|
|
31
31
|
color: deviceStatus['color'];
|
|
32
32
|
brightness: deviceStatus['brightness'];
|
|
33
|
-
colorTemperature
|
|
33
|
+
colorTemperature?: deviceStatus['colorTemperature'];
|
|
34
34
|
deviceStatus!: deviceStatusResponse;
|
|
35
35
|
|
|
36
36
|
// BLE Others
|
|
@@ -44,13 +44,15 @@ export class ColorBulb {
|
|
|
44
44
|
|
|
45
45
|
// Adaptive Lighting
|
|
46
46
|
AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
|
|
47
|
-
minKelvin
|
|
48
|
-
maxKelvin
|
|
47
|
+
minKelvin!: number;
|
|
48
|
+
maxKelvin!: number;
|
|
49
|
+
|
|
50
|
+
// Others
|
|
51
|
+
cacheKelvin!: number;
|
|
49
52
|
|
|
50
53
|
// Updates
|
|
51
54
|
colorBulbUpdateInProgress!: boolean;
|
|
52
55
|
doColorBulbUpdate!: Subject<void>;
|
|
53
|
-
cacheKelvin!: number;
|
|
54
56
|
|
|
55
57
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
56
58
|
// default placeholders
|
|
@@ -63,12 +65,6 @@ export class ColorBulb {
|
|
|
63
65
|
} else {
|
|
64
66
|
this.On = this.accessory.context.On;
|
|
65
67
|
}
|
|
66
|
-
this.Hue = 0;
|
|
67
|
-
this.Brightness = 0;
|
|
68
|
-
this.Saturation = 0;
|
|
69
|
-
this.ColorTemperature = 140;
|
|
70
|
-
this.minKelvin = 2000;
|
|
71
|
-
this.maxKelvin = 9000;
|
|
72
68
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
73
69
|
this.doColorBulbUpdate = new Subject();
|
|
74
70
|
this.colorBulbUpdateInProgress = false;
|
|
@@ -80,19 +76,19 @@ export class ColorBulb {
|
|
|
80
76
|
accessory
|
|
81
77
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
82
78
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
83
|
-
.setCharacteristic(this.platform.Characteristic.Model,
|
|
79
|
+
.setCharacteristic(this.platform.Characteristic.Model, this.model(device))
|
|
84
80
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
85
81
|
|
|
86
82
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
87
83
|
// you can create multiple services for each accessory
|
|
88
|
-
(this.
|
|
89
|
-
`${accessory.displayName}
|
|
84
|
+
(this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
|
|
85
|
+
`${accessory.displayName} ${this.device.deviceType}`;
|
|
90
86
|
|
|
91
87
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
92
|
-
this.accessory.removeService(this.
|
|
93
|
-
this.
|
|
88
|
+
this.accessory.removeService(this.lightBulbService);
|
|
89
|
+
this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
94
90
|
this.accessory.context.adaptiveLighting = false;
|
|
95
|
-
this.debugLog(
|
|
91
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
96
92
|
}
|
|
97
93
|
|
|
98
94
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -101,13 +97,13 @@ export class ColorBulb {
|
|
|
101
97
|
|
|
102
98
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
103
99
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
104
|
-
this.
|
|
100
|
+
this.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
105
101
|
|
|
106
102
|
// handle on / off events using the On characteristic
|
|
107
|
-
this.
|
|
103
|
+
this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
108
104
|
|
|
109
105
|
// handle Brightness events using the Brightness characteristic
|
|
110
|
-
this.
|
|
106
|
+
this.lightBulbService
|
|
111
107
|
.getCharacteristic(this.platform.Characteristic.Brightness)
|
|
112
108
|
.setProps({
|
|
113
109
|
minStep: this.minStep(device),
|
|
@@ -121,20 +117,25 @@ export class ColorBulb {
|
|
|
121
117
|
.onSet(this.BrightnessSet.bind(this));
|
|
122
118
|
|
|
123
119
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
124
|
-
|
|
125
|
-
.
|
|
126
|
-
.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
120
|
+
if (device.deviceType === 'Color Bulb') {
|
|
121
|
+
this.debugLog(`Color Bulb: ${accessory.displayName} Add ColorTemperature Characteristic`);
|
|
122
|
+
this.lightBulbService
|
|
123
|
+
.getCharacteristic(this.platform.Characteristic.ColorTemperature)
|
|
124
|
+
.setProps({
|
|
125
|
+
minValue: 140,
|
|
126
|
+
maxValue: 500,
|
|
127
|
+
validValueRanges: [140, 500],
|
|
128
|
+
})
|
|
129
|
+
.onGet(() => {
|
|
130
|
+
return this.ColorTemperature!;
|
|
131
|
+
})
|
|
132
|
+
.onSet(this.ColorTemperatureSet.bind(this));
|
|
133
|
+
} else {
|
|
134
|
+
this.debugLog(`Color Bulb: ${accessory.displayName} ColorTemperature Characteristic Not Added`);
|
|
135
|
+
}
|
|
135
136
|
|
|
136
137
|
// handle Hue events using the Hue characteristic
|
|
137
|
-
this.
|
|
138
|
+
this.lightBulbService
|
|
138
139
|
.getCharacteristic(this.platform.Characteristic.Hue)
|
|
139
140
|
.setProps({
|
|
140
141
|
minValue: 0,
|
|
@@ -147,7 +148,7 @@ export class ColorBulb {
|
|
|
147
148
|
.onSet(this.HueSet.bind(this));
|
|
148
149
|
|
|
149
150
|
// handle Hue events using the Hue characteristic
|
|
150
|
-
this.
|
|
151
|
+
this.lightBulbService
|
|
151
152
|
.getCharacteristic(this.platform.Characteristic.Saturation)
|
|
152
153
|
.setProps({
|
|
153
154
|
minValue: 0,
|
|
@@ -159,15 +160,15 @@ export class ColorBulb {
|
|
|
159
160
|
})
|
|
160
161
|
.onSet(this.SaturationSet.bind(this));
|
|
161
162
|
|
|
162
|
-
this.debugLog(
|
|
163
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
163
164
|
if (this.adaptiveLightingShift !== -1) {
|
|
164
|
-
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.
|
|
165
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
|
|
165
166
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
166
167
|
});
|
|
167
168
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
168
169
|
this.accessory.context.adaptiveLighting = true;
|
|
169
170
|
this.debugLog(
|
|
170
|
-
|
|
171
|
+
`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
171
172
|
` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
172
173
|
);
|
|
173
174
|
}
|
|
@@ -178,8 +179,8 @@ export class ColorBulb {
|
|
|
178
179
|
// Start an update interval
|
|
179
180
|
interval(this.deviceRefreshRate * 1000)
|
|
180
181
|
.pipe(skipWhile(() => this.colorBulbUpdateInProgress))
|
|
181
|
-
.subscribe(() => {
|
|
182
|
-
this.refreshStatus();
|
|
182
|
+
.subscribe(async () => {
|
|
183
|
+
await this.refreshStatus();
|
|
183
184
|
});
|
|
184
185
|
|
|
185
186
|
// Watch for Bulb change events
|
|
@@ -195,12 +196,14 @@ export class ColorBulb {
|
|
|
195
196
|
try {
|
|
196
197
|
await this.pushChanges();
|
|
197
198
|
} catch (e: any) {
|
|
198
|
-
this.errorLog(
|
|
199
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
|
|
199
200
|
if (this.deviceLogging === 'debug') {
|
|
200
|
-
this.errorLog(
|
|
201
|
+
this.errorLog(
|
|
202
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
203
|
+
);
|
|
201
204
|
}
|
|
202
205
|
if (this.platform.debugMode) {
|
|
203
|
-
this.errorLog(
|
|
206
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
|
|
204
207
|
}
|
|
205
208
|
this.apiError(e);
|
|
206
209
|
}
|
|
@@ -208,7 +211,7 @@ export class ColorBulb {
|
|
|
208
211
|
});
|
|
209
212
|
}
|
|
210
213
|
|
|
211
|
-
parseStatus() {
|
|
214
|
+
async parseStatus(): Promise<void> {
|
|
212
215
|
switch (this.power) {
|
|
213
216
|
case 'on':
|
|
214
217
|
this.On = true;
|
|
@@ -216,63 +219,72 @@ export class ColorBulb {
|
|
|
216
219
|
default:
|
|
217
220
|
this.On = false;
|
|
218
221
|
}
|
|
219
|
-
this.debugLog(
|
|
222
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
220
223
|
|
|
221
224
|
// Brightness
|
|
222
225
|
this.Brightness = Number(this.brightness);
|
|
223
|
-
this.debugLog(
|
|
226
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
224
227
|
|
|
225
228
|
// Color, Hue & Brightness
|
|
226
229
|
if (this.color) {
|
|
227
|
-
this.debugLog(
|
|
230
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
|
|
228
231
|
const [red, green, blue] = this.color!.split(':');
|
|
229
|
-
this.debugLog(
|
|
230
|
-
this.debugLog(
|
|
231
|
-
this.debugLog(
|
|
232
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
233
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
234
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
232
235
|
|
|
233
236
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
234
|
-
this.debugLog(
|
|
237
|
+
this.debugLog(
|
|
238
|
+
`${this.device.deviceType}: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
|
|
239
|
+
);
|
|
235
240
|
|
|
236
241
|
// Hue
|
|
237
242
|
this.Hue = hue;
|
|
238
|
-
this.debugLog(
|
|
243
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
239
244
|
|
|
240
245
|
// Saturation
|
|
241
246
|
this.Saturation = saturation;
|
|
242
|
-
this.debugLog(
|
|
247
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
243
248
|
}
|
|
244
249
|
|
|
245
250
|
// ColorTemperature
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
|
|
251
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
252
|
+
if (!Number.isNaN(this.colorTemperature)) {
|
|
253
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
|
|
254
|
+
const mired = Math.round(1000000 / this.colorTemperature!);
|
|
249
255
|
|
|
250
|
-
|
|
256
|
+
this.ColorTemperature = Number(mired);
|
|
251
257
|
|
|
252
|
-
|
|
253
|
-
|
|
258
|
+
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
259
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
260
|
+
}
|
|
254
261
|
}
|
|
255
262
|
}
|
|
256
263
|
|
|
257
|
-
async refreshStatus() {
|
|
264
|
+
async refreshStatus(): Promise<void> {
|
|
258
265
|
try {
|
|
259
266
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
260
|
-
this.debugLog(
|
|
267
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
261
268
|
this.power = this.deviceStatus.body.power;
|
|
262
269
|
this.color = this.deviceStatus.body.color;
|
|
263
270
|
this.brightness = this.deviceStatus.body.brightness;
|
|
264
|
-
this.
|
|
271
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
272
|
+
this.colorTemperature = this.deviceStatus.body.colorTemperature;
|
|
273
|
+
}
|
|
265
274
|
this.parseStatus();
|
|
266
275
|
this.updateHomeKitCharacteristics();
|
|
267
276
|
} catch (e: any) {
|
|
268
|
-
this.errorLog(
|
|
277
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
269
278
|
if (this.deviceLogging === 'debug') {
|
|
270
279
|
this.errorLog(
|
|
271
|
-
|
|
280
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
281
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
272
282
|
);
|
|
273
283
|
}
|
|
274
284
|
if (this.platform.debugMode) {
|
|
275
|
-
this.errorLog(
|
|
285
|
+
this.errorLog(
|
|
286
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
|
|
287
|
+
);
|
|
276
288
|
}
|
|
277
289
|
this.apiError(e);
|
|
278
290
|
}
|
|
@@ -294,7 +306,7 @@ export class ColorBulb {
|
|
|
294
306
|
* Strip Light - "command" "setColor" "`"{0-255}:{0-255}:{0-255}"`" = set RGB color value |
|
|
295
307
|
*
|
|
296
308
|
*/
|
|
297
|
-
async pushChanges() {
|
|
309
|
+
async pushChanges(): Promise<void> {
|
|
298
310
|
try {
|
|
299
311
|
if (this.On !== this.OnCached) {
|
|
300
312
|
// Push On Update
|
|
@@ -310,13 +322,13 @@ export class ColorBulb {
|
|
|
310
322
|
}
|
|
311
323
|
|
|
312
324
|
this.infoLog(
|
|
313
|
-
|
|
325
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
314
326
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
315
327
|
);
|
|
316
328
|
|
|
317
329
|
// Make the API request
|
|
318
330
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
319
|
-
this.debugLog(
|
|
331
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
320
332
|
this.statusCode(push);
|
|
321
333
|
this.OnCached = this.On;
|
|
322
334
|
this.accessory.context.On = this.OnCached;
|
|
@@ -327,7 +339,7 @@ export class ColorBulb {
|
|
|
327
339
|
}
|
|
328
340
|
|
|
329
341
|
// Push ColorTemperature Update
|
|
330
|
-
if (this.On) {
|
|
342
|
+
if (this.On && this.device.deviceType === 'Color Bulb') {
|
|
331
343
|
await this.pushColorTemperatureChanges();
|
|
332
344
|
}
|
|
333
345
|
|
|
@@ -336,27 +348,30 @@ export class ColorBulb {
|
|
|
336
348
|
await this.pushHueSaturationChanges();
|
|
337
349
|
}
|
|
338
350
|
} catch (e: any) {
|
|
339
|
-
this.errorLog(
|
|
351
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
340
352
|
if (this.deviceLogging === 'debug') {
|
|
341
353
|
this.errorLog(
|
|
342
|
-
|
|
354
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
355
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
343
356
|
);
|
|
344
357
|
}
|
|
345
358
|
if (this.platform.debugMode) {
|
|
346
|
-
this.errorLog(
|
|
359
|
+
this.errorLog(
|
|
360
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
|
|
361
|
+
);
|
|
347
362
|
}
|
|
348
363
|
this.apiError(e);
|
|
349
364
|
}
|
|
350
365
|
}
|
|
351
366
|
|
|
352
|
-
|
|
367
|
+
async pushHueSaturationChanges(): Promise<void> {
|
|
353
368
|
try {
|
|
354
369
|
if (this.Hue !== this.HueCached || this.Saturation !== this.SaturationCached) {
|
|
355
|
-
this.debugLog(
|
|
356
|
-
this.debugLog(
|
|
370
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
371
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
357
372
|
|
|
358
373
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
359
|
-
this.debugLog(
|
|
374
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
360
375
|
|
|
361
376
|
const payload = {
|
|
362
377
|
commandType: 'command',
|
|
@@ -365,37 +380,40 @@ export class ColorBulb {
|
|
|
365
380
|
} as payload;
|
|
366
381
|
|
|
367
382
|
this.infoLog(
|
|
368
|
-
|
|
383
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
369
384
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
370
385
|
);
|
|
371
386
|
|
|
372
387
|
// Make the API request
|
|
373
388
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
374
|
-
this.debugLog(
|
|
389
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
375
390
|
this.statusCode(push);
|
|
376
391
|
this.HueCached = this.Hue;
|
|
377
392
|
this.SaturationCached = this.Saturation;
|
|
378
393
|
} else {
|
|
379
394
|
this.debugLog(
|
|
380
|
-
|
|
395
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
381
396
|
`Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`,
|
|
382
397
|
);
|
|
383
398
|
}
|
|
384
399
|
} catch (e: any) {
|
|
385
|
-
this.errorLog(
|
|
400
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
386
401
|
if (this.deviceLogging === 'debug') {
|
|
387
402
|
this.errorLog(
|
|
388
|
-
|
|
403
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
404
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
389
405
|
);
|
|
390
406
|
}
|
|
391
407
|
if (this.platform.debugMode) {
|
|
392
|
-
this.errorLog(
|
|
408
|
+
this.errorLog(
|
|
409
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
|
|
410
|
+
);
|
|
393
411
|
}
|
|
394
412
|
this.apiError(e);
|
|
395
413
|
}
|
|
396
414
|
}
|
|
397
415
|
|
|
398
|
-
|
|
416
|
+
async pushColorTemperatureChanges(): Promise<void> {
|
|
399
417
|
try {
|
|
400
418
|
if (this.ColorTemperature !== this.ColorTemperatureCached) {
|
|
401
419
|
const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
|
|
@@ -408,36 +426,39 @@ export class ColorBulb {
|
|
|
408
426
|
} as payload;
|
|
409
427
|
|
|
410
428
|
this.infoLog(
|
|
411
|
-
|
|
429
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
412
430
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
413
431
|
);
|
|
414
432
|
|
|
415
433
|
// Make the API request
|
|
416
434
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
417
|
-
this.debugLog(
|
|
435
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
418
436
|
this.statusCode(push);
|
|
419
437
|
this.ColorTemperatureCached = this.ColorTemperature;
|
|
420
438
|
} else {
|
|
421
439
|
this.debugLog(
|
|
422
|
-
|
|
440
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
423
441
|
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`,
|
|
424
442
|
);
|
|
425
443
|
}
|
|
426
444
|
} catch (e: any) {
|
|
427
|
-
this.errorLog(
|
|
445
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
428
446
|
if (this.deviceLogging === 'debug') {
|
|
429
447
|
this.errorLog(
|
|
430
|
-
|
|
448
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
449
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
431
450
|
);
|
|
432
451
|
}
|
|
433
452
|
if (this.platform.debugMode) {
|
|
434
|
-
this.errorLog(
|
|
453
|
+
this.errorLog(
|
|
454
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
|
|
455
|
+
);
|
|
435
456
|
}
|
|
436
457
|
this.apiError(e);
|
|
437
458
|
}
|
|
438
459
|
}
|
|
439
460
|
|
|
440
|
-
|
|
461
|
+
async pushBrightnessChanges(): Promise<void> {
|
|
441
462
|
try {
|
|
442
463
|
if (this.Brightness !== this.BrightnessCached) {
|
|
443
464
|
const payload = {
|
|
@@ -447,125 +468,133 @@ export class ColorBulb {
|
|
|
447
468
|
} as payload;
|
|
448
469
|
|
|
449
470
|
this.infoLog(
|
|
450
|
-
|
|
471
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
451
472
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
452
473
|
);
|
|
453
474
|
|
|
454
475
|
// Make the API request
|
|
455
476
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
456
|
-
this.debugLog(
|
|
477
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
457
478
|
this.statusCode(push);
|
|
458
479
|
this.BrightnessCached = this.Brightness;
|
|
459
480
|
} else {
|
|
460
481
|
this.debugLog(
|
|
461
|
-
|
|
482
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
483
|
+
`Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
|
|
462
484
|
);
|
|
463
485
|
}
|
|
464
486
|
} catch (e: any) {
|
|
465
|
-
this.errorLog(
|
|
487
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
466
488
|
if (this.deviceLogging === 'debug') {
|
|
467
489
|
this.errorLog(
|
|
468
|
-
|
|
490
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
491
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
469
492
|
);
|
|
470
493
|
}
|
|
471
494
|
if (this.platform.debugMode) {
|
|
472
|
-
this.errorLog(
|
|
495
|
+
this.errorLog(
|
|
496
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
|
|
497
|
+
);
|
|
473
498
|
}
|
|
474
499
|
this.apiError(e);
|
|
475
500
|
}
|
|
476
501
|
}
|
|
477
502
|
|
|
478
|
-
updateHomeKitCharacteristics() {
|
|
503
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
479
504
|
if (this.On === undefined) {
|
|
480
|
-
this.debugLog(
|
|
505
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
481
506
|
} else {
|
|
482
|
-
this.
|
|
483
|
-
this.debugLog(
|
|
507
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
508
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
484
509
|
}
|
|
485
510
|
if (this.Brightness === undefined) {
|
|
486
|
-
this.debugLog(
|
|
511
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
487
512
|
} else {
|
|
488
|
-
this.
|
|
489
|
-
this.debugLog(
|
|
513
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
514
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
490
515
|
}
|
|
491
|
-
if (this.
|
|
492
|
-
this.
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
516
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
517
|
+
if (this.ColorTemperature === undefined) {
|
|
518
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
519
|
+
} else {
|
|
520
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
521
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
522
|
+
}
|
|
496
523
|
}
|
|
497
524
|
if (this.Hue === undefined) {
|
|
498
|
-
this.debugLog(
|
|
525
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
499
526
|
} else {
|
|
500
|
-
this.
|
|
501
|
-
this.debugLog(
|
|
527
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
528
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
502
529
|
}
|
|
503
530
|
if (this.Saturation === undefined) {
|
|
504
|
-
this.debugLog(
|
|
531
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
505
532
|
} else {
|
|
506
|
-
this.
|
|
507
|
-
this.debugLog(
|
|
533
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
534
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
508
535
|
}
|
|
509
536
|
}
|
|
510
537
|
|
|
511
|
-
|
|
512
|
-
this.
|
|
513
|
-
this.
|
|
514
|
-
this.
|
|
515
|
-
this.
|
|
516
|
-
|
|
538
|
+
apiError(e: any): void {
|
|
539
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
540
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, e);
|
|
541
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, e);
|
|
542
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e);
|
|
543
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
544
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
|
|
545
|
+
}
|
|
517
546
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
518
547
|
}
|
|
519
548
|
|
|
520
|
-
|
|
549
|
+
statusCode(push: AxiosResponse<{ statusCode: number }>): void {
|
|
521
550
|
switch (push.data.statusCode) {
|
|
522
551
|
case 151:
|
|
523
|
-
this.errorLog(
|
|
552
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
524
553
|
break;
|
|
525
554
|
case 152:
|
|
526
|
-
this.errorLog(
|
|
555
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
527
556
|
break;
|
|
528
557
|
case 160:
|
|
529
|
-
this.errorLog(
|
|
558
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
530
559
|
break;
|
|
531
560
|
case 161:
|
|
532
|
-
this.errorLog(
|
|
561
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
533
562
|
this.offlineOff();
|
|
534
563
|
break;
|
|
535
564
|
case 171:
|
|
536
|
-
this.errorLog(
|
|
565
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
537
566
|
this.offlineOff();
|
|
538
567
|
break;
|
|
539
568
|
case 190:
|
|
540
569
|
this.errorLog(
|
|
541
|
-
|
|
570
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
542
571
|
` Or command: ${JSON.stringify(push.data)} format is invalid`,
|
|
543
572
|
);
|
|
544
573
|
break;
|
|
545
574
|
case 100:
|
|
546
575
|
if (this.platform.debugMode) {
|
|
547
|
-
this.debugLog(
|
|
576
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
548
577
|
}
|
|
549
578
|
break;
|
|
550
579
|
default:
|
|
551
580
|
if (this.platform.debugMode) {
|
|
552
|
-
this.debugLog(
|
|
581
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
553
582
|
}
|
|
554
583
|
}
|
|
555
584
|
}
|
|
556
585
|
|
|
557
|
-
offlineOff() {
|
|
586
|
+
async offlineOff(): Promise<void> {
|
|
558
587
|
if (this.device.offline) {
|
|
559
588
|
this.On = false;
|
|
560
|
-
this.
|
|
589
|
+
this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
561
590
|
}
|
|
562
591
|
}
|
|
563
592
|
|
|
564
593
|
/**
|
|
565
594
|
* Handle requests to set the value of the "On" characteristic
|
|
566
595
|
*/
|
|
567
|
-
OnSet(value: CharacteristicValue) {
|
|
568
|
-
this.debugLog(
|
|
596
|
+
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
597
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${value}`);
|
|
569
598
|
|
|
570
599
|
this.On = value;
|
|
571
600
|
this.doColorBulbUpdate.next();
|
|
@@ -574,8 +603,8 @@ export class ColorBulb {
|
|
|
574
603
|
/**
|
|
575
604
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
576
605
|
*/
|
|
577
|
-
BrightnessSet(value: CharacteristicValue) {
|
|
578
|
-
this.debugLog(
|
|
606
|
+
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
607
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${value}`);
|
|
579
608
|
|
|
580
609
|
this.Brightness = value;
|
|
581
610
|
this.doColorBulbUpdate.next();
|
|
@@ -584,8 +613,8 @@ export class ColorBulb {
|
|
|
584
613
|
/**
|
|
585
614
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
586
615
|
*/
|
|
587
|
-
ColorTemperatureSet(value: CharacteristicValue) {
|
|
588
|
-
this.debugLog(
|
|
616
|
+
async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
617
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${value}`);
|
|
589
618
|
|
|
590
619
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
591
620
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
@@ -599,8 +628,8 @@ export class ColorBulb {
|
|
|
599
628
|
|
|
600
629
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
601
630
|
const hs = m2hs(value);
|
|
602
|
-
this.
|
|
603
|
-
this.
|
|
631
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
|
|
632
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
|
|
604
633
|
|
|
605
634
|
this.ColorTemperature = value;
|
|
606
635
|
this.doColorBulbUpdate.next();
|
|
@@ -609,10 +638,12 @@ export class ColorBulb {
|
|
|
609
638
|
/**
|
|
610
639
|
* Handle requests to set the value of the "Hue" characteristic
|
|
611
640
|
*/
|
|
612
|
-
HueSet(value: CharacteristicValue) {
|
|
613
|
-
this.debugLog(
|
|
641
|
+
async HueSet(value: CharacteristicValue): Promise<void> {
|
|
642
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${value}`);
|
|
614
643
|
|
|
615
|
-
|
|
644
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
645
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
646
|
+
}
|
|
616
647
|
|
|
617
648
|
this.Hue = value;
|
|
618
649
|
this.doColorBulbUpdate.next();
|
|
@@ -621,16 +652,28 @@ export class ColorBulb {
|
|
|
621
652
|
/**
|
|
622
653
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
623
654
|
*/
|
|
624
|
-
SaturationSet(value: CharacteristicValue) {
|
|
625
|
-
this.debugLog(
|
|
655
|
+
async SaturationSet(value: CharacteristicValue): Promise<void> {
|
|
656
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${value}`);
|
|
626
657
|
|
|
627
|
-
|
|
658
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
659
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
660
|
+
}
|
|
628
661
|
|
|
629
662
|
this.Saturation = value;
|
|
630
663
|
this.doColorBulbUpdate.next();
|
|
631
664
|
}
|
|
632
665
|
|
|
633
|
-
|
|
666
|
+
model(device: device & devicesConfig): string {
|
|
667
|
+
let model: string;
|
|
668
|
+
if (device.deviceType === 'Strip Light') {
|
|
669
|
+
model = 'W1701100';
|
|
670
|
+
} else {
|
|
671
|
+
model = 'W1401400';
|
|
672
|
+
}
|
|
673
|
+
return model;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
async config(device: device & devicesConfig): Promise<void> {
|
|
634
677
|
let config = {};
|
|
635
678
|
if (device.colorbulb) {
|
|
636
679
|
config = device.colorbulb;
|
|
@@ -651,43 +694,43 @@ export class ColorBulb {
|
|
|
651
694
|
config['offline'] = device.offline;
|
|
652
695
|
}
|
|
653
696
|
if (Object.entries(config).length !== 0) {
|
|
654
|
-
this.warnLog(
|
|
697
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
655
698
|
}
|
|
656
699
|
}
|
|
657
700
|
|
|
658
|
-
refreshRate(device: device & devicesConfig) {
|
|
701
|
+
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
659
702
|
if (device.refreshRate) {
|
|
660
703
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
661
|
-
this.debugLog(
|
|
704
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
662
705
|
} else if (this.platform.config.options!.refreshRate) {
|
|
663
706
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
664
|
-
this.debugLog(
|
|
707
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
665
708
|
}
|
|
666
709
|
}
|
|
667
710
|
|
|
668
|
-
logs(device: device & devicesConfig) {
|
|
711
|
+
async logs(device: device & devicesConfig): Promise<void> {
|
|
669
712
|
if (this.platform.debugMode) {
|
|
670
713
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
671
|
-
this.debugLog(
|
|
714
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
672
715
|
} else if (device.logging) {
|
|
673
716
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
674
|
-
this.debugLog(
|
|
717
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
675
718
|
} else if (this.platform.config.options?.logging) {
|
|
676
719
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
677
|
-
this.debugLog(
|
|
720
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
678
721
|
} else {
|
|
679
722
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
680
|
-
this.debugLog(
|
|
723
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
681
724
|
}
|
|
682
725
|
}
|
|
683
726
|
|
|
684
|
-
adaptiveLighting(device: device & devicesConfig) {
|
|
727
|
+
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
685
728
|
if (device.colorbulb?.adaptiveLightingShift) {
|
|
686
729
|
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
687
|
-
this.debugLog(
|
|
730
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
688
731
|
} else {
|
|
689
732
|
this.adaptiveLightingShift = 0;
|
|
690
|
-
this.debugLog(
|
|
733
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
691
734
|
}
|
|
692
735
|
}
|
|
693
736
|
|
|
@@ -703,25 +746,25 @@ export class ColorBulb {
|
|
|
703
746
|
/**
|
|
704
747
|
* Logging for Device
|
|
705
748
|
*/
|
|
706
|
-
infoLog(...log: any[]) {
|
|
749
|
+
infoLog(...log: any[]): void {
|
|
707
750
|
if (this.enablingDeviceLogging()) {
|
|
708
751
|
this.platform.log.info(String(...log));
|
|
709
752
|
}
|
|
710
753
|
}
|
|
711
754
|
|
|
712
|
-
warnLog(...log: any[]) {
|
|
755
|
+
warnLog(...log: any[]): void {
|
|
713
756
|
if (this.enablingDeviceLogging()) {
|
|
714
757
|
this.platform.log.warn(String(...log));
|
|
715
758
|
}
|
|
716
759
|
}
|
|
717
760
|
|
|
718
|
-
errorLog(...log: any[]) {
|
|
761
|
+
errorLog(...log: any[]): void {
|
|
719
762
|
if (this.enablingDeviceLogging()) {
|
|
720
763
|
this.platform.log.error(String(...log));
|
|
721
764
|
}
|
|
722
765
|
}
|
|
723
766
|
|
|
724
|
-
debugLog(...log: any[]) {
|
|
767
|
+
debugLog(...log: any[]): void {
|
|
725
768
|
if (this.enablingDeviceLogging()) {
|
|
726
769
|
if (this.deviceLogging === 'debug') {
|
|
727
770
|
this.platform.log.info('[DEBUG]', String(...log));
|