@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
|
@@ -148,24 +148,24 @@ export class StripLight extends deviceBase {
|
|
|
148
148
|
}
|
|
149
149
|
catch (e) {
|
|
150
150
|
await this.apiError(e);
|
|
151
|
-
|
|
151
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
152
152
|
}
|
|
153
153
|
this.stripLightUpdateInProgress = false;
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
async BLEparseStatus() {
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
this.debugLog('BLEparseStatus');
|
|
158
|
+
this.debugLog(`(power, brightness, color) = BLE:(${this.serviceData.power}, ${this.serviceData.brightness}, ${this.serviceData.red}:${this.serviceData.green}:${this.serviceData.blue}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation})`);
|
|
159
159
|
// On
|
|
160
160
|
this.LightBulb.On = this.serviceData.power;
|
|
161
|
-
|
|
161
|
+
this.debugLog(`On: ${this.LightBulb.On}`);
|
|
162
162
|
// Brightness
|
|
163
163
|
this.LightBulb.Brightness = this.serviceData.brightness;
|
|
164
|
-
|
|
164
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
165
165
|
// Color, Hue & Brightness
|
|
166
|
-
|
|
166
|
+
this.debugLog(`red: ${this.serviceData.red}, green: ${this.serviceData.green}, blue: ${this.serviceData.blue}`);
|
|
167
167
|
const [hue, saturation] = rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue);
|
|
168
|
-
|
|
168
|
+
this.debugLog(`hs: ${JSON.stringify(rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue))}`);
|
|
169
169
|
// Hue
|
|
170
170
|
this.LightBulb.Hue = hue;
|
|
171
171
|
this.debugLog(`Hue: ${this.LightBulb.Hue}`);
|
|
@@ -174,30 +174,30 @@ export class StripLight extends deviceBase {
|
|
|
174
174
|
this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
175
175
|
}
|
|
176
176
|
async openAPIparseStatus() {
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
this.debugLog('openAPIparseStatus');
|
|
178
|
+
this.debugLog(`(power, brightness, color) = API:(${this.deviceStatus.power}, ${this.deviceStatus.brightness}, ${this.deviceStatus.color}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation})`);
|
|
179
179
|
// On
|
|
180
180
|
this.LightBulb.On = this.deviceStatus.power === 'on';
|
|
181
|
-
|
|
181
|
+
this.debugLog(`On: ${this.LightBulb.On}`);
|
|
182
182
|
// Brightness
|
|
183
183
|
this.LightBulb.Brightness = this.deviceStatus.brightness;
|
|
184
|
-
|
|
184
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
185
185
|
// Color, Hue & Brightness
|
|
186
|
-
|
|
186
|
+
this.debugLog(`color: ${JSON.stringify(this.deviceStatus.color)}`);
|
|
187
187
|
const [red, green, blue] = this.deviceStatus.color.split(':');
|
|
188
|
-
|
|
188
|
+
this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
|
|
189
189
|
const [hue, saturation] = rgb2hs(red, green, blue);
|
|
190
|
-
|
|
190
|
+
this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
|
|
191
191
|
// Hue
|
|
192
192
|
this.LightBulb.Hue = hue;
|
|
193
|
-
|
|
193
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}`);
|
|
194
194
|
// Saturation
|
|
195
195
|
this.LightBulb.Saturation = saturation;
|
|
196
|
-
|
|
196
|
+
this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
197
197
|
// Firmware Version
|
|
198
198
|
if (this.deviceStatus.version) {
|
|
199
199
|
const version = this.deviceStatus.version.toString();
|
|
200
|
-
|
|
200
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
201
201
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
202
202
|
this.accessory
|
|
203
203
|
.getService(this.hap.Service.AccessoryInformation)
|
|
@@ -206,37 +206,37 @@ export class StripLight extends deviceBase {
|
|
|
206
206
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
207
207
|
.updateValue(deviceVersion);
|
|
208
208
|
this.accessory.context.version = deviceVersion;
|
|
209
|
-
|
|
209
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
async parseStatusWebhook() {
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
this.debugLog('parseStatusWebhook');
|
|
214
|
+
this.debugLog(`(powerState, brightness, color) = Webhook:(${this.webhookContext.powerState}, ${this.webhookContext.brightness}, ${this.webhookContext.color}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue}, ${this.LightBulb.Saturation})`);
|
|
215
215
|
// On
|
|
216
216
|
this.LightBulb.On = this.webhookContext.powerState === 'ON';
|
|
217
|
-
|
|
217
|
+
this.debugLog(`On: ${this.LightBulb.On}`);
|
|
218
218
|
// Brightness
|
|
219
219
|
this.LightBulb.Brightness = this.webhookContext.brightness;
|
|
220
|
-
|
|
220
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
221
221
|
// Color, Hue & Brightness
|
|
222
|
-
|
|
222
|
+
this.debugLog(`color: ${JSON.stringify(this.webhookContext.color)}`);
|
|
223
223
|
const [red, green, blue] = this.webhookContext.color.split(':');
|
|
224
|
-
|
|
224
|
+
this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
|
|
225
225
|
const [hue, saturation] = rgb2hs(red, green, blue);
|
|
226
|
-
|
|
226
|
+
this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
|
|
227
227
|
// Hue
|
|
228
228
|
this.LightBulb.Hue = hue;
|
|
229
|
-
|
|
229
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}`);
|
|
230
230
|
// Saturation
|
|
231
231
|
this.LightBulb.Saturation = saturation;
|
|
232
|
-
|
|
232
|
+
this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
235
235
|
* Asks the SwitchBot API for the latest device information
|
|
236
236
|
*/
|
|
237
237
|
async refreshStatus() {
|
|
238
238
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
239
|
-
|
|
239
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
240
240
|
}
|
|
241
241
|
else if (this.BLE) {
|
|
242
242
|
await this.BLERefreshStatus();
|
|
@@ -246,11 +246,11 @@ export class StripLight extends deviceBase {
|
|
|
246
246
|
}
|
|
247
247
|
else {
|
|
248
248
|
await this.offlineOff();
|
|
249
|
-
|
|
249
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
async BLERefreshStatus() {
|
|
253
|
-
|
|
253
|
+
this.debugLog('BLERefreshStatus');
|
|
254
254
|
const switchBotBLE = await this.switchbotBLE();
|
|
255
255
|
if (switchBotBLE === undefined) {
|
|
256
256
|
await this.BLERefreshConnection(switchBotBLE);
|
|
@@ -267,79 +267,79 @@ export class StripLight extends deviceBase {
|
|
|
267
267
|
await this.updateHomeKitCharacteristics();
|
|
268
268
|
}
|
|
269
269
|
else {
|
|
270
|
-
|
|
270
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`);
|
|
271
271
|
await this.BLERefreshConnection(switchBotBLE);
|
|
272
272
|
}
|
|
273
273
|
})();
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
async registerPlatformBLE() {
|
|
277
|
-
|
|
277
|
+
this.debugLog('registerPlatformBLE');
|
|
278
278
|
if (this.config.options?.BLE) {
|
|
279
|
-
|
|
279
|
+
this.debugLog('is listening to Platform BLE.');
|
|
280
280
|
try {
|
|
281
281
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
282
282
|
this.device.bleMac = formattedDeviceId;
|
|
283
|
-
|
|
283
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
284
284
|
this.platform.bleEventHandler[this.device.bleMac] = async (context) => {
|
|
285
285
|
try {
|
|
286
|
-
|
|
286
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
287
287
|
this.serviceData = context;
|
|
288
288
|
await this.BLEparseStatus();
|
|
289
289
|
await this.updateHomeKitCharacteristics();
|
|
290
290
|
}
|
|
291
291
|
catch (e) {
|
|
292
|
-
|
|
292
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
293
293
|
}
|
|
294
294
|
};
|
|
295
295
|
}
|
|
296
296
|
catch (error) {
|
|
297
|
-
|
|
297
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
else {
|
|
301
|
-
|
|
301
|
+
this.debugLog('is not listening to Platform BLE');
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
async openAPIRefreshStatus() {
|
|
305
|
-
|
|
305
|
+
this.debugLog('openAPIRefreshStatus');
|
|
306
306
|
try {
|
|
307
|
-
const
|
|
308
|
-
const deviceStatus =
|
|
309
|
-
|
|
307
|
+
const response = await this.deviceRefreshStatus();
|
|
308
|
+
const deviceStatus = response.body;
|
|
309
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
310
310
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
311
|
-
|
|
311
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
312
312
|
this.deviceStatus = deviceStatus.body;
|
|
313
313
|
await this.openAPIparseStatus();
|
|
314
314
|
await this.updateHomeKitCharacteristics();
|
|
315
315
|
}
|
|
316
316
|
else {
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
318
|
+
this.debugWarnLog(deviceStatus);
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
catch (e) {
|
|
322
322
|
await this.apiError(e);
|
|
323
|
-
|
|
323
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
async registerWebhook() {
|
|
327
327
|
if (this.device.webhook) {
|
|
328
|
-
|
|
328
|
+
this.debugLog('is listening webhook.');
|
|
329
329
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
330
330
|
try {
|
|
331
|
-
|
|
331
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
332
332
|
this.webhookContext = context;
|
|
333
333
|
await this.parseStatusWebhook();
|
|
334
334
|
await this.updateHomeKitCharacteristics();
|
|
335
335
|
}
|
|
336
336
|
catch (e) {
|
|
337
|
-
|
|
337
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
338
338
|
}
|
|
339
339
|
};
|
|
340
340
|
}
|
|
341
341
|
else {
|
|
342
|
-
|
|
342
|
+
this.debugLog('is not listening webhook.');
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
/**
|
|
@@ -360,10 +360,10 @@ export class StripLight extends deviceBase {
|
|
|
360
360
|
await this.BLEpushChanges();
|
|
361
361
|
if (this.LightBulb.On) {
|
|
362
362
|
// Push Brightness Update
|
|
363
|
-
|
|
363
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
364
364
|
await this.BLEpushBrightnessChanges();
|
|
365
365
|
// Push Hue & Saturation Update
|
|
366
|
-
|
|
366
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
|
|
367
367
|
await this.BLEpushRGBChanges();
|
|
368
368
|
// Set ColorTemperature
|
|
369
369
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
@@ -371,30 +371,30 @@ export class StripLight extends deviceBase {
|
|
|
371
371
|
this.accessory.context.kelvin = kelvin;
|
|
372
372
|
}
|
|
373
373
|
else {
|
|
374
|
-
|
|
374
|
+
this.debugLog(`No pushColorTemperatureChanges, ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
377
|
else {
|
|
378
|
-
|
|
378
|
+
this.debugLog('BLE (Brightness), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
382
382
|
await this.openAPIpushChanges();
|
|
383
383
|
if (this.LightBulb.On) {
|
|
384
384
|
// Push Brightness Update
|
|
385
|
-
|
|
385
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
386
386
|
await this.pushBrightnessChanges();
|
|
387
387
|
// Push Hue & Saturation Update
|
|
388
|
-
|
|
388
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
|
|
389
389
|
await this.pushHueSaturationChanges();
|
|
390
390
|
}
|
|
391
391
|
else {
|
|
392
|
-
|
|
392
|
+
this.debugLog('openAPI (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
|
|
393
393
|
}
|
|
394
394
|
}
|
|
395
395
|
else {
|
|
396
396
|
await this.offlineOff();
|
|
397
|
-
|
|
397
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
398
398
|
}
|
|
399
399
|
// Refresh the status from the API
|
|
400
400
|
interval(15000)
|
|
@@ -405,20 +405,20 @@ export class StripLight extends deviceBase {
|
|
|
405
405
|
});
|
|
406
406
|
}
|
|
407
407
|
async BLEpushChanges() {
|
|
408
|
-
|
|
408
|
+
this.debugLog('BLEpushChanges');
|
|
409
409
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
410
|
-
|
|
410
|
+
this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
411
411
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device);
|
|
412
412
|
try {
|
|
413
413
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
414
414
|
this.device.bleMac = formattedDeviceId;
|
|
415
|
-
|
|
415
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
416
416
|
if (switchBotBLE !== false) {
|
|
417
417
|
switchBotBLE
|
|
418
418
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
419
419
|
.then(async (device_list) => {
|
|
420
420
|
const deviceList = device_list;
|
|
421
|
-
|
|
421
|
+
this.infoLog(`On: ${this.LightBulb.On}`);
|
|
422
422
|
return await this.retryBLE({
|
|
423
423
|
max: await this.maxRetryBLE(),
|
|
424
424
|
fn: async () => {
|
|
@@ -432,109 +432,109 @@ export class StripLight extends deviceBase {
|
|
|
432
432
|
});
|
|
433
433
|
})
|
|
434
434
|
.then(async () => {
|
|
435
|
-
|
|
435
|
+
this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
|
|
436
436
|
await this.updateHomeKitCharacteristics();
|
|
437
437
|
})
|
|
438
438
|
.catch(async (e) => {
|
|
439
439
|
await this.apiError(e);
|
|
440
|
-
|
|
440
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
441
441
|
await this.BLEPushConnection();
|
|
442
442
|
});
|
|
443
443
|
}
|
|
444
444
|
else {
|
|
445
|
-
|
|
445
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
|
|
446
446
|
await this.BLEPushConnection();
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
449
|
catch (error) {
|
|
450
|
-
|
|
450
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
453
|
else {
|
|
454
|
-
|
|
454
|
+
this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
457
|
async BLEpushBrightnessChanges() {
|
|
458
|
-
|
|
458
|
+
this.debugLog('BLEpushBrightnessChanges');
|
|
459
459
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
460
460
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device);
|
|
461
461
|
try {
|
|
462
462
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
463
463
|
this.device.bleMac = formattedDeviceId;
|
|
464
|
-
|
|
464
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
465
465
|
if (switchBotBLE !== false) {
|
|
466
466
|
switchBotBLE
|
|
467
467
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
468
468
|
.then(async (device_list) => {
|
|
469
|
-
|
|
469
|
+
this.infoLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
470
470
|
return await device_list[0].setBrightness(this.LightBulb.Brightness);
|
|
471
471
|
})
|
|
472
472
|
.then(async () => {
|
|
473
|
-
|
|
473
|
+
this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`);
|
|
474
474
|
await this.updateHomeKitCharacteristics();
|
|
475
475
|
})
|
|
476
476
|
.catch(async (e) => {
|
|
477
477
|
await this.apiError(e);
|
|
478
|
-
|
|
478
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
479
479
|
await this.BLEPushConnection();
|
|
480
480
|
});
|
|
481
481
|
}
|
|
482
482
|
else {
|
|
483
|
-
|
|
483
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
|
|
484
484
|
await this.BLEPushConnection();
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
487
|
catch (error) {
|
|
488
|
-
|
|
488
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
491
|
else {
|
|
492
|
-
|
|
492
|
+
this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
async BLEpushRGBChanges() {
|
|
496
|
-
|
|
496
|
+
this.debugLog('BLEpushRGBChanges');
|
|
497
497
|
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
498
|
-
|
|
498
|
+
this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
499
499
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation);
|
|
500
|
-
|
|
500
|
+
this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
|
|
501
501
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device);
|
|
502
502
|
try {
|
|
503
503
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
504
504
|
this.device.bleMac = formattedDeviceId;
|
|
505
|
-
|
|
505
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
506
506
|
if (switchBotBLE !== false) {
|
|
507
507
|
switchBotBLE
|
|
508
508
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
509
509
|
.then(async (device_list) => {
|
|
510
|
-
|
|
510
|
+
this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`);
|
|
511
511
|
return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue);
|
|
512
512
|
})
|
|
513
513
|
.then(async () => {
|
|
514
|
-
|
|
514
|
+
this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`);
|
|
515
515
|
await this.updateHomeKitCharacteristics();
|
|
516
516
|
})
|
|
517
517
|
.catch(async (e) => {
|
|
518
518
|
await this.apiError(e);
|
|
519
|
-
|
|
519
|
+
this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
520
520
|
await this.BLEPushConnection();
|
|
521
521
|
});
|
|
522
522
|
}
|
|
523
523
|
else {
|
|
524
|
-
|
|
524
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
|
|
525
525
|
await this.BLEPushConnection();
|
|
526
526
|
}
|
|
527
527
|
}
|
|
528
528
|
catch (error) {
|
|
529
|
-
|
|
529
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
532
|
else {
|
|
533
|
-
|
|
533
|
+
this.debugLog(`No changes (BLEpushRGBChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
534
534
|
}
|
|
535
535
|
}
|
|
536
536
|
async openAPIpushChanges() {
|
|
537
|
-
|
|
537
|
+
this.debugLog('openAPIpushChanges');
|
|
538
538
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
539
539
|
const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
|
|
540
540
|
const bodyChange = {
|
|
@@ -542,13 +542,13 @@ export class StripLight extends deviceBase {
|
|
|
542
542
|
parameter: 'default',
|
|
543
543
|
commandType: 'command',
|
|
544
544
|
};
|
|
545
|
-
|
|
545
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
546
546
|
try {
|
|
547
|
-
const
|
|
548
|
-
const deviceStatus =
|
|
549
|
-
|
|
547
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
548
|
+
const deviceStatus = response.body;
|
|
549
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
550
550
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
551
|
-
|
|
551
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
552
552
|
await this.updateHomeKitCharacteristics();
|
|
553
553
|
}
|
|
554
554
|
else {
|
|
@@ -557,31 +557,31 @@ export class StripLight extends deviceBase {
|
|
|
557
557
|
}
|
|
558
558
|
catch (e) {
|
|
559
559
|
await this.apiError(e);
|
|
560
|
-
|
|
560
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
563
|
else {
|
|
564
|
-
|
|
564
|
+
this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
567
|
async pushHueSaturationChanges() {
|
|
568
|
-
|
|
568
|
+
this.debugLog('pushHueSaturationChanges');
|
|
569
569
|
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
570
|
-
|
|
570
|
+
this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
571
571
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation);
|
|
572
|
-
|
|
572
|
+
this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
|
|
573
573
|
const bodyChange = {
|
|
574
574
|
command: 'setColor',
|
|
575
575
|
parameter: `${red}:${green}:${blue}`,
|
|
576
576
|
commandType: 'command',
|
|
577
577
|
};
|
|
578
|
-
|
|
578
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
579
579
|
try {
|
|
580
|
-
const
|
|
581
|
-
const deviceStatus =
|
|
582
|
-
|
|
580
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
581
|
+
const deviceStatus = response.body;
|
|
582
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
583
583
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
584
|
-
|
|
584
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
585
585
|
await this.updateHomeKitCharacteristics();
|
|
586
586
|
}
|
|
587
587
|
else {
|
|
@@ -590,28 +590,28 @@ export class StripLight extends deviceBase {
|
|
|
590
590
|
}
|
|
591
591
|
catch (e) {
|
|
592
592
|
await this.apiError(e);
|
|
593
|
-
|
|
593
|
+
this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
594
594
|
}
|
|
595
595
|
}
|
|
596
596
|
else {
|
|
597
|
-
|
|
597
|
+
this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
598
598
|
}
|
|
599
599
|
}
|
|
600
600
|
async pushBrightnessChanges() {
|
|
601
|
-
|
|
601
|
+
this.debugLog('pushBrightnessChanges');
|
|
602
602
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
603
603
|
const bodyChange = {
|
|
604
604
|
command: 'setBrightness',
|
|
605
605
|
parameter: `${this.LightBulb.Brightness}`,
|
|
606
606
|
commandType: 'command',
|
|
607
607
|
};
|
|
608
|
-
|
|
608
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
609
609
|
try {
|
|
610
|
-
const
|
|
611
|
-
const deviceStatus =
|
|
612
|
-
|
|
610
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
611
|
+
const deviceStatus = response.body;
|
|
612
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
613
613
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
614
|
-
|
|
614
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
615
615
|
await this.updateHomeKitCharacteristics();
|
|
616
616
|
}
|
|
617
617
|
else {
|
|
@@ -620,11 +620,11 @@ export class StripLight extends deviceBase {
|
|
|
620
620
|
}
|
|
621
621
|
catch (e) {
|
|
622
622
|
await this.apiError(e);
|
|
623
|
-
|
|
623
|
+
this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
626
|
else {
|
|
627
|
-
|
|
627
|
+
this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
628
628
|
}
|
|
629
629
|
}
|
|
630
630
|
/**
|
|
@@ -632,10 +632,10 @@ export class StripLight extends deviceBase {
|
|
|
632
632
|
*/
|
|
633
633
|
async OnSet(value) {
|
|
634
634
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
635
|
-
|
|
635
|
+
this.infoLog(`Set On: ${value}`);
|
|
636
636
|
}
|
|
637
637
|
else {
|
|
638
|
-
|
|
638
|
+
this.debugLog(`No Changes, On: ${value}`);
|
|
639
639
|
}
|
|
640
640
|
this.LightBulb.On = value;
|
|
641
641
|
this.doStripLightUpdate.next();
|
|
@@ -645,7 +645,7 @@ export class StripLight extends deviceBase {
|
|
|
645
645
|
*/
|
|
646
646
|
async BrightnessSet(value) {
|
|
647
647
|
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
648
|
-
|
|
648
|
+
this.infoLog(`Set Brightness: ${value}`);
|
|
649
649
|
}
|
|
650
650
|
else {
|
|
651
651
|
if (this.LightBulb.On) {
|
|
@@ -742,21 +742,21 @@ export class StripLight extends deviceBase {
|
|
|
742
742
|
async getAdaptiveLightingSettings(accessory, device) {
|
|
743
743
|
// Adaptive Lighting
|
|
744
744
|
this.adaptiveLighting = accessory.context.adaptiveLighting ?? true;
|
|
745
|
-
|
|
745
|
+
this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`);
|
|
746
746
|
// Adaptive Lighting Shift
|
|
747
747
|
this.adaptiveLightingShift = device.adaptiveLightingShift ?? 0;
|
|
748
748
|
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
749
749
|
}
|
|
750
750
|
async BLEPushConnection() {
|
|
751
751
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
752
|
-
|
|
752
|
+
this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
753
753
|
await this.openAPIpushChanges();
|
|
754
754
|
}
|
|
755
755
|
}
|
|
756
756
|
async BLERefreshConnection(switchbot) {
|
|
757
|
-
|
|
757
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
758
758
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
759
|
-
|
|
759
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
760
760
|
await this.openAPIRefreshStatus();
|
|
761
761
|
}
|
|
762
762
|
}
|