@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/device.ts
CHANGED
|
@@ -90,7 +90,7 @@ export abstract class deviceBase {
|
|
|
90
90
|
this.deviceLogging = this.platform.debugMode ? 'debugMode' : device.logging ?? this.config.logging ?? 'standard'
|
|
91
91
|
const logging = this.platform.debugMode ? 'Debug Mode' : device.logging ? 'Device Config' : this.config.logging ? 'Platform Config' : 'Default'
|
|
92
92
|
accessory.context.deviceLogging = this.deviceLogging
|
|
93
|
-
|
|
93
|
+
this.debugLog(`Using ${logging} Logging: ${this.deviceLogging}`)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
async getDeviceRateSettings(accessory: PlatformAccessory, device: device & devicesConfig): Promise<void> {
|
|
@@ -106,7 +106,7 @@ export abstract class deviceBase {
|
|
|
106
106
|
this.devicePushRate = device.pushRate ?? this.config.options?.pushRate ?? 1
|
|
107
107
|
accessory.context.devicePushRate = this.devicePushRate
|
|
108
108
|
const pushRate = device.pushRate ? 'Device Config' : this.config.options?.pushRate ? 'Platform Config' : 'Default'
|
|
109
|
-
|
|
109
|
+
this.debugLog(`Using ${refreshRate} refreshRate: ${this.deviceRefreshRate}, ${updateRate} updateRate: ${this.deviceUpdateRate}, ${pushRate} pushRate: ${this.devicePushRate}`)
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
async getDeviceRetry(device: device & devicesConfig): Promise<void> {
|
|
@@ -114,7 +114,7 @@ export abstract class deviceBase {
|
|
|
114
114
|
const maxRetries = device.maxRetries ? 'Device' : 'Default'
|
|
115
115
|
this.deviceDelayBetweenRetries = device.delayBetweenRetries ? (device.delayBetweenRetries * 1000) : 3000
|
|
116
116
|
const delayBetweenRetries = device.delayBetweenRetries ? 'Device' : 'Default'
|
|
117
|
-
|
|
117
|
+
this.debugLog(`Using ${maxRetries} Max Retries: ${this.deviceMaxRetries}, ${delayBetweenRetries} Delay Between Retries: ${this.deviceDelayBetweenRetries}`)
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
async retryBLE({ max, fn }: { max: number, fn: { (): any, (): Promise<any> } }): Promise<null> {
|
|
@@ -122,14 +122,14 @@ export abstract class deviceBase {
|
|
|
122
122
|
if (max === 0) {
|
|
123
123
|
throw e
|
|
124
124
|
}
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
this.warnLog(e)
|
|
126
|
+
this.infoLog('Retrying')
|
|
127
127
|
await sleep(1000)
|
|
128
128
|
return this.retryBLE({ max: max - 1, fn })
|
|
129
129
|
})
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
maxRetryBLE(): number {
|
|
133
133
|
return this.device.maxRetry ? this.device.maxRetry : 5
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -261,7 +261,7 @@ export abstract class deviceBase {
|
|
|
261
261
|
: lightLevel === numberOfLevels
|
|
262
262
|
? set_maxLux
|
|
263
263
|
: ((set_maxLux - set_minLux) / spaceBetweenLevels) * (Number(lightLevel) - 1)
|
|
264
|
-
|
|
264
|
+
this.debugLog(`CurrentAmbientLightLevel: ${CurrentAmbientLightLevel}, LightLevel: ${lightLevel}, set_minLux: ${set_minLux}, set_maxLux: ${set_maxLux}`)
|
|
265
265
|
return CurrentAmbientLightLevel
|
|
266
266
|
}
|
|
267
267
|
|
|
@@ -291,7 +291,7 @@ export abstract class deviceBase {
|
|
|
291
291
|
// mqttPubOptions
|
|
292
292
|
this.deviceMqttPubOptions = device.mqttPubOptions ?? this.config.options?.mqttPubOptions ?? {}
|
|
293
293
|
const mqttPubOptions = device.mqttPubOptions ? 'Device Config' : this.config.options?.mqttPubOptions ? 'Platform Config' : 'Default'
|
|
294
|
-
|
|
294
|
+
this.debugLog(`Using ${mqttURL} MQTT URL: ${this.deviceMqttURL}, ${mqttOptions} mqttOptions: ${JSON.stringify(this.deviceMqttOptions)}, ${mqttPubOptions} mqttPubOptions: ${JSON.stringify(this.deviceMqttPubOptions)}`)
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
/*
|
|
@@ -301,7 +301,7 @@ export abstract class deviceBase {
|
|
|
301
301
|
try {
|
|
302
302
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
303
303
|
this.device.bleMac = formattedDeviceId
|
|
304
|
-
|
|
304
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
305
305
|
this.historyService = device.history
|
|
306
306
|
? new this.platform.fakegatoAPI('room', accessory, {
|
|
307
307
|
log: this.platform.log,
|
|
@@ -310,7 +310,7 @@ export abstract class deviceBase {
|
|
|
310
310
|
})
|
|
311
311
|
: null
|
|
312
312
|
} catch (error) {
|
|
313
|
-
|
|
313
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
|
|
@@ -320,24 +320,24 @@ export abstract class deviceBase {
|
|
|
320
320
|
try {
|
|
321
321
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
322
322
|
this.device.bleMac = formattedDeviceId
|
|
323
|
-
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
324
323
|
await this.getCustomBLEAddress(switchBotBLE)
|
|
324
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
325
325
|
return switchBotBLE
|
|
326
326
|
} catch (error) {
|
|
327
|
-
|
|
327
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
async monitorAdvertisementPackets(switchbot: any) {
|
|
332
|
-
|
|
332
|
+
this.debugLog(`Scanning for ${this.device.bleModelName} devices...`)
|
|
333
333
|
try {
|
|
334
334
|
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac })
|
|
335
335
|
} catch (e: any) {
|
|
336
|
-
|
|
336
|
+
this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`)
|
|
337
337
|
}
|
|
338
338
|
// Set an event handler
|
|
339
339
|
let serviceData = { model: this.device.bleModel, modelName: this.device.bleModelName } as ad['serviceData']
|
|
340
|
-
switchbot.onadvertisement =
|
|
340
|
+
switchbot.onadvertisement = (ad: ad) => {
|
|
341
341
|
if (this.device.bleMac === ad.address && ad.serviceData.model === this.device.bleModel) {
|
|
342
342
|
this.debugLog(`${JSON.stringify(ad, null, ' ')}`)
|
|
343
343
|
this.debugLog(`address: ${ad.address}, model: ${ad.serviceData.model}`)
|
|
@@ -351,7 +351,7 @@ export abstract class deviceBase {
|
|
|
351
351
|
try {
|
|
352
352
|
await switchbot.stopScan()
|
|
353
353
|
} catch (e: any) {
|
|
354
|
-
|
|
354
|
+
this.errorLog(`Failed to stop BLE scanning. Error:${e.message ?? e}`)
|
|
355
355
|
}
|
|
356
356
|
return serviceData
|
|
357
357
|
}
|
|
@@ -364,10 +364,10 @@ export abstract class deviceBase {
|
|
|
364
364
|
try {
|
|
365
365
|
await switchbot.startScan({ model: this.device.bleModel })
|
|
366
366
|
} catch (e: any) {
|
|
367
|
-
|
|
367
|
+
this.errorLog(`Failed to start BLE scanning. Error:${e.message ?? e}`)
|
|
368
368
|
}
|
|
369
369
|
// Set an event handler
|
|
370
|
-
switchbot.onadvertisement =
|
|
370
|
+
switchbot.onadvertisement = (ad: ad) => {
|
|
371
371
|
this.warnLog(`ad: ${JSON.stringify(ad, null, ' ')}`)
|
|
372
372
|
}
|
|
373
373
|
await sleep(10000)
|
|
@@ -375,7 +375,7 @@ export abstract class deviceBase {
|
|
|
375
375
|
try {
|
|
376
376
|
switchbot.stopScan()
|
|
377
377
|
} catch (e: any) {
|
|
378
|
-
|
|
378
|
+
this.errorLog(`Failed to stop BLE scanning. Error:${e.message ?? e}`)
|
|
379
379
|
}
|
|
380
380
|
})()
|
|
381
381
|
}
|
|
@@ -676,7 +676,7 @@ export abstract class deviceBase {
|
|
|
676
676
|
device.bleModel = deviceConfig.bleModel
|
|
677
677
|
device.bleModelName = deviceConfig.bleModelName
|
|
678
678
|
device.bleModelFriednlyName = deviceConfig.bleModelFriednlyName
|
|
679
|
-
|
|
679
|
+
this.debugLog(`Model: ${device.model}, BLE Model: ${device.bleModel}, BLE Model Name: ${device.bleModelName}, BLE Model Friendly Name: ${device.bleModelFriednlyName}`)
|
|
680
680
|
|
|
681
681
|
const deviceFirmwareVersion = device.firmware ?? device.version ?? accessory.context.version ?? this.platform.version ?? '0.0.0'
|
|
682
682
|
const version = deviceFirmwareVersion.toString()
|
|
@@ -733,56 +733,56 @@ export abstract class deviceBase {
|
|
|
733
733
|
/**
|
|
734
734
|
* Logging for Device
|
|
735
735
|
*/
|
|
736
|
-
|
|
737
|
-
if (
|
|
736
|
+
infoLog(...log: any[]): void {
|
|
737
|
+
if (this.enablingDeviceLogging()) {
|
|
738
738
|
this.log.info(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
|
|
739
739
|
}
|
|
740
740
|
}
|
|
741
741
|
|
|
742
|
-
|
|
743
|
-
if (
|
|
742
|
+
successLog(...log: any[]): void {
|
|
743
|
+
if (this.enablingDeviceLogging()) {
|
|
744
744
|
this.log.success(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
|
|
745
745
|
}
|
|
746
746
|
}
|
|
747
747
|
|
|
748
|
-
|
|
749
|
-
if (
|
|
750
|
-
if (
|
|
748
|
+
debugSuccessLog(...log: any[]): void {
|
|
749
|
+
if (this.enablingDeviceLogging()) {
|
|
750
|
+
if (this.loggingIsDebug()) {
|
|
751
751
|
this.log.success(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
|
|
752
752
|
}
|
|
753
753
|
}
|
|
754
754
|
}
|
|
755
755
|
|
|
756
|
-
|
|
757
|
-
if (
|
|
756
|
+
warnLog(...log: any[]): void {
|
|
757
|
+
if (this.enablingDeviceLogging()) {
|
|
758
758
|
this.log.warn(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
|
|
759
759
|
}
|
|
760
760
|
}
|
|
761
761
|
|
|
762
|
-
|
|
763
|
-
if (
|
|
764
|
-
if (
|
|
762
|
+
debugWarnLog(...log: any[]): void {
|
|
763
|
+
if (this.enablingDeviceLogging()) {
|
|
764
|
+
if (this.loggingIsDebug()) {
|
|
765
765
|
this.log.warn(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
|
|
766
766
|
}
|
|
767
767
|
}
|
|
768
768
|
}
|
|
769
769
|
|
|
770
|
-
|
|
771
|
-
if (
|
|
770
|
+
errorLog(...log: any[]): void {
|
|
771
|
+
if (this.enablingDeviceLogging()) {
|
|
772
772
|
this.log.error(`${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
|
|
773
773
|
}
|
|
774
774
|
}
|
|
775
775
|
|
|
776
|
-
|
|
777
|
-
if (
|
|
778
|
-
if (
|
|
776
|
+
debugErrorLog(...log: any[]): void {
|
|
777
|
+
if (this.enablingDeviceLogging()) {
|
|
778
|
+
if (this.loggingIsDebug()) {
|
|
779
779
|
this.log.error(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
|
|
780
780
|
}
|
|
781
781
|
}
|
|
782
782
|
}
|
|
783
783
|
|
|
784
|
-
|
|
785
|
-
if (
|
|
784
|
+
debugLog(...log: any[]): void {
|
|
785
|
+
if (this.enablingDeviceLogging()) {
|
|
786
786
|
if (this.deviceLogging === 'debug') {
|
|
787
787
|
this.log.info(`[DEBUG] ${this.device.deviceType}: ${this.accessory.displayName}`, String(...log))
|
|
788
788
|
} else if (this.deviceLogging === 'debugMode') {
|
|
@@ -791,11 +791,11 @@ export abstract class deviceBase {
|
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
793
|
|
|
794
|
-
|
|
794
|
+
loggingIsDebug(): boolean {
|
|
795
795
|
return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug'
|
|
796
796
|
}
|
|
797
797
|
|
|
798
|
-
|
|
798
|
+
enablingDeviceLogging(): boolean {
|
|
799
799
|
return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug' || this.deviceLogging === 'standard'
|
|
800
800
|
}
|
|
801
801
|
}
|