node-switchbot 3.4.2-beta.2 → 3.4.2-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/wohumi.d.ts +22 -11
- package/dist/device/wohumi.d.ts.map +1 -1
- package/dist/device/wohumi.js +45 -20
- package/dist/device/wohumi.js.map +1 -1
- package/dist/test/wohumi.test.js +25 -73
- package/dist/test/wohumi.test.js.map +1 -1
- package/package.json +1 -1
package/dist/device/wohumi.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { SwitchbotDevice } from '../device.js';
|
|
|
7
7
|
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/tree/latest/devicetypes
|
|
8
8
|
*/
|
|
9
9
|
export declare class WoHumi extends SwitchbotDevice {
|
|
10
|
+
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
|
|
10
11
|
/**
|
|
11
12
|
* Parses the service data for WoHumi.
|
|
12
13
|
* @param {Buffer} serviceData - The service data buffer.
|
|
@@ -14,18 +15,12 @@ export declare class WoHumi extends SwitchbotDevice {
|
|
|
14
15
|
* @returns {Promise<humidifierServiceData | null>} - Parsed service data or null if invalid.
|
|
15
16
|
*/
|
|
16
17
|
static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<humidifierServiceData | null>;
|
|
17
|
-
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
|
|
18
18
|
/**
|
|
19
19
|
* Sends a command to the humidifier.
|
|
20
|
-
* @param {
|
|
21
|
-
* @returns {Promise<void>}
|
|
22
|
-
*/
|
|
23
|
-
operateHumi(bytes: number[]): Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* Presses the humidifier button.
|
|
20
|
+
* @param {Buffer} reqBuf - The command buffer.
|
|
26
21
|
* @returns {Promise<void>}
|
|
27
22
|
*/
|
|
28
|
-
|
|
23
|
+
protected operateHumi(reqBuf: Buffer): Promise<void>;
|
|
29
24
|
/**
|
|
30
25
|
* Turns on the humidifier.
|
|
31
26
|
* @returns {Promise<void>}
|
|
@@ -36,15 +31,31 @@ export declare class WoHumi extends SwitchbotDevice {
|
|
|
36
31
|
* @returns {Promise<void>}
|
|
37
32
|
*/
|
|
38
33
|
turnOff(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Increases the humidifier setting.
|
|
36
|
+
* @returns {Promise<void>}
|
|
37
|
+
*/
|
|
38
|
+
increase(): Promise<void>;
|
|
39
39
|
/**
|
|
40
40
|
* Decreases the humidifier setting.
|
|
41
41
|
* @returns {Promise<void>}
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
decrease(): Promise<void>;
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Sets the humidifier to auto mode.
|
|
46
|
+
* @returns {Promise<void>}
|
|
47
|
+
*/
|
|
48
|
+
setAutoMode(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Sets the humidifier to manual mode.
|
|
51
|
+
* @returns {Promise<void>}
|
|
52
|
+
*/
|
|
53
|
+
setManualMode(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Sets the humidifier level.
|
|
56
|
+
* @param {number} level - The level to set (0-100).
|
|
46
57
|
* @returns {Promise<void>}
|
|
47
58
|
*/
|
|
48
|
-
|
|
59
|
+
percentage(level: number): Promise<void>;
|
|
49
60
|
}
|
|
50
61
|
//# sourceMappingURL=wohumi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohumi.d.ts","sourceRoot":"","sources":["../../src/device/wohumi.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"wohumi.d.ts","sourceRoot":"","sources":["../../src/device/wohumi.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAW9C;;;GAGG;AACH,qBAAa,MAAO,SAAQ,eAAe;gBAC7B,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC;IAI5E;;;;;OAKG;WACU,gBAAgB,CAC3B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAChD,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;IA2BxC;;;;OAIG;cACa,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1D;;;OAGG;IACU,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC;;;OAGG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAItC;;;OAGG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAItC;;;OAGG;IACU,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzC;;;OAGG;IACU,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3C;;;;OAIG;IACU,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOtD"}
|
package/dist/device/wohumi.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { SwitchbotDevice } from '../device.js';
|
|
3
3
|
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
4
|
+
const HUMIDIFIER_COMMAND_HEADER = '5701';
|
|
5
|
+
const TURN_ON_KEY = `${HUMIDIFIER_COMMAND_HEADER}0101`;
|
|
6
|
+
const TURN_OFF_KEY = `${HUMIDIFIER_COMMAND_HEADER}0102`;
|
|
7
|
+
const INCREASE_KEY = `${HUMIDIFIER_COMMAND_HEADER}0103`;
|
|
8
|
+
const DECREASE_KEY = `${HUMIDIFIER_COMMAND_HEADER}0104`;
|
|
9
|
+
const SET_AUTO_MODE_KEY = `${HUMIDIFIER_COMMAND_HEADER}0105`;
|
|
10
|
+
const SET_MANUAL_MODE_KEY = `${HUMIDIFIER_COMMAND_HEADER}0106`;
|
|
4
11
|
/**
|
|
5
12
|
* Class representing a WoHumi device.
|
|
6
13
|
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/tree/latest/devicetypes
|
|
7
14
|
*/
|
|
8
15
|
export class WoHumi extends SwitchbotDevice {
|
|
16
|
+
constructor(peripheral, noble) {
|
|
17
|
+
super(peripheral, noble);
|
|
18
|
+
}
|
|
9
19
|
/**
|
|
10
20
|
* Parses the service data for WoHumi.
|
|
11
21
|
* @param {Buffer} serviceData - The service data buffer.
|
|
@@ -34,56 +44,71 @@ export class WoHumi extends SwitchbotDevice {
|
|
|
34
44
|
};
|
|
35
45
|
return data;
|
|
36
46
|
}
|
|
37
|
-
constructor(peripheral, noble) {
|
|
38
|
-
super(peripheral, noble);
|
|
39
|
-
}
|
|
40
47
|
/**
|
|
41
48
|
* Sends a command to the humidifier.
|
|
42
|
-
* @param {
|
|
49
|
+
* @param {Buffer} reqBuf - The command buffer.
|
|
43
50
|
* @returns {Promise<void>}
|
|
44
51
|
*/
|
|
45
|
-
async operateHumi(
|
|
46
|
-
const reqBuf = Buffer.from(bytes);
|
|
52
|
+
async operateHumi(reqBuf) {
|
|
47
53
|
const resBuf = await this.command(reqBuf);
|
|
48
54
|
const code = resBuf.readUInt8(0);
|
|
49
55
|
if (resBuf.length !== 3 || (code !== 0x01 && code !== 0x05)) {
|
|
50
56
|
throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Presses the humidifier button.
|
|
55
|
-
* @returns {Promise<void>}
|
|
56
|
-
*/
|
|
57
|
-
async press() {
|
|
58
|
-
await this.operateHumi([0x57, 0x01, 0x00]);
|
|
59
|
-
}
|
|
60
59
|
/**
|
|
61
60
|
* Turns on the humidifier.
|
|
62
61
|
* @returns {Promise<void>}
|
|
63
62
|
*/
|
|
64
63
|
async turnOn() {
|
|
65
|
-
await this.operateHumi(
|
|
64
|
+
await this.operateHumi(Buffer.from(TURN_ON_KEY, 'hex'));
|
|
66
65
|
}
|
|
67
66
|
/**
|
|
68
67
|
* Turns off the humidifier.
|
|
69
68
|
* @returns {Promise<void>}
|
|
70
69
|
*/
|
|
71
70
|
async turnOff() {
|
|
72
|
-
await this.operateHumi(
|
|
71
|
+
await this.operateHumi(Buffer.from(TURN_OFF_KEY, 'hex'));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Increases the humidifier setting.
|
|
75
|
+
* @returns {Promise<void>}
|
|
76
|
+
*/
|
|
77
|
+
async increase() {
|
|
78
|
+
await this.operateHumi(Buffer.from(INCREASE_KEY, 'hex'));
|
|
73
79
|
}
|
|
74
80
|
/**
|
|
75
81
|
* Decreases the humidifier setting.
|
|
76
82
|
* @returns {Promise<void>}
|
|
77
83
|
*/
|
|
78
|
-
async
|
|
79
|
-
await this.operateHumi(
|
|
84
|
+
async decrease() {
|
|
85
|
+
await this.operateHumi(Buffer.from(DECREASE_KEY, 'hex'));
|
|
80
86
|
}
|
|
81
87
|
/**
|
|
82
|
-
*
|
|
88
|
+
* Sets the humidifier to auto mode.
|
|
89
|
+
* @returns {Promise<void>}
|
|
90
|
+
*/
|
|
91
|
+
async setAutoMode() {
|
|
92
|
+
await this.operateHumi(Buffer.from(SET_AUTO_MODE_KEY, 'hex'));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Sets the humidifier to manual mode.
|
|
96
|
+
* @returns {Promise<void>}
|
|
97
|
+
*/
|
|
98
|
+
async setManualMode() {
|
|
99
|
+
await this.operateHumi(Buffer.from(SET_MANUAL_MODE_KEY, 'hex'));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Sets the humidifier level.
|
|
103
|
+
* @param {number} level - The level to set (0-100).
|
|
83
104
|
* @returns {Promise<void>}
|
|
84
105
|
*/
|
|
85
|
-
async
|
|
86
|
-
|
|
106
|
+
async percentage(level) {
|
|
107
|
+
if (level < 0 || level > 100) {
|
|
108
|
+
throw new Error('Level must be between 0 and 100');
|
|
109
|
+
}
|
|
110
|
+
const levelKey = `${HUMIDIFIER_COMMAND_HEADER}0107${level.toString(16).padStart(2, '0')}`;
|
|
111
|
+
await this.operateHumi(Buffer.from(levelKey, 'hex'));
|
|
87
112
|
}
|
|
88
113
|
}
|
|
89
114
|
//# sourceMappingURL=wohumi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohumi.js","sourceRoot":"","sources":["../../src/device/wohumi.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE3G;;;GAGG;AACH,MAAM,OAAO,MAAO,SAAQ,eAAe;IACzC;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAC3B,WAAmB,EACnB,OAAiD;QAEjD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,YAAY,EAAE,6CAA6C,WAAW,CAAC,MAAM,SAA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AC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAA;IAC1D,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,QAAQ;QACnB,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAA;IAC1D,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,WAAW;QACtB,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC,CAAA;IAC/D,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,aAAa;QACxB,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAAA;IACjE,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,UAAU,CAAC,KAAa;QACnC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;QACpD,CAAC;QACD,MAAM,QAAQ,GAAG,GAAG,yBAAyB,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAA;QACzF,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAA;IACtD,CAAC;CACF"}
|
package/dist/test/wohumi.test.js
CHANGED
|
@@ -1,81 +1,33 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
import { describe, expect, it
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { SwitchbotDevice } from '../device.js';
|
|
3
4
|
import { WoHumi } from '../device/wohumi.js';
|
|
4
|
-
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
5
5
|
describe('woHumi', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
modelFriendlyName: SwitchBotBLEModelFriendlyName.Humidifier,
|
|
15
|
-
onState: true,
|
|
16
|
-
autoMode: true,
|
|
17
|
-
percentage: 0,
|
|
18
|
-
humidity: 0,
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
it('should return null for invalid service data length', async () => {
|
|
22
|
-
const serviceData = Buffer.from([0x00, 0x80, 0x00]);
|
|
23
|
-
const result = await WoHumi.parseServiceData(serviceData, emitLog);
|
|
24
|
-
expect(result).toBeNull();
|
|
25
|
-
expect(emitLog).toHaveBeenCalledWith('error', '[parseServiceDataForWoHumi] Buffer length 3 !== 8!');
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe('operateHumi', () => {
|
|
29
|
-
it('should throw an error if the device returns an error', async () => {
|
|
30
|
-
const peripheral = {};
|
|
31
|
-
const wohumi = new WoHumi(peripheral, emitLog);
|
|
32
|
-
vi.spyOn(wohumi, 'command').mockResolvedValue(Buffer.from([0x00, 0x00, 0x00]));
|
|
33
|
-
await expect(wohumi.operateHumi([0x57, 0x01, 0x00])).rejects.toThrow('The device returned an error: 0x000000');
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
describe('press', () => {
|
|
37
|
-
it('should call operateHumi with correct bytes', async () => {
|
|
38
|
-
const peripheral = {};
|
|
39
|
-
const wohumi = new WoHumi(peripheral, emitLog);
|
|
40
|
-
const operateHumiSpy = vi.spyOn(wohumi, 'operateHumi').mockResolvedValue();
|
|
41
|
-
await wohumi.press();
|
|
42
|
-
expect(operateHumiSpy).toHaveBeenCalledWith([0x57, 0x01, 0x00]);
|
|
43
|
-
});
|
|
6
|
+
let wohumi;
|
|
7
|
+
let mockPeripheral;
|
|
8
|
+
let mockNoble;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
mockPeripheral = {};
|
|
11
|
+
mockNoble = {};
|
|
12
|
+
wohumi = new WoHumi(mockPeripheral, mockNoble);
|
|
13
|
+
jest.spyOn(SwitchbotDevice.prototype, 'command').mockResolvedValue(Buffer.from([0x01, 0x00, 0x00]));
|
|
44
14
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const peripheral = {};
|
|
48
|
-
const wohumi = new WoHumi(peripheral, emitLog);
|
|
49
|
-
const operateHumiSpy = vi.spyOn(wohumi, 'operateHumi').mockResolvedValue();
|
|
50
|
-
await wohumi.turnOn();
|
|
51
|
-
expect(operateHumiSpy).toHaveBeenCalledWith([0x57, 0x01, 0x01]);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe('turnOff', () => {
|
|
55
|
-
it('should call operateHumi with correct bytes', async () => {
|
|
56
|
-
const peripheral = {};
|
|
57
|
-
const wohumi = new WoHumi(peripheral, emitLog);
|
|
58
|
-
const operateHumiSpy = vi.spyOn(wohumi, 'operateHumi').mockResolvedValue();
|
|
59
|
-
await wohumi.turnOff();
|
|
60
|
-
expect(operateHumiSpy).toHaveBeenCalledWith([0x57, 0x01, 0x02]);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
describe('down', () => {
|
|
64
|
-
it('should call operateHumi with correct bytes', async () => {
|
|
65
|
-
const peripheral = {};
|
|
66
|
-
const wohumi = new WoHumi(peripheral, emitLog);
|
|
67
|
-
const operateHumiSpy = vi.spyOn(wohumi, 'operateHumi').mockResolvedValue();
|
|
68
|
-
await wohumi.down();
|
|
69
|
-
expect(operateHumiSpy).toHaveBeenCalledWith([0x57, 0x01, 0x03]);
|
|
70
|
-
});
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
jest.restoreAllMocks();
|
|
71
17
|
});
|
|
72
|
-
describe('
|
|
73
|
-
it('should
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
await wohumi.
|
|
78
|
-
|
|
18
|
+
describe('percentage', () => {
|
|
19
|
+
it('should throw an error if level is less than 0', async () => {
|
|
20
|
+
await expect(wohumi.percentage(-1)).rejects.toThrow('Level must be between 0 and 100');
|
|
21
|
+
});
|
|
22
|
+
it('should throw an error if level is greater than 100', async () => {
|
|
23
|
+
await expect(wohumi.percentage(101)).rejects.toThrow('Level must be between 0 and 100');
|
|
24
|
+
});
|
|
25
|
+
it('should send the correct command for a valid level', async () => {
|
|
26
|
+
const level = 50;
|
|
27
|
+
const expectedCommand = Buffer.from(`57010107${level.toString(16).padStart(2, '0')}`, 'hex');
|
|
28
|
+
const operateHumiSpy = jest.spyOn(wohumi, 'operateHumi');
|
|
29
|
+
await wohumi.percentage(level);
|
|
30
|
+
expect(operateHumiSpy).toHaveBeenCalledWith(expectedCommand);
|
|
79
31
|
});
|
|
80
32
|
});
|
|
81
33
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohumi.test.js","sourceRoot":"","sources":["../../src/test/wohumi.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"wohumi.test.js","sourceRoot":"","sources":["../../src/test/wohumi.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,IAAI,MAAc,CAAA;IAClB,IAAI,cAAwC,CAAA;IAC5C,IAAI,SAA8B,CAAA;IAElC,UAAU,CAAC,GAAG,EAAE;QACd,cAAc,GAAG,EAA8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cAAc,CAAC,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAA;QAC9D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-switchbot",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.4.2-beta.
|
|
4
|
+
"version": "3.4.2-beta.3",
|
|
5
5
|
"description": "The node-switchbot is a Node.js module which allows you to control your Switchbot Devices through Bluetooth (BLE).",
|
|
6
6
|
"author": "OpenWonderLabs (https://github.com/OpenWonderLabs)",
|
|
7
7
|
"license": "MIT",
|