@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.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 +14 -0
- package/dist/device/blindtilt.js +103 -103
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +84 -84
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +97 -97
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +139 -139
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +47 -47
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +91 -89
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +12 -12
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +42 -42
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +95 -95
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +46 -46
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.js +84 -84
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +44 -44
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +118 -118
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +74 -74
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +44 -44
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +42 -42
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/meterpro.js +42 -42
- package/dist/device/meterpro.js.map +1 -1
- package/dist/device/motion.js +44 -44
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +59 -59
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +73 -73
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js +44 -44
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.js +31 -31
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js +10 -10
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js +9 -9
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.js +11 -11
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.js +11 -11
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.js +9 -9
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js +55 -55
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.js +33 -33
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.js +228 -228
- package/dist/platform.js.map +1 -1
- package/package.json +9 -9
- package/src/device/blindtilt.ts +103 -103
- package/src/device/bot.ts +84 -84
- package/src/device/ceilinglight.ts +97 -97
- package/src/device/colorbulb.ts +139 -139
- package/src/device/contact.ts +47 -47
- package/src/device/curtain.ts +91 -89
- package/src/device/device.ts +42 -42
- package/src/device/fan.ts +95 -95
- package/src/device/hub.ts +46 -46
- package/src/device/humidifier.ts +84 -84
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +118 -118
- package/src/device/lock.ts +74 -74
- package/src/device/meter.ts +44 -44
- package/src/device/meterplus.ts +42 -42
- package/src/device/meterpro.ts +42 -42
- package/src/device/motion.ts +44 -44
- package/src/device/plug.ts +61 -61
- package/src/device/robotvacuumcleaner.ts +73 -73
- package/src/device/waterdetector.ts +44 -44
- package/src/irdevice/airconditioner.ts +31 -31
- package/src/irdevice/airpurifier.ts +10 -10
- package/src/irdevice/camera.ts +9 -9
- package/src/irdevice/fan.ts +11 -11
- package/src/irdevice/irdevice.ts +11 -11
- package/src/irdevice/light.ts +9 -9
- package/src/irdevice/other.ts +55 -55
- package/src/irdevice/tv.ts +33 -33
- package/src/irdevice/vacuumcleaner.ts +9 -9
- package/src/irdevice/waterheater.ts +9 -9
- package/src/platform.ts +228 -228
package/dist/device/colorbulb.js
CHANGED
|
@@ -144,7 +144,7 @@ export class ColorBulb extends deviceBase {
|
|
|
144
144
|
}
|
|
145
145
|
catch (e) {
|
|
146
146
|
await this.apiError(e);
|
|
147
|
-
|
|
147
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
148
148
|
}
|
|
149
149
|
this.colorBulbUpdateInProgress = false;
|
|
150
150
|
});
|
|
@@ -153,59 +153,59 @@ export class ColorBulb extends deviceBase {
|
|
|
153
153
|
* Parse the device status from the SwitchBotBLE API
|
|
154
154
|
*/
|
|
155
155
|
async BLEparseStatus() {
|
|
156
|
-
|
|
156
|
+
this.debugLog('BLEparseStatus');
|
|
157
157
|
// On
|
|
158
158
|
this.LightBulb.On = this.serviceData.power;
|
|
159
|
-
|
|
159
|
+
this.debugLog(`On: ${this.LightBulb.On}`);
|
|
160
160
|
// Brightness
|
|
161
161
|
this.LightBulb.Brightness = this.serviceData.brightness;
|
|
162
|
-
|
|
162
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
163
163
|
// Color, Hue & Brightness
|
|
164
|
-
|
|
164
|
+
this.debugLog(`red: ${this.serviceData.red}, green: ${this.serviceData.green}, blue: ${this.serviceData.blue}`);
|
|
165
165
|
const [hue, saturation] = rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue);
|
|
166
|
-
|
|
166
|
+
this.debugLog(`hs: ${JSON.stringify(rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue))}`);
|
|
167
167
|
// Hue
|
|
168
168
|
this.LightBulb.Hue = hue;
|
|
169
|
-
|
|
169
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}`);
|
|
170
170
|
// Saturation
|
|
171
171
|
this.LightBulb.Saturation = saturation;
|
|
172
|
-
|
|
172
|
+
this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
173
173
|
// ColorTemperature
|
|
174
174
|
const miredColorTemperature = Math.round(1000000 / this.serviceData.color_temperature);
|
|
175
175
|
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
|
|
176
|
-
|
|
176
|
+
this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* Parse the device status from the SwitchBot OpenAPI
|
|
180
180
|
*/
|
|
181
181
|
async openAPIparseStatus() {
|
|
182
|
-
|
|
182
|
+
this.debugLog('openAPIparseStatus');
|
|
183
183
|
// On
|
|
184
184
|
this.LightBulb.On = this.deviceStatus.power === 'on';
|
|
185
|
-
|
|
185
|
+
this.debugLog(`On: ${this.LightBulb.On}`);
|
|
186
186
|
// Brightness
|
|
187
187
|
this.LightBulb.Brightness = this.deviceStatus.brightness;
|
|
188
|
-
|
|
188
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
189
189
|
// Color, Hue & Brightness
|
|
190
|
-
|
|
190
|
+
this.debugLog(`color: ${JSON.stringify(this.deviceStatus.color)}`);
|
|
191
191
|
const [red, green, blue] = this.deviceStatus.color.split(':');
|
|
192
|
-
|
|
192
|
+
this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
|
|
193
193
|
const [hue, saturation] = rgb2hs(red, green, blue);
|
|
194
|
-
|
|
194
|
+
this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
|
|
195
195
|
// Hue
|
|
196
196
|
this.LightBulb.Hue = hue;
|
|
197
|
-
|
|
197
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}`);
|
|
198
198
|
// Saturation
|
|
199
199
|
this.LightBulb.Saturation = saturation;
|
|
200
|
-
|
|
200
|
+
this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
201
201
|
// ColorTemperature
|
|
202
202
|
const miredColorTemperature = Math.round(1000000 / this.deviceStatus.colorTemperature);
|
|
203
203
|
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
|
|
204
|
-
|
|
204
|
+
this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
205
205
|
// Firmware Version
|
|
206
206
|
if (this.deviceStatus.version) {
|
|
207
207
|
const version = this.deviceStatus.version.toString();
|
|
208
|
-
|
|
208
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
209
209
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
210
210
|
this.accessory
|
|
211
211
|
.getService(this.hap.Service.AccessoryInformation)
|
|
@@ -214,41 +214,41 @@ export class ColorBulb extends deviceBase {
|
|
|
214
214
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
215
215
|
.updateValue(deviceVersion);
|
|
216
216
|
this.accessory.context.version = deviceVersion;
|
|
217
|
-
|
|
217
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`);
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
async parseStatusWebhook() {
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
this.debugLog('parseStatusWebhook');
|
|
222
|
+
this.debugLog(`(powerState, brightness, color, colorTemperature) = Webhook:(${this.webhookContext.powerState}, ${this.webhookContext.brightness}, ${this.webhookContext.color}, ${this.webhookContext.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation}, ${this.LightBulb.ColorTemperature})`);
|
|
223
223
|
// On
|
|
224
224
|
this.LightBulb.On = this.webhookContext.powerState === 'ON';
|
|
225
|
-
|
|
225
|
+
this.debugLog(`On: ${this.LightBulb.On}`);
|
|
226
226
|
// Brightness
|
|
227
227
|
this.LightBulb.Brightness = this.webhookContext.brightness;
|
|
228
|
-
|
|
228
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
229
229
|
// Color, Hue & Brightness
|
|
230
|
-
|
|
230
|
+
this.debugLog(`color: ${JSON.stringify(this.webhookContext.color)}`);
|
|
231
231
|
const [red, green, blue] = this.webhookContext.color.split(':');
|
|
232
|
-
|
|
232
|
+
this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
|
|
233
233
|
const [hue, saturation] = rgb2hs(red, green, blue);
|
|
234
|
-
|
|
234
|
+
this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
|
|
235
235
|
// Hue
|
|
236
236
|
this.LightBulb.Hue = hue;
|
|
237
|
-
|
|
237
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}`);
|
|
238
238
|
// Saturation
|
|
239
239
|
this.LightBulb.Saturation = saturation;
|
|
240
|
-
|
|
240
|
+
this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
241
241
|
// ColorTemperature
|
|
242
242
|
const miredColorTemperature = Math.round(1000000 / this.webhookContext.colorTemperature);
|
|
243
243
|
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
|
|
244
|
-
|
|
244
|
+
this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
245
245
|
}
|
|
246
246
|
/**
|
|
247
247
|
* Asks the SwitchBot API for the latest device information
|
|
248
248
|
*/
|
|
249
249
|
async refreshStatus() {
|
|
250
250
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
251
|
-
|
|
251
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
252
252
|
}
|
|
253
253
|
else if (this.BLE) {
|
|
254
254
|
await this.BLERefreshStatus();
|
|
@@ -258,11 +258,11 @@ export class ColorBulb extends deviceBase {
|
|
|
258
258
|
}
|
|
259
259
|
else {
|
|
260
260
|
await this.offlineOff();
|
|
261
|
-
|
|
261
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
async BLERefreshStatus() {
|
|
265
|
-
|
|
265
|
+
this.debugLog('BLERefreshStatus');
|
|
266
266
|
const switchBotBLE = await this.switchbotBLE();
|
|
267
267
|
if (switchBotBLE === undefined) {
|
|
268
268
|
await this.BLERefreshConnection(switchBotBLE);
|
|
@@ -279,79 +279,79 @@ export class ColorBulb extends deviceBase {
|
|
|
279
279
|
await this.updateHomeKitCharacteristics();
|
|
280
280
|
}
|
|
281
281
|
else {
|
|
282
|
-
|
|
282
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`);
|
|
283
283
|
await this.BLERefreshConnection(switchBotBLE);
|
|
284
284
|
}
|
|
285
285
|
})();
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
async registerPlatformBLE() {
|
|
289
|
-
|
|
289
|
+
this.debugLog('registerPlatformBLE');
|
|
290
290
|
if (this.config.options?.BLE) {
|
|
291
|
-
|
|
291
|
+
this.debugLog('is listening to Platform BLE.');
|
|
292
292
|
try {
|
|
293
293
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
294
294
|
this.device.bleMac = formattedDeviceId;
|
|
295
|
-
|
|
295
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
296
296
|
this.platform.bleEventHandler[this.device.bleMac] = async (context) => {
|
|
297
297
|
try {
|
|
298
|
-
|
|
298
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
299
299
|
this.serviceData = context;
|
|
300
300
|
await this.BLEparseStatus();
|
|
301
301
|
await this.updateHomeKitCharacteristics();
|
|
302
302
|
}
|
|
303
303
|
catch (e) {
|
|
304
|
-
|
|
304
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
305
305
|
}
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
308
|
catch (error) {
|
|
309
|
-
|
|
309
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
else {
|
|
313
|
-
|
|
313
|
+
this.debugLog('is not listening to Platform BLE');
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
async openAPIRefreshStatus() {
|
|
317
|
-
|
|
317
|
+
this.debugLog('openAPIRefreshStatus');
|
|
318
318
|
try {
|
|
319
|
-
const
|
|
320
|
-
const deviceStatus =
|
|
321
|
-
|
|
319
|
+
const response = await this.deviceRefreshStatus();
|
|
320
|
+
const deviceStatus = response.body;
|
|
321
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
322
322
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
323
|
-
|
|
323
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
324
324
|
this.deviceStatus = deviceStatus.body;
|
|
325
325
|
await this.openAPIparseStatus();
|
|
326
326
|
await this.updateHomeKitCharacteristics();
|
|
327
327
|
}
|
|
328
328
|
else {
|
|
329
|
-
|
|
330
|
-
|
|
329
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
330
|
+
this.debugWarnLog(deviceStatus);
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
catch (e) {
|
|
334
334
|
await this.apiError(e);
|
|
335
|
-
|
|
335
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
async registerWebhook() {
|
|
339
339
|
if (this.device.webhook) {
|
|
340
|
-
|
|
340
|
+
this.debugLog('is listening webhook.');
|
|
341
341
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
342
342
|
try {
|
|
343
|
-
|
|
343
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
344
344
|
this.webhookContext = context;
|
|
345
345
|
await this.parseStatusWebhook();
|
|
346
346
|
await this.updateHomeKitCharacteristics();
|
|
347
347
|
}
|
|
348
348
|
catch (e) {
|
|
349
|
-
|
|
349
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
350
350
|
}
|
|
351
351
|
};
|
|
352
352
|
}
|
|
353
353
|
else {
|
|
354
|
-
|
|
354
|
+
this.debugLog('is not listening webhook.');
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
/**
|
|
@@ -367,45 +367,45 @@ export class ColorBulb extends deviceBase {
|
|
|
367
367
|
*/
|
|
368
368
|
async pushChanges() {
|
|
369
369
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
370
|
-
|
|
370
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
371
371
|
}
|
|
372
372
|
else if (this.BLE) {
|
|
373
373
|
await this.BLEpushChanges();
|
|
374
374
|
if (this.LightBulb.On) {
|
|
375
375
|
// Push Brightness Update
|
|
376
|
-
|
|
376
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
377
377
|
await this.BLEpushBrightnessChanges();
|
|
378
378
|
// Push ColorTemperature Update
|
|
379
|
-
|
|
379
|
+
this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
380
380
|
await this.BLEpushColorTemperatureChanges();
|
|
381
381
|
// Push Hue & Saturation Update
|
|
382
|
-
|
|
382
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
|
|
383
383
|
await this.BLEpushRGBChanges();
|
|
384
384
|
}
|
|
385
385
|
else {
|
|
386
|
-
|
|
386
|
+
this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
|
|
387
387
|
}
|
|
388
388
|
}
|
|
389
389
|
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
390
390
|
await this.openAPIpushChanges();
|
|
391
391
|
if (this.LightBulb.On) {
|
|
392
392
|
// Push Brightness Update
|
|
393
|
-
|
|
393
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
394
394
|
await this.pushBrightnessChanges();
|
|
395
395
|
// Push ColorTemperature Update
|
|
396
|
-
|
|
396
|
+
this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
397
397
|
await this.pushColorTemperatureChanges();
|
|
398
398
|
// Push Hue & Saturation Update
|
|
399
|
-
|
|
399
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
|
|
400
400
|
await this.pushHueSaturationChanges();
|
|
401
401
|
}
|
|
402
402
|
else {
|
|
403
|
-
|
|
403
|
+
this.debugLog('openAPI (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
else {
|
|
407
407
|
await this.offlineOff();
|
|
408
|
-
|
|
408
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
409
409
|
}
|
|
410
410
|
// Refresh the status from the API
|
|
411
411
|
interval(15000)
|
|
@@ -416,19 +416,19 @@ export class ColorBulb extends deviceBase {
|
|
|
416
416
|
});
|
|
417
417
|
}
|
|
418
418
|
async BLEpushChanges() {
|
|
419
|
-
|
|
419
|
+
this.debugLog('BLEpushChanges');
|
|
420
420
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
421
|
-
|
|
421
|
+
this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
422
422
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device);
|
|
423
423
|
try {
|
|
424
424
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
425
425
|
this.device.bleMac = formattedDeviceId;
|
|
426
|
-
|
|
426
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
427
427
|
if (switchBotBLE !== false) {
|
|
428
428
|
switchBotBLE
|
|
429
429
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
430
430
|
.then(async (device_list) => {
|
|
431
|
-
|
|
431
|
+
this.infoLog(`On: ${this.LightBulb.On}`);
|
|
432
432
|
return await this.retryBLE({
|
|
433
433
|
max: await this.maxRetryBLE(),
|
|
434
434
|
fn: async () => {
|
|
@@ -442,69 +442,69 @@ export class ColorBulb extends deviceBase {
|
|
|
442
442
|
});
|
|
443
443
|
})
|
|
444
444
|
.then(async () => {
|
|
445
|
-
|
|
445
|
+
this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
|
|
446
446
|
await this.updateHomeKitCharacteristics();
|
|
447
447
|
})
|
|
448
448
|
.catch(async (e) => {
|
|
449
449
|
await this.apiError(e);
|
|
450
|
-
|
|
450
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
451
451
|
await this.BLEPushConnection();
|
|
452
452
|
});
|
|
453
453
|
}
|
|
454
454
|
else {
|
|
455
|
-
|
|
455
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
|
|
456
456
|
await this.BLEPushConnection();
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
459
|
catch (error) {
|
|
460
|
-
|
|
460
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
461
461
|
}
|
|
462
462
|
}
|
|
463
463
|
else {
|
|
464
|
-
|
|
464
|
+
this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
467
|
async BLEpushBrightnessChanges() {
|
|
468
|
-
|
|
468
|
+
this.debugLog('BLEpushBrightnessChanges');
|
|
469
469
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
470
470
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device);
|
|
471
471
|
try {
|
|
472
472
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
473
473
|
this.device.bleMac = formattedDeviceId;
|
|
474
|
-
|
|
474
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
475
475
|
if (switchBotBLE !== false) {
|
|
476
476
|
switchBotBLE
|
|
477
477
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
478
478
|
.then(async (device_list) => {
|
|
479
479
|
const deviceList = device_list;
|
|
480
|
-
|
|
480
|
+
this.infoLog(`Target Brightness: ${this.LightBulb.Brightness}`);
|
|
481
481
|
return await deviceList[0].setBrightness(Number(this.LightBulb.Brightness));
|
|
482
482
|
})
|
|
483
483
|
.then(async () => {
|
|
484
|
-
|
|
484
|
+
this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`);
|
|
485
485
|
await this.updateHomeKitCharacteristics();
|
|
486
486
|
})
|
|
487
487
|
.catch(async (e) => {
|
|
488
488
|
await this.apiError(e);
|
|
489
|
-
|
|
489
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
490
490
|
await this.BLEPushConnection();
|
|
491
491
|
});
|
|
492
492
|
}
|
|
493
493
|
else {
|
|
494
|
-
|
|
494
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
|
|
495
495
|
await this.BLEPushConnection();
|
|
496
496
|
}
|
|
497
497
|
}
|
|
498
498
|
catch (error) {
|
|
499
|
-
|
|
499
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
502
|
else {
|
|
503
|
-
|
|
503
|
+
this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
504
504
|
}
|
|
505
505
|
}
|
|
506
506
|
async BLEpushColorTemperatureChanges() {
|
|
507
|
-
|
|
507
|
+
this.debugLog('BLEpushColorTemperatureChanges');
|
|
508
508
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
509
509
|
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
|
|
510
510
|
this.accessory.context.kelvin = kelvin;
|
|
@@ -512,82 +512,82 @@ export class ColorBulb extends deviceBase {
|
|
|
512
512
|
try {
|
|
513
513
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
514
514
|
this.device.bleMac = formattedDeviceId;
|
|
515
|
-
|
|
515
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
516
516
|
if (switchBotBLE !== false) {
|
|
517
517
|
switchBotBLE
|
|
518
518
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
519
519
|
.then(async (device_list) => {
|
|
520
520
|
const deviceList = device_list;
|
|
521
|
-
|
|
521
|
+
this.infoLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
522
522
|
return await deviceList[0].setColorTemperature(kelvin);
|
|
523
523
|
})
|
|
524
524
|
.then(async () => {
|
|
525
|
-
|
|
525
|
+
this.successLog(`ColorTemperature: ${this.LightBulb.ColorTemperature} sent over SwitchBot BLE, sent successfully`);
|
|
526
526
|
await this.updateHomeKitCharacteristics();
|
|
527
527
|
})
|
|
528
528
|
.catch(async (e) => {
|
|
529
529
|
await this.apiError(e);
|
|
530
|
-
|
|
530
|
+
this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
531
531
|
await this.BLEPushConnection();
|
|
532
532
|
});
|
|
533
533
|
}
|
|
534
534
|
else {
|
|
535
|
-
|
|
535
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
|
|
536
536
|
await this.BLEPushConnection();
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
catch (error) {
|
|
540
|
-
|
|
540
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
541
541
|
}
|
|
542
542
|
}
|
|
543
543
|
else {
|
|
544
|
-
|
|
544
|
+
this.debugLog(`No changes (BLEpushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
545
545
|
}
|
|
546
546
|
}
|
|
547
547
|
async BLEpushRGBChanges() {
|
|
548
|
-
|
|
548
|
+
this.debugLog('BLEpushRGBChanges');
|
|
549
549
|
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
550
|
-
|
|
550
|
+
this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
551
551
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation);
|
|
552
|
-
|
|
552
|
+
this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
|
|
553
553
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device);
|
|
554
554
|
try {
|
|
555
555
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
556
556
|
this.device.bleMac = formattedDeviceId;
|
|
557
|
-
|
|
557
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
558
558
|
if (switchBotBLE !== false) {
|
|
559
559
|
switchBotBLE
|
|
560
560
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
561
561
|
.then(async (device_list) => {
|
|
562
562
|
const deviceList = device_list;
|
|
563
|
-
|
|
563
|
+
this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`);
|
|
564
564
|
return await deviceList[0].setRGB(Number(this.LightBulb.Brightness), red, green, blue);
|
|
565
565
|
})
|
|
566
566
|
.then(async () => {
|
|
567
|
-
|
|
567
|
+
this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`);
|
|
568
568
|
await this.updateHomeKitCharacteristics();
|
|
569
569
|
})
|
|
570
570
|
.catch(async (e) => {
|
|
571
571
|
await this.apiError(e);
|
|
572
|
-
|
|
572
|
+
this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
573
573
|
await this.BLEPushConnection();
|
|
574
574
|
});
|
|
575
575
|
}
|
|
576
576
|
else {
|
|
577
|
-
|
|
577
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
|
|
578
578
|
await this.BLEPushConnection();
|
|
579
579
|
}
|
|
580
580
|
}
|
|
581
581
|
catch (error) {
|
|
582
|
-
|
|
582
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
585
|
else {
|
|
586
|
-
|
|
586
|
+
this.debugLog(`No changes (BLEpushRGBChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
587
587
|
}
|
|
588
588
|
}
|
|
589
589
|
async openAPIpushChanges() {
|
|
590
|
-
|
|
590
|
+
this.debugLog('openAPIpushChanges');
|
|
591
591
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
592
592
|
const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
|
|
593
593
|
const bodyChange = {
|
|
@@ -595,13 +595,13 @@ export class ColorBulb extends deviceBase {
|
|
|
595
595
|
parameter: 'default',
|
|
596
596
|
commandType: 'command',
|
|
597
597
|
};
|
|
598
|
-
|
|
598
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
599
599
|
try {
|
|
600
|
-
const
|
|
601
|
-
const deviceStatus =
|
|
602
|
-
|
|
600
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
601
|
+
const deviceStatus = response.body;
|
|
602
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
603
603
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
604
|
-
|
|
604
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
605
605
|
await this.updateHomeKitCharacteristics();
|
|
606
606
|
}
|
|
607
607
|
else {
|
|
@@ -610,31 +610,31 @@ export class ColorBulb extends deviceBase {
|
|
|
610
610
|
}
|
|
611
611
|
catch (e) {
|
|
612
612
|
await this.apiError(e);
|
|
613
|
-
|
|
613
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
614
614
|
}
|
|
615
615
|
}
|
|
616
616
|
else {
|
|
617
|
-
|
|
617
|
+
this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
618
618
|
}
|
|
619
619
|
}
|
|
620
620
|
async pushHueSaturationChanges() {
|
|
621
|
-
|
|
621
|
+
this.debugLog('pushHueSaturationChanges');
|
|
622
622
|
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
623
|
-
|
|
623
|
+
this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
624
624
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation);
|
|
625
|
-
|
|
625
|
+
this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
|
|
626
626
|
const bodyChange = {
|
|
627
627
|
command: 'setColor',
|
|
628
628
|
parameter: `${red}:${green}:${blue}`,
|
|
629
629
|
commandType: 'command',
|
|
630
630
|
};
|
|
631
|
-
|
|
631
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
632
632
|
try {
|
|
633
|
-
const
|
|
634
|
-
const deviceStatus =
|
|
635
|
-
|
|
633
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
634
|
+
const deviceStatus = response.body;
|
|
635
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
636
636
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
637
|
-
|
|
637
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
638
638
|
await this.updateHomeKitCharacteristics();
|
|
639
639
|
}
|
|
640
640
|
else {
|
|
@@ -643,15 +643,15 @@ export class ColorBulb extends deviceBase {
|
|
|
643
643
|
}
|
|
644
644
|
catch (e) {
|
|
645
645
|
await this.apiError(e);
|
|
646
|
-
|
|
646
|
+
this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
649
|
else {
|
|
650
|
-
|
|
650
|
+
this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
651
651
|
}
|
|
652
652
|
}
|
|
653
653
|
async pushColorTemperatureChanges() {
|
|
654
|
-
|
|
654
|
+
this.debugLog('pushColorTemperatureChanges');
|
|
655
655
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
656
656
|
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
|
|
657
657
|
this.accessory.context.kelvin = kelvin;
|
|
@@ -660,13 +660,13 @@ export class ColorBulb extends deviceBase {
|
|
|
660
660
|
parameter: `${kelvin}`,
|
|
661
661
|
commandType: 'command',
|
|
662
662
|
};
|
|
663
|
-
|
|
663
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
664
664
|
try {
|
|
665
|
-
const
|
|
666
|
-
const deviceStatus =
|
|
667
|
-
|
|
665
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
666
|
+
const deviceStatus = response.body;
|
|
667
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
668
668
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
669
|
-
|
|
669
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
670
670
|
await this.updateHomeKitCharacteristics();
|
|
671
671
|
}
|
|
672
672
|
else {
|
|
@@ -675,28 +675,28 @@ export class ColorBulb extends deviceBase {
|
|
|
675
675
|
}
|
|
676
676
|
catch (e) {
|
|
677
677
|
await this.apiError(e);
|
|
678
|
-
|
|
678
|
+
this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
679
679
|
}
|
|
680
680
|
}
|
|
681
681
|
else {
|
|
682
|
-
|
|
682
|
+
this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
683
683
|
}
|
|
684
684
|
}
|
|
685
685
|
async pushBrightnessChanges() {
|
|
686
|
-
|
|
686
|
+
this.debugLog('pushBrightnessChanges');
|
|
687
687
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
688
688
|
const bodyChange = {
|
|
689
689
|
command: 'setBrightness',
|
|
690
690
|
parameter: `${this.LightBulb.Brightness}`,
|
|
691
691
|
commandType: 'command',
|
|
692
692
|
};
|
|
693
|
-
|
|
693
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
694
694
|
try {
|
|
695
|
-
const
|
|
696
|
-
const deviceStatus =
|
|
697
|
-
|
|
695
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
696
|
+
const deviceStatus = response.body;
|
|
697
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
698
698
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
699
|
-
|
|
699
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
700
700
|
await this.updateHomeKitCharacteristics();
|
|
701
701
|
}
|
|
702
702
|
else {
|
|
@@ -705,11 +705,11 @@ export class ColorBulb extends deviceBase {
|
|
|
705
705
|
}
|
|
706
706
|
catch (e) {
|
|
707
707
|
await this.apiError(e);
|
|
708
|
-
|
|
708
|
+
this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
709
709
|
}
|
|
710
710
|
}
|
|
711
711
|
else {
|
|
712
|
-
|
|
712
|
+
this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
713
713
|
}
|
|
714
714
|
}
|
|
715
715
|
/**
|
|
@@ -717,10 +717,10 @@ export class ColorBulb extends deviceBase {
|
|
|
717
717
|
*/
|
|
718
718
|
async OnSet(value) {
|
|
719
719
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
720
|
-
|
|
720
|
+
this.infoLog(`Set On: ${value}`);
|
|
721
721
|
}
|
|
722
722
|
else {
|
|
723
|
-
|
|
723
|
+
this.debugLog(`No Changes, On: ${value}`);
|
|
724
724
|
}
|
|
725
725
|
this.LightBulb.On = value;
|
|
726
726
|
this.doColorBulbUpdate.next();
|
|
@@ -730,7 +730,7 @@ export class ColorBulb extends deviceBase {
|
|
|
730
730
|
*/
|
|
731
731
|
async BrightnessSet(value) {
|
|
732
732
|
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
733
|
-
|
|
733
|
+
this.infoLog(`Set Brightness: ${value}`);
|
|
734
734
|
}
|
|
735
735
|
else {
|
|
736
736
|
if (this.LightBulb.On) {
|
|
@@ -827,21 +827,21 @@ export class ColorBulb extends deviceBase {
|
|
|
827
827
|
async getAdaptiveLightingSettings(accessory, device) {
|
|
828
828
|
// Adaptive Lighting
|
|
829
829
|
this.adaptiveLighting = accessory.context.adaptiveLighting ?? true;
|
|
830
|
-
|
|
830
|
+
this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`);
|
|
831
831
|
// Adaptive Lighting Shift
|
|
832
832
|
this.adaptiveLightingShift = device.adaptiveLightingShift ?? 0;
|
|
833
833
|
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
834
834
|
}
|
|
835
835
|
async BLEPushConnection() {
|
|
836
836
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
837
|
-
|
|
837
|
+
this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
838
838
|
await this.openAPIpushChanges();
|
|
839
839
|
}
|
|
840
840
|
}
|
|
841
841
|
async BLERefreshConnection(switchbot) {
|
|
842
|
-
|
|
842
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
843
843
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
844
|
-
|
|
844
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
845
845
|
await this.openAPIRefreshStatus();
|
|
846
846
|
}
|
|
847
847
|
}
|