@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.1-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/device/blindtilt.js +102 -102
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +85 -85
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +98 -98
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +140 -140
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +44 -44
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js +82 -82
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +11 -11
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +41 -41
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +96 -96
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +43 -43
- 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 +119 -119
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +75 -75
- 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 +42 -42
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js +60 -60
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -74
- 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 +1 -1
- package/src/device/blindtilt.ts +102 -102
- package/src/device/bot.ts +85 -85
- package/src/device/ceilinglight.ts +98 -98
- package/src/device/colorbulb.ts +140 -140
- package/src/device/contact.ts +44 -44
- package/src/device/curtain.ts +82 -82
- package/src/device/device.ts +41 -41
- package/src/device/fan.ts +96 -96
- package/src/device/hub.ts +43 -43
- package/src/device/humidifier.ts +84 -84
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +119 -119
- package/src/device/lock.ts +75 -75
- 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 +42 -42
- package/src/device/plug.ts +60 -60
- package/src/device/robotvacuumcleaner.ts +74 -74
- 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/src/device/lightstrip.ts
CHANGED
|
@@ -188,28 +188,28 @@ export class StripLight extends deviceBase {
|
|
|
188
188
|
await this.pushChanges()
|
|
189
189
|
} catch (e: any) {
|
|
190
190
|
await this.apiError(e)
|
|
191
|
-
|
|
191
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
192
192
|
}
|
|
193
193
|
this.stripLightUpdateInProgress = false
|
|
194
194
|
})
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
async BLEparseStatus(): Promise<void> {
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
this.debugLog('BLEparseStatus')
|
|
199
|
+
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})`)
|
|
200
200
|
|
|
201
201
|
// On
|
|
202
202
|
this.LightBulb.On = this.serviceData.power
|
|
203
|
-
|
|
203
|
+
this.debugLog(`On: ${this.LightBulb.On}`)
|
|
204
204
|
|
|
205
205
|
// Brightness
|
|
206
206
|
this.LightBulb.Brightness = this.serviceData.brightness
|
|
207
|
-
|
|
207
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
208
208
|
|
|
209
209
|
// Color, Hue & Brightness
|
|
210
|
-
|
|
210
|
+
this.debugLog(`red: ${this.serviceData.red}, green: ${this.serviceData.green}, blue: ${this.serviceData.blue}`)
|
|
211
211
|
const [hue, saturation] = rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue)
|
|
212
|
-
|
|
212
|
+
this.debugLog(`hs: ${JSON.stringify(rgb2hs(this.serviceData.red, this.serviceData.green, this.serviceData.blue))}`)
|
|
213
213
|
|
|
214
214
|
// Hue
|
|
215
215
|
this.LightBulb.Hue = hue
|
|
@@ -221,36 +221,36 @@ export class StripLight extends deviceBase {
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
async openAPIparseStatus(): Promise<void> {
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
this.debugLog('openAPIparseStatus')
|
|
225
|
+
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})`)
|
|
226
226
|
|
|
227
227
|
// On
|
|
228
228
|
this.LightBulb.On = this.deviceStatus.power === 'on'
|
|
229
|
-
|
|
229
|
+
this.debugLog(`On: ${this.LightBulb.On}`)
|
|
230
230
|
|
|
231
231
|
// Brightness
|
|
232
232
|
this.LightBulb.Brightness = this.deviceStatus.brightness
|
|
233
|
-
|
|
233
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
234
234
|
|
|
235
235
|
// Color, Hue & Brightness
|
|
236
|
-
|
|
236
|
+
this.debugLog(`color: ${JSON.stringify(this.deviceStatus.color)}`)
|
|
237
237
|
const [red, green, blue] = this.deviceStatus.color.split(':')
|
|
238
|
-
|
|
238
|
+
this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`)
|
|
239
239
|
const [hue, saturation] = rgb2hs(red, green, blue)
|
|
240
|
-
|
|
240
|
+
this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`)
|
|
241
241
|
|
|
242
242
|
// Hue
|
|
243
243
|
this.LightBulb.Hue = hue
|
|
244
|
-
|
|
244
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}`)
|
|
245
245
|
|
|
246
246
|
// Saturation
|
|
247
247
|
this.LightBulb.Saturation = saturation
|
|
248
|
-
|
|
248
|
+
this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
|
|
249
249
|
|
|
250
250
|
// Firmware Version
|
|
251
251
|
if (this.deviceStatus.version) {
|
|
252
252
|
const version = this.deviceStatus.version.toString()
|
|
253
|
-
|
|
253
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
254
254
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
255
255
|
this.accessory
|
|
256
256
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -259,36 +259,36 @@ export class StripLight extends deviceBase {
|
|
|
259
259
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
260
260
|
.updateValue(deviceVersion)
|
|
261
261
|
this.accessory.context.version = deviceVersion
|
|
262
|
-
|
|
262
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
async parseStatusWebhook(): Promise<void> {
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
this.debugLog('parseStatusWebhook')
|
|
268
|
+
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})`)
|
|
269
269
|
|
|
270
270
|
// On
|
|
271
271
|
this.LightBulb.On = this.webhookContext.powerState === 'ON'
|
|
272
|
-
|
|
272
|
+
this.debugLog(`On: ${this.LightBulb.On}`)
|
|
273
273
|
|
|
274
274
|
// Brightness
|
|
275
275
|
this.LightBulb.Brightness = this.webhookContext.brightness
|
|
276
|
-
|
|
276
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
277
277
|
|
|
278
278
|
// Color, Hue & Brightness
|
|
279
|
-
|
|
279
|
+
this.debugLog(`color: ${JSON.stringify(this.webhookContext.color)}`)
|
|
280
280
|
const [red, green, blue] = this.webhookContext.color.split(':')
|
|
281
|
-
|
|
281
|
+
this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`)
|
|
282
282
|
const [hue, saturation] = rgb2hs(red, green, blue)
|
|
283
|
-
|
|
283
|
+
this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`)
|
|
284
284
|
|
|
285
285
|
// Hue
|
|
286
286
|
this.LightBulb.Hue = hue
|
|
287
|
-
|
|
287
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}`)
|
|
288
288
|
|
|
289
289
|
// Saturation
|
|
290
290
|
this.LightBulb.Saturation = saturation
|
|
291
|
-
|
|
291
|
+
this.debugLog(`Saturation: ${this.LightBulb.Saturation}`)
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
/**
|
|
@@ -296,19 +296,19 @@ export class StripLight extends deviceBase {
|
|
|
296
296
|
*/
|
|
297
297
|
async refreshStatus(): Promise<void> {
|
|
298
298
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
299
|
-
|
|
299
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
300
300
|
} else if (this.BLE) {
|
|
301
301
|
await this.BLERefreshStatus()
|
|
302
302
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
303
303
|
await this.openAPIRefreshStatus()
|
|
304
304
|
} else {
|
|
305
305
|
await this.offlineOff()
|
|
306
|
-
|
|
306
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
async BLERefreshStatus(): Promise<void> {
|
|
311
|
-
|
|
311
|
+
this.debugLog('BLERefreshStatus')
|
|
312
312
|
const switchBotBLE = await this.switchbotBLE()
|
|
313
313
|
if (switchBotBLE === undefined) {
|
|
314
314
|
await this.BLERefreshConnection(switchBotBLE)
|
|
@@ -323,7 +323,7 @@ export class StripLight extends deviceBase {
|
|
|
323
323
|
await this.BLEparseStatus()
|
|
324
324
|
await this.updateHomeKitCharacteristics()
|
|
325
325
|
} else {
|
|
326
|
-
|
|
326
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
327
327
|
await this.BLERefreshConnection(switchBotBLE)
|
|
328
328
|
}
|
|
329
329
|
})()
|
|
@@ -331,67 +331,67 @@ export class StripLight extends deviceBase {
|
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
async registerPlatformBLE(): Promise<void> {
|
|
334
|
-
|
|
334
|
+
this.debugLog('registerPlatformBLE')
|
|
335
335
|
if (this.config.options?.BLE) {
|
|
336
|
-
|
|
336
|
+
this.debugLog('is listening to Platform BLE.')
|
|
337
337
|
try {
|
|
338
338
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
339
339
|
this.device.bleMac = formattedDeviceId
|
|
340
|
-
|
|
340
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
341
341
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: stripLightServiceData) => {
|
|
342
342
|
try {
|
|
343
|
-
|
|
343
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
344
344
|
this.serviceData = context
|
|
345
345
|
await this.BLEparseStatus()
|
|
346
346
|
await this.updateHomeKitCharacteristics()
|
|
347
347
|
} catch (e: any) {
|
|
348
|
-
|
|
348
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
} catch (error) {
|
|
352
|
-
|
|
352
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
353
353
|
}
|
|
354
354
|
} else {
|
|
355
|
-
|
|
355
|
+
this.debugLog('is not listening to Platform BLE')
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
async openAPIRefreshStatus(): Promise<void> {
|
|
360
|
-
|
|
360
|
+
this.debugLog('openAPIRefreshStatus')
|
|
361
361
|
try {
|
|
362
|
-
const
|
|
363
|
-
const deviceStatus: any =
|
|
364
|
-
|
|
362
|
+
const response = await this.deviceRefreshStatus()
|
|
363
|
+
const deviceStatus: any = response.body
|
|
364
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
365
365
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
366
|
-
|
|
366
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
367
367
|
this.deviceStatus = deviceStatus.body
|
|
368
368
|
await this.openAPIparseStatus()
|
|
369
369
|
await this.updateHomeKitCharacteristics()
|
|
370
370
|
} else {
|
|
371
|
-
|
|
372
|
-
|
|
371
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
372
|
+
this.debugWarnLog(deviceStatus)
|
|
373
373
|
}
|
|
374
374
|
} catch (e: any) {
|
|
375
375
|
await this.apiError(e)
|
|
376
|
-
|
|
376
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
async registerWebhook() {
|
|
381
381
|
if (this.device.webhook) {
|
|
382
|
-
|
|
382
|
+
this.debugLog('is listening webhook.')
|
|
383
383
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: stripLightWebhookContext) => {
|
|
384
384
|
try {
|
|
385
|
-
|
|
385
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
386
386
|
this.webhookContext = context
|
|
387
387
|
await this.parseStatusWebhook()
|
|
388
388
|
await this.updateHomeKitCharacteristics()
|
|
389
389
|
} catch (e: any) {
|
|
390
|
-
|
|
390
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
} else {
|
|
394
|
-
|
|
394
|
+
this.debugLog('is not listening webhook.')
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
|
|
@@ -412,36 +412,36 @@ export class StripLight extends deviceBase {
|
|
|
412
412
|
await this.BLEpushChanges()
|
|
413
413
|
if (this.LightBulb.On) {
|
|
414
414
|
// Push Brightness Update
|
|
415
|
-
|
|
415
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
416
416
|
await this.BLEpushBrightnessChanges()
|
|
417
417
|
// Push Hue & Saturation Update
|
|
418
|
-
|
|
418
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`)
|
|
419
419
|
await this.BLEpushRGBChanges()
|
|
420
420
|
// Set ColorTemperature
|
|
421
421
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
422
422
|
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature))
|
|
423
423
|
this.accessory.context.kelvin = kelvin
|
|
424
424
|
} else {
|
|
425
|
-
|
|
425
|
+
this.debugLog(`No pushColorTemperatureChanges, ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`)
|
|
426
426
|
}
|
|
427
427
|
} else {
|
|
428
|
-
|
|
428
|
+
this.debugLog('BLE (Brightness), (Hue), & (Saturation) changes will not happen, as the device is OFF.')
|
|
429
429
|
}
|
|
430
430
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
431
431
|
await this.openAPIpushChanges()
|
|
432
432
|
if (this.LightBulb.On) {
|
|
433
433
|
// Push Brightness Update
|
|
434
|
-
|
|
434
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
435
435
|
await this.pushBrightnessChanges()
|
|
436
436
|
// Push Hue & Saturation Update
|
|
437
|
-
|
|
437
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`)
|
|
438
438
|
await this.pushHueSaturationChanges()
|
|
439
439
|
} else {
|
|
440
|
-
|
|
440
|
+
this.debugLog('openAPI (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.')
|
|
441
441
|
}
|
|
442
442
|
} else {
|
|
443
443
|
await this.offlineOff()
|
|
444
|
-
|
|
444
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
|
|
445
445
|
}
|
|
446
446
|
// Refresh the status from the API
|
|
447
447
|
interval(15000)
|
|
@@ -453,22 +453,22 @@ export class StripLight extends deviceBase {
|
|
|
453
453
|
}
|
|
454
454
|
|
|
455
455
|
async BLEpushChanges(): Promise<void> {
|
|
456
|
-
|
|
456
|
+
this.debugLog('BLEpushChanges')
|
|
457
457
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
458
|
-
|
|
458
|
+
this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
459
459
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
460
460
|
try {
|
|
461
461
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
462
462
|
this.device.bleMac = formattedDeviceId
|
|
463
|
-
|
|
463
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
464
464
|
if (switchBotBLE !== false) {
|
|
465
465
|
switchBotBLE
|
|
466
466
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
467
467
|
.then(async (device_list: SwitchbotDevice[]) => {
|
|
468
468
|
const deviceList = device_list as unknown as WoStrip[]
|
|
469
|
-
|
|
469
|
+
this.infoLog(`On: ${this.LightBulb.On}`)
|
|
470
470
|
return await this.retryBLE({
|
|
471
|
-
max:
|
|
471
|
+
max: this.maxRetryBLE(),
|
|
472
472
|
fn: async () => {
|
|
473
473
|
if (this.LightBulb.On) {
|
|
474
474
|
return await deviceList[0].turnOn()
|
|
@@ -479,103 +479,103 @@ export class StripLight extends deviceBase {
|
|
|
479
479
|
})
|
|
480
480
|
})
|
|
481
481
|
.then(async () => {
|
|
482
|
-
|
|
482
|
+
this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
483
483
|
await this.updateHomeKitCharacteristics()
|
|
484
484
|
})
|
|
485
485
|
.catch(async (e: any) => {
|
|
486
486
|
await this.apiError(e)
|
|
487
|
-
|
|
487
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
488
488
|
await this.BLEPushConnection()
|
|
489
489
|
})
|
|
490
490
|
} else {
|
|
491
|
-
|
|
491
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
492
492
|
await this.BLEPushConnection()
|
|
493
493
|
}
|
|
494
494
|
} catch (error) {
|
|
495
|
-
|
|
495
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
496
496
|
}
|
|
497
497
|
} else {
|
|
498
|
-
|
|
498
|
+
this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
|
|
502
502
|
async BLEpushBrightnessChanges(): Promise<void> {
|
|
503
|
-
|
|
503
|
+
this.debugLog('BLEpushBrightnessChanges')
|
|
504
504
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
505
505
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
506
506
|
try {
|
|
507
507
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
508
508
|
this.device.bleMac = formattedDeviceId
|
|
509
|
-
|
|
509
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
510
510
|
if (switchBotBLE !== false) {
|
|
511
511
|
switchBotBLE
|
|
512
512
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
513
513
|
.then(async (device_list: SwitchbotDevice[]) => {
|
|
514
|
-
|
|
514
|
+
this.infoLog(`Brightness: ${this.LightBulb.Brightness}`)
|
|
515
515
|
return await device_list[0].setBrightness(this.LightBulb.Brightness)
|
|
516
516
|
})
|
|
517
517
|
.then(async () => {
|
|
518
|
-
|
|
518
|
+
this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`)
|
|
519
519
|
await this.updateHomeKitCharacteristics()
|
|
520
520
|
})
|
|
521
521
|
.catch(async (e: any) => {
|
|
522
522
|
await this.apiError(e)
|
|
523
|
-
|
|
523
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
524
524
|
await this.BLEPushConnection()
|
|
525
525
|
})
|
|
526
526
|
} else {
|
|
527
|
-
|
|
527
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
528
528
|
await this.BLEPushConnection()
|
|
529
529
|
}
|
|
530
530
|
} catch (error) {
|
|
531
|
-
|
|
531
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
532
532
|
}
|
|
533
533
|
} else {
|
|
534
|
-
|
|
534
|
+
this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
537
|
|
|
538
538
|
async BLEpushRGBChanges(): Promise<void> {
|
|
539
|
-
|
|
539
|
+
this.debugLog('BLEpushRGBChanges')
|
|
540
540
|
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
541
|
-
|
|
541
|
+
this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
542
542
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
543
|
-
|
|
543
|
+
this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
544
544
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
545
545
|
try {
|
|
546
546
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
547
547
|
this.device.bleMac = formattedDeviceId
|
|
548
|
-
|
|
548
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
549
549
|
if (switchBotBLE !== false) {
|
|
550
550
|
switchBotBLE
|
|
551
551
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
552
552
|
.then(async (device_list: SwitchbotDevice[]) => {
|
|
553
|
-
|
|
553
|
+
this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`)
|
|
554
554
|
return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue)
|
|
555
555
|
})
|
|
556
556
|
.then(async () => {
|
|
557
|
-
|
|
557
|
+
this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`)
|
|
558
558
|
await this.updateHomeKitCharacteristics()
|
|
559
559
|
})
|
|
560
560
|
.catch(async (e: any) => {
|
|
561
561
|
await this.apiError(e)
|
|
562
|
-
|
|
562
|
+
this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
563
563
|
await this.BLEPushConnection()
|
|
564
564
|
})
|
|
565
565
|
} else {
|
|
566
|
-
|
|
566
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
567
567
|
await this.BLEPushConnection()
|
|
568
568
|
}
|
|
569
569
|
} catch (error) {
|
|
570
|
-
|
|
570
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
571
571
|
}
|
|
572
572
|
} else {
|
|
573
|
-
|
|
573
|
+
this.debugLog(`No changes (BLEpushRGBChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`)
|
|
574
574
|
}
|
|
575
575
|
}
|
|
576
576
|
|
|
577
577
|
async openAPIpushChanges() {
|
|
578
|
-
|
|
578
|
+
this.debugLog('openAPIpushChanges')
|
|
579
579
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
580
580
|
const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
|
|
581
581
|
const bodyChange: bodyChange = {
|
|
@@ -583,82 +583,82 @@ export class StripLight extends deviceBase {
|
|
|
583
583
|
parameter: 'default',
|
|
584
584
|
commandType: 'command',
|
|
585
585
|
}
|
|
586
|
-
|
|
586
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
587
587
|
try {
|
|
588
|
-
const
|
|
589
|
-
const deviceStatus: any =
|
|
590
|
-
|
|
588
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
589
|
+
const deviceStatus: any = response.body
|
|
590
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
591
591
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
592
|
-
|
|
592
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
593
593
|
await this.updateHomeKitCharacteristics()
|
|
594
594
|
} else {
|
|
595
595
|
await this.statusCode(deviceStatus.statusCode)
|
|
596
596
|
}
|
|
597
597
|
} catch (e: any) {
|
|
598
598
|
await this.apiError(e)
|
|
599
|
-
|
|
599
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
600
600
|
}
|
|
601
601
|
} else {
|
|
602
|
-
|
|
602
|
+
this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
603
603
|
}
|
|
604
604
|
}
|
|
605
605
|
|
|
606
606
|
async pushHueSaturationChanges(): Promise<void> {
|
|
607
|
-
|
|
607
|
+
this.debugLog('pushHueSaturationChanges')
|
|
608
608
|
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
609
|
-
|
|
609
|
+
this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
610
610
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
611
|
-
|
|
611
|
+
this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
612
612
|
const bodyChange: bodyChange = {
|
|
613
613
|
command: 'setColor',
|
|
614
614
|
parameter: `${red}:${green}:${blue}`,
|
|
615
615
|
commandType: 'command',
|
|
616
616
|
}
|
|
617
|
-
|
|
617
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
618
618
|
try {
|
|
619
|
-
const
|
|
620
|
-
const deviceStatus: any =
|
|
621
|
-
|
|
619
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
620
|
+
const deviceStatus: any = response.body
|
|
621
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
622
622
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
623
|
-
|
|
623
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
624
624
|
await this.updateHomeKitCharacteristics()
|
|
625
625
|
} else {
|
|
626
626
|
await this.statusCode(deviceStatus.statusCode)
|
|
627
627
|
}
|
|
628
628
|
} catch (e: any) {
|
|
629
629
|
await this.apiError(e)
|
|
630
|
-
|
|
630
|
+
this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
631
631
|
}
|
|
632
632
|
} else {
|
|
633
|
-
|
|
633
|
+
this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`)
|
|
634
634
|
}
|
|
635
635
|
}
|
|
636
636
|
|
|
637
637
|
async pushBrightnessChanges(): Promise<void> {
|
|
638
|
-
|
|
638
|
+
this.debugLog('pushBrightnessChanges')
|
|
639
639
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
640
640
|
const bodyChange: bodyChange = {
|
|
641
641
|
command: 'setBrightness',
|
|
642
642
|
parameter: `${this.LightBulb.Brightness}`,
|
|
643
643
|
commandType: 'command',
|
|
644
644
|
}
|
|
645
|
-
|
|
645
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
646
646
|
try {
|
|
647
|
-
const
|
|
648
|
-
const deviceStatus: any =
|
|
649
|
-
|
|
647
|
+
const response = await this.pushChangeRequest(bodyChange)
|
|
648
|
+
const deviceStatus: any = response.body
|
|
649
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
650
650
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
651
|
-
|
|
651
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
652
652
|
await this.updateHomeKitCharacteristics()
|
|
653
653
|
} else {
|
|
654
654
|
await this.statusCode(deviceStatus.statusCode)
|
|
655
655
|
}
|
|
656
656
|
} catch (e: any) {
|
|
657
657
|
await this.apiError(e)
|
|
658
|
-
|
|
658
|
+
this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
659
659
|
}
|
|
660
660
|
} else {
|
|
661
|
-
|
|
661
|
+
this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`)
|
|
662
662
|
}
|
|
663
663
|
}
|
|
664
664
|
|
|
@@ -667,9 +667,9 @@ export class StripLight extends deviceBase {
|
|
|
667
667
|
*/
|
|
668
668
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
669
669
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
670
|
-
|
|
670
|
+
this.infoLog(`Set On: ${value}`)
|
|
671
671
|
} else {
|
|
672
|
-
|
|
672
|
+
this.debugLog(`No Changes, On: ${value}`)
|
|
673
673
|
}
|
|
674
674
|
|
|
675
675
|
this.LightBulb.On = value
|
|
@@ -681,7 +681,7 @@ export class StripLight extends deviceBase {
|
|
|
681
681
|
*/
|
|
682
682
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
683
683
|
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
684
|
-
|
|
684
|
+
this.infoLog(`Set Brightness: ${value}`)
|
|
685
685
|
} else {
|
|
686
686
|
if (this.LightBulb.On) {
|
|
687
687
|
this.debugLog(`No Changes, Brightness: ${value}`)
|
|
@@ -784,7 +784,7 @@ export class StripLight extends deviceBase {
|
|
|
784
784
|
async getAdaptiveLightingSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
|
|
785
785
|
// Adaptive Lighting
|
|
786
786
|
this.adaptiveLighting = accessory.context.adaptiveLighting ?? true
|
|
787
|
-
|
|
787
|
+
this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`)
|
|
788
788
|
// Adaptive Lighting Shift
|
|
789
789
|
this.adaptiveLightingShift = (device as stripLightConfig).adaptiveLightingShift ?? 0
|
|
790
790
|
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`)
|
|
@@ -792,15 +792,15 @@ export class StripLight extends deviceBase {
|
|
|
792
792
|
|
|
793
793
|
async BLEPushConnection() {
|
|
794
794
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
795
|
-
|
|
795
|
+
this.warnLog('Using OpenAPI Connection to Push Changes')
|
|
796
796
|
await this.openAPIpushChanges()
|
|
797
797
|
}
|
|
798
798
|
}
|
|
799
799
|
|
|
800
800
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
801
|
-
|
|
801
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
802
802
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
803
|
-
|
|
803
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
804
804
|
await this.openAPIRefreshStatus()
|
|
805
805
|
}
|
|
806
806
|
}
|