@switchbot/homebridge-switchbot 3.8.1-beta.2 → 3.8.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +51 -38
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +78 -64
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +55 -42
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +133 -99
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -13
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +88 -70
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +0 -1
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +26 -22
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +54 -40
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +20 -14
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +45 -32
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +20 -14
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +107 -80
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +54 -40
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +20 -14
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +20 -14
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +20 -13
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +55 -41
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +55 -41
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +20 -13
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +23 -0
- package/dist/utils.js.map +1 -1
- package/package.json +7 -7
- package/src/device/blindtilt.ts +47 -36
- package/src/device/bot.ts +71 -59
- package/src/device/ceilinglight.ts +50 -39
- package/src/device/colorbulb.ts +128 -99
- package/src/device/contact.ts +16 -10
- package/src/device/curtain.ts +84 -69
- package/src/device/device.ts +24 -23
- package/src/device/fan.ts +49 -37
- package/src/device/hub.ts +16 -11
- package/src/device/humidifier.ts +41 -30
- package/src/device/iosensor.ts +16 -11
- package/src/device/lightstrip.ts +102 -79
- package/src/device/lock.ts +49 -37
- package/src/device/meter.ts +16 -11
- package/src/device/meterplus.ts +16 -11
- package/src/device/motion.ts +16 -10
- package/src/device/plug.ts +50 -38
- package/src/device/robotvacuumcleaner.ts +50 -38
- package/src/device/waterdetector.ts +16 -10
- package/src/utils.ts +29 -0
|
@@ -22,6 +22,7 @@ import type {
|
|
|
22
22
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
23
23
|
import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
|
|
24
24
|
|
|
25
|
+
import { formatDeviceIdAsMac } from '../utils.js'
|
|
25
26
|
import { deviceBase } from './device.js'
|
|
26
27
|
|
|
27
28
|
export class RobotVacuumCleaner extends deviceBase {
|
|
@@ -295,17 +296,22 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
295
296
|
await this.debugLog('registerPlatformBLE')
|
|
296
297
|
if (this.config.options?.BLE) {
|
|
297
298
|
await this.debugLog('is listening to Platform BLE.')
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
299
|
+
try {
|
|
300
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
301
|
+
this.device.bleMac = formattedDeviceId
|
|
302
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
303
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: robotVacuumCleanerServiceData) => {
|
|
304
|
+
try {
|
|
305
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
306
|
+
this.serviceData = context
|
|
307
|
+
await this.BLEparseStatus()
|
|
308
|
+
await this.updateHomeKitCharacteristics()
|
|
309
|
+
} catch (e: any) {
|
|
310
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
311
|
+
}
|
|
308
312
|
}
|
|
313
|
+
} catch (error) {
|
|
314
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
309
315
|
}
|
|
310
316
|
} else {
|
|
311
317
|
await this.debugLog('is not listening to Platform BLE')
|
|
@@ -383,35 +389,41 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
383
389
|
await this.debugLog('BLEpushChanges')
|
|
384
390
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
385
391
|
const switchbot = await this.platform.connectBLE(this.accessory, this.device)
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
392
|
+
try {
|
|
393
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
394
|
+
this.device.bleMac = formattedDeviceId
|
|
395
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
396
|
+
if (switchbot !== false) {
|
|
397
|
+
switchbot
|
|
398
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
399
|
+
.then(async (device_list: any) => {
|
|
400
|
+
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
401
|
+
return await this.retryBLE({
|
|
402
|
+
max: await this.maxRetryBLE(),
|
|
403
|
+
fn: async () => {
|
|
404
|
+
if (this.LightBulb.On) {
|
|
405
|
+
return await device_list[0].turnOn({ id: this.device.bleMac })
|
|
406
|
+
} else {
|
|
407
|
+
return await device_list[0].turnOff({ id: this.device.bleMac })
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
})
|
|
401
411
|
})
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
412
|
+
.then(async () => {
|
|
413
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`)
|
|
414
|
+
await this.updateHomeKitCharacteristics()
|
|
415
|
+
})
|
|
416
|
+
.catch(async (e: any) => {
|
|
417
|
+
await this.apiError(e)
|
|
418
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
419
|
+
await this.BLEPushConnection()
|
|
420
|
+
})
|
|
421
|
+
} else {
|
|
422
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
423
|
+
await this.BLEPushConnection()
|
|
424
|
+
}
|
|
425
|
+
} catch (error) {
|
|
426
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
415
427
|
}
|
|
416
428
|
} else {
|
|
417
429
|
await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`)
|
|
@@ -18,6 +18,7 @@ import type { waterLeakDetectorWebhookContext } from '../types/devicewebhookstat
|
|
|
18
18
|
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
19
19
|
import { interval, skipWhile, Subject } from 'rxjs'
|
|
20
20
|
|
|
21
|
+
import { formatDeviceIdAsMac } from '../utils.js'
|
|
21
22
|
import { deviceBase } from './device.js'
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -295,17 +296,22 @@ export class WaterDetector extends deviceBase {
|
|
|
295
296
|
await this.debugLog('registerPlatformBLE')
|
|
296
297
|
if (this.config.options?.BLE) {
|
|
297
298
|
await this.debugLog('is listening to Platform BLE.')
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
299
|
+
try {
|
|
300
|
+
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId!)
|
|
301
|
+
this.device.bleMac = formattedDeviceId
|
|
302
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
303
|
+
this.platform.bleEventHandler[this.device.bleMac] = async (context: waterLeakDetectorServiceData) => {
|
|
304
|
+
try {
|
|
305
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
306
|
+
this.serviceData = context
|
|
307
|
+
await this.BLEparseStatus()
|
|
308
|
+
await this.updateHomeKitCharacteristics()
|
|
309
|
+
} catch (e: any) {
|
|
310
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
311
|
+
}
|
|
308
312
|
}
|
|
313
|
+
} catch (error) {
|
|
314
|
+
await this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
|
|
309
315
|
}
|
|
310
316
|
} else {
|
|
311
317
|
await this.debugLog('is not listening to Platform BLE')
|
package/src/utils.ts
CHANGED
|
@@ -158,6 +158,35 @@ export function convertUnits(value: number, unit: string, convert?: string): num
|
|
|
158
158
|
return value
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/**
|
|
162
|
+
* Formats a device ID as a MAC address.
|
|
163
|
+
* Ensures the device ID does not already contain colons.
|
|
164
|
+
*
|
|
165
|
+
* @param deviceId - The device ID to format.
|
|
166
|
+
* @returns The formatted MAC address.
|
|
167
|
+
*/
|
|
168
|
+
export function formatDeviceIdAsMac(deviceId: string): string {
|
|
169
|
+
if (typeof deviceId !== 'string') {
|
|
170
|
+
throw new TypeError('Invalid device ID format. Device ID must be a string.')
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
deviceId = deviceId.trim()
|
|
174
|
+
|
|
175
|
+
const macAddressRegex = /^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$/i
|
|
176
|
+
const hexRegex = /^[0-9a-f]{12}$/i
|
|
177
|
+
|
|
178
|
+
if (macAddressRegex.test(deviceId)) {
|
|
179
|
+
return deviceId.toLowerCase()
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Check if the deviceId is a valid 12-character hexadecimal string
|
|
183
|
+
if (hexRegex.test(deviceId)) {
|
|
184
|
+
return deviceId.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
throw new Error('Invalid device ID format. Must be a valid MAC address or a 12-character hexadecimal string.')
|
|
188
|
+
}
|
|
189
|
+
|
|
161
190
|
export function rgb2hs(r: any, g: any, b: any) {
|
|
162
191
|
/**
|
|
163
192
|
* Credit:
|