@switchbot/homebridge-switchbot 4.1.6-beta.2 → 4.1.6-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/dist/device/device.d.ts +1 -1
- package/dist/device/device.js +2 -2
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +2 -3
- package/dist/device/fan.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +1 -2
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lightstrip.js +2 -2
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +2 -2
- package/dist/device/lock.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +2 -3
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/platform.d.ts +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +2 -2
- package/dist/platform.js.map +1 -1
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +18 -0
- package/dist/utils.js.map +1 -1
- package/docs/assets/main.js +3 -3
- package/docs/assets/style.css +14 -0
- package/docs/functions/default.html +1 -1
- package/package.json +11 -11
- package/src/device/device.ts +2 -2
- package/src/device/fan.ts +2 -3
- package/src/device/humidifier.ts +1 -2
- package/src/device/lightstrip.ts +2 -2
- package/src/device/lock.ts +3 -3
- package/src/device/robotvacuumcleaner.ts +2 -3
- package/src/platform.ts +8 -9
- package/src/utils.ts +19 -0
package/src/device/lock.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* lock.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
-
import type { bodyChange, device, lockProServiceData, lockProStatus, lockProWebhookContext, lockServiceData, lockStatus, lockWebhookContext, SwitchbotDevice } from 'node-switchbot'
|
|
6
|
+
import type { bodyChange, device, lockProServiceData, lockProStatus, lockProWebhookContext, lockServiceData, lockStatus, lockWebhookContext, SwitchbotDevice, WoSmartLock } from 'node-switchbot'
|
|
7
7
|
|
|
8
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
9
9
|
import type { devicesConfig, lockConfig } from '../settings.js'
|
|
@@ -451,9 +451,9 @@ export class Lock extends deviceBase {
|
|
|
451
451
|
max: this.maxRetryBLE(),
|
|
452
452
|
fn: async () => {
|
|
453
453
|
if (this.LockMechanism.LockTargetState === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
454
|
-
return await device_list[0].lock(
|
|
454
|
+
return await (device_list[0] as WoSmartLock).lock()
|
|
455
455
|
} else {
|
|
456
|
-
return await device_list[0].unlock(
|
|
456
|
+
return await (device_list[0] as WoSmartLock).unlock()
|
|
457
457
|
}
|
|
458
458
|
},
|
|
459
459
|
})
|
|
@@ -392,15 +392,14 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
392
392
|
switchBotBLE
|
|
393
393
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
394
394
|
.then(async (device_list: SwitchbotDevice[]) => {
|
|
395
|
-
const deviceList = device_list as SwitchbotDevice[]
|
|
396
395
|
this.infoLog(`On: ${this.LightBulb.On}`)
|
|
397
396
|
return await this.retryBLE({
|
|
398
397
|
max: this.maxRetryBLE(),
|
|
399
398
|
fn: async () => {
|
|
400
399
|
if (this.LightBulb.On) {
|
|
401
|
-
return await
|
|
400
|
+
return await (device_list[0] as any).turnOn()
|
|
402
401
|
} else {
|
|
403
|
-
return await
|
|
402
|
+
return await (device_list[0] as any).turnOff()
|
|
404
403
|
}
|
|
405
404
|
},
|
|
406
405
|
})
|
package/src/platform.ts
CHANGED
|
@@ -6,6 +6,12 @@ import type { Server } from 'node:http'
|
|
|
6
6
|
|
|
7
7
|
import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge'
|
|
8
8
|
import type { MqttClient } from 'mqtt'
|
|
9
|
+
/*
|
|
10
|
+
* For Testing Locally:
|
|
11
|
+
* import type { blindTilt, curtain, curtain3, device, irdevice } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
12
|
+
* import { LogLevel, SwitchBotBLE, SwitchBotModel, SwitchBotOpenAPI } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
13
|
+
*/
|
|
14
|
+
import type { blindTilt, curtain, curtain3, device, deviceStatus, deviceStatusRequest, irdevice } from 'node-switchbot'
|
|
9
15
|
|
|
10
16
|
import type { blindTiltConfig, curtainConfig, devicesConfig, irDevicesConfig, options, SwitchBotPlatformConfig } from './settings.js'
|
|
11
17
|
|
|
@@ -15,13 +21,6 @@ import process, { argv } from 'node:process'
|
|
|
15
21
|
import asyncmqtt from 'async-mqtt'
|
|
16
22
|
import fakegato from 'fakegato-history'
|
|
17
23
|
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes'
|
|
18
|
-
/*
|
|
19
|
-
* For Testing Locally:
|
|
20
|
-
* import type { blindTilt, curtain, curtain3, device, irdevice } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
21
|
-
* import { LogLevel, SwitchBotBLE, SwitchBotModel, SwitchBotOpenAPI } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
22
|
-
*/
|
|
23
|
-
import type { blindTilt, curtain, curtain3, device, deviceStatus, deviceStatusRequest, irdevice } from 'node-switchbot'
|
|
24
|
-
|
|
25
24
|
import { LogLevel, SwitchBotBLE, SwitchBotModel, SwitchBotOpenAPI } from 'node-switchbot'
|
|
26
25
|
import { queueScheduler } from 'rxjs'
|
|
27
26
|
|
|
@@ -54,7 +53,7 @@ import { TV } from './irdevice/tv.js'
|
|
|
54
53
|
import { VacuumCleaner } from './irdevice/vacuumcleaner.js'
|
|
55
54
|
import { WaterHeater } from './irdevice/waterheater.js'
|
|
56
55
|
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'
|
|
57
|
-
import { formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js'
|
|
56
|
+
import { formatDeviceIdAsMac, isBlindTiltDevice, isCurtainDevice, safeStringify, sleep } from './utils.js'
|
|
58
57
|
|
|
59
58
|
/**
|
|
60
59
|
* HomebridgePlatform
|
|
@@ -2630,7 +2629,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
2630
2629
|
async connectBLE(accessory: PlatformAccessory, device: device & devicesConfig): Promise<any> {
|
|
2631
2630
|
try {
|
|
2632
2631
|
queueScheduler.schedule(async () => this.switchBotBLE)
|
|
2633
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${
|
|
2632
|
+
this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${safeStringify(this.switchBotBLE)}`)
|
|
2634
2633
|
return this.switchBotBLE
|
|
2635
2634
|
} catch (e: any) {
|
|
2636
2635
|
this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' not found, Error: ${e.message ?? e}`)
|
package/src/utils.ts
CHANGED
|
@@ -54,6 +54,25 @@ export function convertUnits(value: number, unit: string, convert?: string): num
|
|
|
54
54
|
return value
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Safely serializes an object to a JSON string, handling circular references.
|
|
59
|
+
*
|
|
60
|
+
* @param obj - The object to be serialized.
|
|
61
|
+
* @returns The JSON string representation of the object.
|
|
62
|
+
*/
|
|
63
|
+
export function safeStringify(obj: any) {
|
|
64
|
+
const seen = new WeakSet()
|
|
65
|
+
return JSON.stringify(obj, (_key, value) => {
|
|
66
|
+
if (typeof value === 'object' && value !== null) {
|
|
67
|
+
if (seen.has(value)) {
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
seen.add(value)
|
|
71
|
+
}
|
|
72
|
+
return value
|
|
73
|
+
}, ' ')
|
|
74
|
+
}
|
|
75
|
+
|
|
57
76
|
/**
|
|
58
77
|
* Formats a device ID as a MAC address.
|
|
59
78
|
* Ensures the device ID does not already contain colons.
|