node-switchbot 2.5.0-beta.1 → 2.5.0-beta.10
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/advertising.d.ts +32 -15
- package/dist/advertising.d.ts.map +1 -1
- package/dist/advertising.js +72 -72
- package/dist/advertising.js.map +1 -1
- package/dist/device/woblindtilt.d.ts +19 -50
- package/dist/device/woblindtilt.d.ts.map +1 -1
- package/dist/device/woblindtilt.js +39 -98
- package/dist/device/woblindtilt.js.map +1 -1
- package/dist/device/wobulb.d.ts +41 -15
- package/dist/device/wobulb.d.ts.map +1 -1
- package/dist/device/wobulb.js +71 -127
- package/dist/device/wobulb.js.map +1 -1
- package/dist/device/woceilinglight.d.ts +47 -21
- package/dist/device/woceilinglight.d.ts.map +1 -1
- package/dist/device/woceilinglight.js +94 -169
- package/dist/device/woceilinglight.js.map +1 -1
- package/dist/device/wocontact.d.ts +11 -1
- package/dist/device/wocontact.d.ts.map +1 -1
- package/dist/device/wocontact.js +22 -21
- package/dist/device/wocontact.js.map +1 -1
- package/dist/device/wocurtain.d.ts +39 -1
- package/dist/device/wocurtain.d.ts.map +1 -1
- package/dist/device/wocurtain.js +68 -102
- package/dist/device/wocurtain.js.map +1 -1
- package/dist/device/wohand.d.ts +37 -2
- package/dist/device/wohand.d.ts.map +1 -1
- package/dist/device/wohand.js +54 -88
- package/dist/device/wohand.js.map +1 -1
- package/dist/device/wohub2.d.ts +11 -1
- package/dist/device/wohub2.d.ts.map +1 -1
- package/dist/device/wohub2.js +22 -22
- package/dist/device/wohub2.js.map +1 -1
- package/dist/device/wohumi.d.ts +37 -2
- package/dist/device/wohumi.d.ts.map +1 -1
- package/dist/device/wohumi.js +51 -82
- package/dist/device/wohumi.js.map +1 -1
- package/dist/device/woiosensorth.d.ts +12 -1
- package/dist/device/woiosensorth.d.ts.map +1 -1
- package/dist/device/woiosensorth.js +26 -22
- package/dist/device/woiosensorth.js.map +1 -1
- package/dist/device/woplugmini.d.ts +45 -12
- package/dist/device/woplugmini.d.ts.map +1 -1
- package/dist/device/woplugmini.js +69 -75
- package/dist/device/woplugmini.js.map +1 -1
- package/dist/device/wopresence.d.ts +11 -1
- package/dist/device/wopresence.d.ts.map +1 -1
- package/dist/device/wopresence.js +20 -26
- package/dist/device/wopresence.js.map +1 -1
- package/dist/device/wosensorth.d.ts +18 -2
- package/dist/device/wosensorth.d.ts.map +1 -1
- package/dist/device/wosensorth.js +34 -40
- package/dist/device/wosensorth.js.map +1 -1
- package/dist/device/wosmartlock.d.ts +56 -13
- package/dist/device/wosmartlock.d.ts.map +1 -1
- package/dist/device/wosmartlock.js +106 -194
- package/dist/device/wosmartlock.js.map +1 -1
- package/dist/device/wosmartlockpro.d.ts +61 -18
- package/dist/device/wosmartlockpro.d.ts.map +1 -1
- package/dist/device/wosmartlockpro.js +114 -203
- package/dist/device/wosmartlockpro.js.map +1 -1
- package/dist/device/wostrip.d.ts +37 -18
- package/dist/device/wostrip.d.ts.map +1 -1
- package/dist/device/wostrip.js +78 -124
- package/dist/device/wostrip.js.map +1 -1
- package/dist/device.d.ts +86 -223
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +123 -407
- package/dist/device.js.map +1 -1
- package/dist/parameter-checker.d.ts +78 -18
- package/dist/parameter-checker.d.ts.map +1 -1
- package/dist/parameter-checker.js +139 -334
- package/dist/parameter-checker.js.map +1 -1
- package/dist/settings.d.ts +23 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +23 -2
- package/dist/settings.js.map +1 -1
- package/dist/switchbot.d.ts +67 -35
- package/dist/switchbot.d.ts.map +1 -1
- package/dist/switchbot.js +182 -380
- package/dist/switchbot.js.map +1 -1
- package/dist/test/woblindtilt.test.d.ts.map +1 -0
- package/dist/test/woblindtilt.test.js +93 -0
- package/dist/test/woblindtilt.test.js.map +1 -0
- package/dist/{device → test}/wobulb.test.d.ts.map +1 -1
- package/dist/test/wobulb.test.js +100 -0
- package/dist/test/wobulb.test.js.map +1 -0
- package/dist/test/woceilinglight.test.d.ts.map +1 -0
- package/dist/test/woceilinglight.test.js +91 -0
- package/dist/test/woceilinglight.test.js.map +1 -0
- package/dist/test/wocontact.test.d.ts.map +1 -0
- package/dist/test/wocontact.test.js +34 -0
- package/dist/test/wocontact.test.js.map +1 -0
- package/dist/test/wocurtain.test.d.ts.map +1 -0
- package/dist/test/wocurtain.test.js +72 -0
- package/dist/test/wocurtain.test.js.map +1 -0
- package/dist/{device → test}/wohand.test.d.ts.map +1 -1
- package/dist/test/wohand.test.js +72 -0
- package/dist/test/wohand.test.js.map +1 -0
- package/dist/test/wohub2.test.d.ts +2 -0
- package/dist/test/wohub2.test.d.ts.map +1 -0
- package/dist/{device/wohand2.test.js → test/wohub2.test.js} +6 -4
- package/dist/test/wohub2.test.js.map +1 -0
- package/dist/{device → test}/wohumi.test.d.ts.map +1 -1
- package/dist/{device → test}/wohumi.test.js +1 -2
- package/dist/test/wohumi.test.js.map +1 -0
- package/dist/test/woiosensorth.test.d.ts.map +1 -0
- package/dist/{device → test}/woiosensorth.test.js +7 -5
- package/dist/test/woiosensorth.test.js.map +1 -0
- package/dist/test/woplugmini.test.d.ts.map +1 -0
- package/dist/{device → test}/woplugmini.test.js +6 -5
- package/dist/test/woplugmini.test.js.map +1 -0
- package/dist/test/wopresence.test.d.ts.map +1 -0
- package/dist/{device → test}/wopresence.test.js +1 -1
- package/dist/test/wopresence.test.js.map +1 -0
- package/dist/test/wosensorth.test.d.ts.map +1 -0
- package/dist/{device → test}/wosensorth.test.js +3 -4
- package/dist/test/wosensorth.test.js.map +1 -0
- package/dist/test/wosmartlock.test.d.ts.map +1 -0
- package/dist/test/wosmartlock.test.js +143 -0
- package/dist/test/wosmartlock.test.js.map +1 -0
- package/dist/test/wosmartlockpro.test.d.ts.map +1 -0
- package/dist/{device → test}/wosmartlockpro.test.js +26 -26
- package/dist/test/wosmartlockpro.test.js.map +1 -0
- package/dist/{device → test}/wostrip.test.d.ts.map +1 -1
- package/dist/{device → test}/wostrip.test.js +18 -19
- package/dist/test/wostrip.test.js.map +1 -0
- package/dist/types/types.d.ts +52 -120
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/device/woblindtilt.test.d.ts.map +0 -1
- package/dist/device/woblindtilt.test.js +0 -26
- package/dist/device/woblindtilt.test.js.map +0 -1
- package/dist/device/wobulb.test.js +0 -52
- package/dist/device/wobulb.test.js.map +0 -1
- package/dist/device/woceilinglight.test.d.ts.map +0 -1
- package/dist/device/woceilinglight.test.js +0 -63
- package/dist/device/woceilinglight.test.js.map +0 -1
- package/dist/device/wocontact.test.d.ts.map +0 -1
- package/dist/device/wocontact.test.js +0 -34
- package/dist/device/wocontact.test.js.map +0 -1
- package/dist/device/wocurtain.test.d.ts.map +0 -1
- package/dist/device/wocurtain.test.js +0 -33
- package/dist/device/wocurtain.test.js.map +0 -1
- package/dist/device/wohand.test.js +0 -62
- package/dist/device/wohand.test.js.map +0 -1
- package/dist/device/wohand2.test.d.ts +0 -2
- package/dist/device/wohand2.test.d.ts.map +0 -1
- package/dist/device/wohand2.test.js.map +0 -1
- package/dist/device/wohumi.test.js.map +0 -1
- package/dist/device/woiosensorth.test.d.ts.map +0 -1
- package/dist/device/woiosensorth.test.js.map +0 -1
- package/dist/device/woplugmini.test.d.ts.map +0 -1
- package/dist/device/woplugmini.test.js.map +0 -1
- package/dist/device/wopresence.test.d.ts.map +0 -1
- package/dist/device/wopresence.test.js.map +0 -1
- package/dist/device/wosensorth.test.d.ts.map +0 -1
- package/dist/device/wosensorth.test.js.map +0 -1
- package/dist/device/wosmartlock.test.d.ts.map +0 -1
- package/dist/device/wosmartlock.test.js +0 -84
- package/dist/device/wosmartlock.test.js.map +0 -1
- package/dist/device/wosmartlockpro.test.d.ts.map +0 -1
- package/dist/device/wosmartlockpro.test.js.map +0 -1
- package/dist/device/wostrip.test.js.map +0 -1
- /package/dist/{device → test}/woblindtilt.test.d.ts +0 -0
- /package/dist/{device → test}/wobulb.test.d.ts +0 -0
- /package/dist/{device → test}/woceilinglight.test.d.ts +0 -0
- /package/dist/{device → test}/wocontact.test.d.ts +0 -0
- /package/dist/{device → test}/wocurtain.test.d.ts +0 -0
- /package/dist/{device → test}/wohand.test.d.ts +0 -0
- /package/dist/{device → test}/wohumi.test.d.ts +0 -0
- /package/dist/{device → test}/woiosensorth.test.d.ts +0 -0
- /package/dist/{device → test}/woplugmini.test.d.ts +0 -0
- /package/dist/{device → test}/wopresence.test.d.ts +0 -0
- /package/dist/{device → test}/wosensorth.test.d.ts +0 -0
- /package/dist/{device → test}/wosmartlock.test.d.ts +0 -0
- /package/dist/{device → test}/wosmartlockpro.test.d.ts +0 -0
- /package/dist/{device → test}/wostrip.test.d.ts +0 -0
|
@@ -1,130 +1,106 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
1
|
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
3
2
|
*
|
|
4
3
|
* woblindtilt.ts: Switchbot BLE API registration.
|
|
5
4
|
*/
|
|
5
|
+
import { Buffer } from 'node:buffer';
|
|
6
6
|
import { SwitchbotDevice } from '../device.js';
|
|
7
7
|
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Class representing a WoBlindTilt device.
|
|
10
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/curtain.md
|
|
11
|
+
*/
|
|
8
12
|
export class WoBlindTilt extends SwitchbotDevice {
|
|
9
13
|
_reverse = false;
|
|
10
14
|
/**
|
|
11
15
|
* Parses the service data and manufacturer data for the WoBlindTilt device.
|
|
12
|
-
*
|
|
13
16
|
* @param {Buffer} serviceData - The service data buffer.
|
|
14
17
|
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
15
18
|
* @param {(message: string) => void} [onlog] - Optional logging function.
|
|
16
19
|
* @param {boolean} [reverse] - Whether to reverse the tilt percentage.
|
|
17
|
-
* @returns {object | null} The parsed data object or null if the data is invalid.
|
|
20
|
+
* @returns {Promise<object | null>} - The parsed data object or null if the data is invalid.
|
|
18
21
|
*/
|
|
19
22
|
static async parseServiceData(serviceData, manufacturerData, onlog, reverse = false) {
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
onlog(`[parseServiceDataForWoBlindTilt] Buffer length ${manufacturerData.length} !== 5 or 6!`);
|
|
23
|
-
}
|
|
23
|
+
if (![5, 6].includes(manufacturerData.length)) {
|
|
24
|
+
onlog?.(`[parseServiceDataForWoBlindTilt] Buffer length ${manufacturerData.length} !== 5 or 6!`);
|
|
24
25
|
return null;
|
|
25
26
|
}
|
|
26
|
-
// const byte1 = serviceData.readUInt8(1)
|
|
27
27
|
const byte2 = serviceData.readUInt8(2);
|
|
28
28
|
const byte6 = manufacturerData.subarray(6);
|
|
29
|
-
const tilt = Math.max(Math.min(byte6.readUInt8(2) & 0b01111111, 100), 0);
|
|
29
|
+
const tilt = Math.max(Math.min(byte6.readUInt8(2) & 0b01111111, 100), 0);
|
|
30
30
|
const inMotion = !!(byte2 & 0b10000000);
|
|
31
|
-
const lightLevel = (byte6.readUInt8(1) >> 4) & 0b00001111;
|
|
32
|
-
const calibration = !!(byte6.readUInt8(1) & 0b00000001);
|
|
31
|
+
const lightLevel = (byte6.readUInt8(1) >> 4) & 0b00001111;
|
|
32
|
+
const calibration = !!(byte6.readUInt8(1) & 0b00000001);
|
|
33
33
|
const sequenceNumber = byte6.readUInt8(0);
|
|
34
34
|
const battery = serviceData.length > 2 ? byte2 & 0b01111111 : null;
|
|
35
|
-
|
|
35
|
+
return {
|
|
36
36
|
model: SwitchBotBLEModel.BlindTilt,
|
|
37
37
|
modelName: SwitchBotBLEModelName.BlindTilt,
|
|
38
38
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.BlindTilt,
|
|
39
39
|
calibration,
|
|
40
40
|
battery,
|
|
41
41
|
inMotion,
|
|
42
|
-
tilt: reverse ?
|
|
42
|
+
tilt: reverse ? 100 - tilt : tilt,
|
|
43
43
|
lightLevel,
|
|
44
44
|
sequenceNumber,
|
|
45
45
|
};
|
|
46
|
-
return data;
|
|
47
46
|
}
|
|
48
47
|
/**
|
|
49
|
-
* open
|
|
50
|
-
*
|
|
51
48
|
* Opens the blind tilt to the fully open position.
|
|
52
|
-
*
|
|
53
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
49
|
+
* @returns {Promise<void>}
|
|
54
50
|
*/
|
|
55
51
|
async open() {
|
|
56
|
-
|
|
52
|
+
await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x32]);
|
|
57
53
|
}
|
|
58
54
|
/**
|
|
59
|
-
* closeUp
|
|
60
|
-
*
|
|
61
55
|
* Closes the blind tilt up to the nearest endpoint.
|
|
62
|
-
*
|
|
63
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
56
|
+
* @returns {Promise<void>}
|
|
64
57
|
*/
|
|
65
58
|
async closeUp() {
|
|
66
|
-
|
|
59
|
+
await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x64]);
|
|
67
60
|
}
|
|
68
61
|
/**
|
|
69
|
-
* closeDown
|
|
70
|
-
*
|
|
71
62
|
* Closes the blind tilt down to the nearest endpoint.
|
|
72
|
-
*
|
|
73
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
63
|
+
* @returns {Promise<void>}
|
|
74
64
|
*/
|
|
75
65
|
async closeDown() {
|
|
76
|
-
|
|
66
|
+
await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, 0xFF, 0x00]);
|
|
77
67
|
}
|
|
78
68
|
/**
|
|
79
|
-
* close
|
|
80
|
-
*
|
|
81
69
|
* Closes the blind tilt to the nearest endpoint.
|
|
82
|
-
*
|
|
83
|
-
* @returns {Promise<void>} - A promise that resolves when the operation is complete. Nothing will be passed to the `resolve()`.
|
|
70
|
+
* @returns {Promise<void>}
|
|
84
71
|
*/
|
|
85
72
|
async close() {
|
|
86
73
|
const position = await this.getPosition();
|
|
87
74
|
if (position > 50) {
|
|
88
|
-
|
|
75
|
+
await this.closeUp();
|
|
89
76
|
}
|
|
90
77
|
else {
|
|
91
|
-
|
|
78
|
+
await this.closeDown();
|
|
92
79
|
}
|
|
93
80
|
}
|
|
94
81
|
/**
|
|
95
|
-
* getPosition
|
|
96
|
-
*
|
|
97
82
|
* Retrieves the current position of the blind tilt.
|
|
98
|
-
*
|
|
99
|
-
* @returns {number} - The current position of the blind tilt (0-100).
|
|
83
|
+
* @returns {Promise<number>} - The current position of the blind tilt (0-100).
|
|
100
84
|
*/
|
|
101
85
|
async getPosition() {
|
|
102
|
-
// Retrieve the current tilt position using the _getAdvValue method
|
|
103
86
|
const tiltPosition = await this._getAdvValue('tilt');
|
|
104
|
-
// Ensure the tilt position is within the valid range (0-100)
|
|
105
87
|
return Math.max(0, Math.min(tiltPosition, 100));
|
|
106
88
|
}
|
|
107
89
|
/**
|
|
108
|
-
* _getAdvValue
|
|
109
|
-
*
|
|
110
90
|
* Retrieves the advertised value for a given key.
|
|
111
|
-
*
|
|
112
91
|
* @param {string} key - The key for the advertised value.
|
|
113
92
|
* @returns {Promise<number>} - The advertised value.
|
|
93
|
+
* @private
|
|
114
94
|
*/
|
|
115
95
|
async _getAdvValue(key) {
|
|
116
|
-
// Mock implementation, replace with actual logic to retrieve the advertised value
|
|
117
96
|
if (key === 'tilt') {
|
|
118
97
|
return 50; // Example value
|
|
119
98
|
}
|
|
120
99
|
throw new Error(`Unknown key: ${key}`);
|
|
121
100
|
}
|
|
122
101
|
/**
|
|
123
|
-
* getBasicInfo
|
|
124
|
-
*
|
|
125
102
|
* Retrieves the basic information of the blind tilt.
|
|
126
|
-
*
|
|
127
|
-
* @returns {Promise<object>} - A promise that resolves to an object containing the basic information of the blind tilt.
|
|
103
|
+
* @returns {Promise<object | null>} - A promise that resolves to an object containing the basic information of the blind tilt.
|
|
128
104
|
*/
|
|
129
105
|
async getBasicInfo() {
|
|
130
106
|
const data = await this.getBasicInfo();
|
|
@@ -168,73 +144,38 @@ export class WoBlindTilt extends SwitchbotDevice {
|
|
|
168
144
|
}
|
|
169
145
|
/**
|
|
170
146
|
* Pauses the blind tilt operation.
|
|
171
|
-
*
|
|
172
|
-
* This method sends a command to pause the current operation of the blind tilt.
|
|
173
|
-
*
|
|
174
|
-
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
175
|
-
* No value is passed to the `resolve()` function.
|
|
147
|
+
* @returns {Promise<void>}
|
|
176
148
|
*/
|
|
177
149
|
async pause() {
|
|
178
150
|
await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x00, 0xFF]);
|
|
179
151
|
}
|
|
180
152
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* This method sends a command to run the blind tilt to the specified position.
|
|
184
|
-
*
|
|
153
|
+
* Runs the blind tilt to the specified position.
|
|
185
154
|
* @param {number} percent - The target position percentage (0-100).
|
|
186
155
|
* @param {number} mode - The running mode (0 or 1).
|
|
187
|
-
* @returns {Promise<void>}
|
|
156
|
+
* @returns {Promise<void>}
|
|
188
157
|
*/
|
|
189
158
|
async runToPos(percent, mode) {
|
|
190
|
-
if (typeof percent !== 'number') {
|
|
191
|
-
throw new
|
|
159
|
+
if (typeof percent !== 'number' || percent < 0 || percent > 100) {
|
|
160
|
+
throw new RangeError('Percent must be a number between 0 and 100');
|
|
192
161
|
}
|
|
193
|
-
if (mode
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
if (typeof mode !== 'number') {
|
|
198
|
-
throw new TypeError(`The type of running mode is incorrect: ${typeof mode}`);
|
|
199
|
-
}
|
|
200
|
-
if (mode > 1) {
|
|
201
|
-
mode = 0xFF;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (percent > 100) {
|
|
205
|
-
percent = 100;
|
|
206
|
-
}
|
|
207
|
-
else if (percent < 0) {
|
|
208
|
-
percent = 0;
|
|
162
|
+
if (typeof mode !== 'number' || mode < 0 || mode > 1) {
|
|
163
|
+
throw new RangeError('Mode must be a number between 0 and 1');
|
|
209
164
|
}
|
|
210
165
|
await this.operateBlindTilt([0x57, 0x0F, 0x45, 0x01, 0x05, mode, percent]);
|
|
211
166
|
}
|
|
212
167
|
/**
|
|
213
168
|
* Sends a command to operate the blind tilt and handles the response.
|
|
214
|
-
*
|
|
215
|
-
* This method constructs a buffer from the provided byte array and sends it as a command to the device.
|
|
216
|
-
* It returns a promise that resolves if the device responds with a success code (0x01) and rejects if the device
|
|
217
|
-
* returns an error or if the command fails.
|
|
218
|
-
*
|
|
219
169
|
* @param {number[]} bytes - The byte array representing the command to be sent to the device.
|
|
220
|
-
* @returns {Promise<void>}
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* @throws {Error} Throws an error if the device returns an error code or if the command fails.
|
|
170
|
+
* @returns {Promise<void>}
|
|
171
|
+
* @private
|
|
224
172
|
*/
|
|
225
173
|
async operateBlindTilt(bytes) {
|
|
226
|
-
const
|
|
227
|
-
this.command(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
throw new Error(`The device returned an error: 0x${res_buf.toString('hex')}`);
|
|
234
|
-
}
|
|
235
|
-
}).catch((error) => {
|
|
236
|
-
throw error;
|
|
237
|
-
});
|
|
174
|
+
const reqBuf = Buffer.from(bytes);
|
|
175
|
+
const resBuf = await this.command(reqBuf);
|
|
176
|
+
if (resBuf.length !== 3 || resBuf.readUInt8(0) !== 0x01) {
|
|
177
|
+
throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
|
|
178
|
+
}
|
|
238
179
|
}
|
|
239
180
|
}
|
|
240
181
|
//# sourceMappingURL=woblindtilt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"woblindtilt.js","sourceRoot":"","sources":["../../src/device/woblindtilt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC
|
|
1
|
+
{"version":3,"file":"woblindtilt.js","sourceRoot":"","sources":["../../src/device/woblindtilt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,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,WAAY,SAAQ,eAAe;IACtC,QAAQ,GAAY,KAAK,CAAA;IAEjC;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAC3B,WAAmB,EACnB,gBAAwB,EACxB,KAAiC,EACjC,UAAmB,KAAK;QAExB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9C,KAAK,EAAE,CAAC,kDAAkD,gBAAgB,CAAC,MAAM,cAAc,CAAC,CAAA;YAChG,OAAO,IAAI,CAAA;QACb,CAAC;QAED,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QACtC,MAAM,KAAK,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;QAE1C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,UAAU,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;QACxE,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,CAAA;QACv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C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC9E,CAAC;IACH,CAAC;CACF"}
|
package/dist/device/wobulb.d.ts
CHANGED
|
@@ -1,41 +1,67 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { SwitchbotDevice } from '../device.js';
|
|
3
3
|
/**
|
|
4
|
+
* Class representing a WoBulb device.
|
|
4
5
|
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
|
|
5
6
|
*/
|
|
6
7
|
export declare class WoBulb extends SwitchbotDevice {
|
|
7
|
-
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, onlog: ((message: string) => void) | undefined): Promise<object | null>;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Parses the service data for WoBulb.
|
|
10
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
11
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
12
|
+
* @param {Function} [onlog] - Optional logging function.
|
|
13
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
10
14
|
*/
|
|
11
|
-
|
|
15
|
+
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, onlog?: (message: string) => void): Promise<object | null>;
|
|
12
16
|
/**
|
|
17
|
+
* Reads the state of the bulb.
|
|
18
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true) or OFF (false).
|
|
19
|
+
*/
|
|
20
|
+
readState(): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Sets the state of the bulb.
|
|
23
|
+
* @param {number[]} reqByteArray - The request byte array.
|
|
24
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
13
25
|
* @private
|
|
14
26
|
*/
|
|
15
|
-
setState(reqByteArray: number[]): Promise<
|
|
27
|
+
setState(reqByteArray: number[]): Promise<boolean>;
|
|
16
28
|
/**
|
|
17
|
-
*
|
|
29
|
+
* Turns on the bulb.
|
|
30
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true).
|
|
18
31
|
*/
|
|
19
|
-
turnOn(): Promise<
|
|
32
|
+
turnOn(): Promise<boolean>;
|
|
20
33
|
/**
|
|
21
|
-
*
|
|
34
|
+
* Turns off the bulb.
|
|
35
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is OFF (false).
|
|
22
36
|
*/
|
|
23
|
-
turnOff(): Promise<
|
|
37
|
+
turnOff(): Promise<boolean>;
|
|
24
38
|
/**
|
|
25
|
-
*
|
|
39
|
+
* Sets the brightness of the bulb.
|
|
40
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
41
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
26
42
|
*/
|
|
27
|
-
setBrightness(brightness: number): Promise<
|
|
43
|
+
setBrightness(brightness: number): Promise<boolean>;
|
|
28
44
|
/**
|
|
29
|
-
*
|
|
45
|
+
* Sets the color temperature of the bulb.
|
|
46
|
+
* @param {number} color_temperature - The color temperature percentage (0-100).
|
|
47
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
30
48
|
*/
|
|
31
|
-
setColorTemperature(color_temperature: number): Promise<
|
|
49
|
+
setColorTemperature(color_temperature: number): Promise<boolean>;
|
|
32
50
|
/**
|
|
33
|
-
*
|
|
51
|
+
* Sets the RGB color of the bulb.
|
|
52
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
53
|
+
* @param {number} red - The red color value (0-255).
|
|
54
|
+
* @param {number} green - The green color value (0-255).
|
|
55
|
+
* @param {number} blue - The blue color value (0-255).
|
|
56
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
34
57
|
*/
|
|
35
|
-
setRGB(brightness: number, red: number, green: number, blue: number): Promise<
|
|
58
|
+
setRGB(brightness: number, red: number, green: number, blue: number): Promise<boolean>;
|
|
36
59
|
/**
|
|
60
|
+
* Sends a command to the bulb.
|
|
61
|
+
* @param {number[]} bytes - The command bytes.
|
|
62
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
37
63
|
* @private
|
|
38
64
|
*/
|
|
39
|
-
operateBulb
|
|
65
|
+
private operateBulb;
|
|
40
66
|
}
|
|
41
67
|
//# sourceMappingURL=wobulb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wobulb.d.ts","sourceRoot":"","sources":["../../src/device/wobulb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wobulb.d.ts","sourceRoot":"","sources":["../../src/device/wobulb.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C;;;GAGG;AACH,qBAAa,MAAO,SAAQ,eAAe;IACzC;;;;;;OAMG;WACU,gBAAgB,CAC3B,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAChC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAyCzB;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC;;;;;OAKG;IACU,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAK/D;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAIhC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC;;;;OAIG;IACG,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOzD;;;;OAIG;IACG,mBAAmB,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOtE;;;;;;;OAOG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAO5F;;;;;OAKG;YACW,WAAW;CAY1B"}
|
package/dist/device/wobulb.js
CHANGED
|
@@ -1,190 +1,134 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
1
|
/* Copyright(C) 2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
3
2
|
*
|
|
4
3
|
* wobulb.ts: Switchbot BLE API registration.
|
|
5
4
|
*/
|
|
5
|
+
import { Buffer } from 'node:buffer';
|
|
6
6
|
import { SwitchbotDevice } from '../device.js';
|
|
7
7
|
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
8
8
|
/**
|
|
9
|
+
* Class representing a WoBulb device.
|
|
9
10
|
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
|
|
10
11
|
*/
|
|
11
12
|
export class WoBulb extends SwitchbotDevice {
|
|
13
|
+
/**
|
|
14
|
+
* Parses the service data for WoBulb.
|
|
15
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
16
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
17
|
+
* @param {Function} [onlog] - Optional logging function.
|
|
18
|
+
* @returns {Promise<object | null>} - Parsed service data or null if invalid.
|
|
19
|
+
*/
|
|
12
20
|
static async parseServiceData(serviceData, manufacturerData, onlog) {
|
|
13
21
|
if (serviceData.length !== 18) {
|
|
14
|
-
|
|
15
|
-
onlog(`[parseServiceDataForWoBulb] Buffer length ${serviceData.length} !== 18!`);
|
|
16
|
-
}
|
|
22
|
+
onlog?.(`[parseServiceDataForWoBulb] Buffer length ${serviceData.length} !== 18!`);
|
|
17
23
|
return null;
|
|
18
24
|
}
|
|
19
25
|
if (manufacturerData.length !== 13) {
|
|
20
|
-
|
|
21
|
-
onlog(`[parseServiceDataForWoBulb] Buffer length ${manufacturerData.length} !== 13!`);
|
|
22
|
-
}
|
|
26
|
+
onlog?.(`[parseServiceDataForWoBulb] Buffer length ${manufacturerData.length} !== 13!`);
|
|
23
27
|
return null;
|
|
24
28
|
}
|
|
25
|
-
const byte1
|
|
26
|
-
|
|
27
|
-
const byte3 = manufacturerData.readUInt8(3); // bulb R
|
|
28
|
-
const byte4 = manufacturerData.readUInt8(4); // bulb G
|
|
29
|
-
const byte5 = manufacturerData.readUInt8(5); // bulb B
|
|
30
|
-
const byte6 = manufacturerData.readUInt8(6); // bulb temperature
|
|
31
|
-
const byte7 = manufacturerData.readUInt8(7);
|
|
32
|
-
const byte8 = manufacturerData.readUInt8(8);
|
|
33
|
-
const byte9 = manufacturerData.readUInt8(9);
|
|
34
|
-
const byte10 = manufacturerData.readUInt8(10); // bulb mode
|
|
35
|
-
const power = byte1;
|
|
36
|
-
const red = byte3;
|
|
37
|
-
const green = byte4;
|
|
38
|
-
const blue = byte5;
|
|
39
|
-
const color_temperature = byte6;
|
|
40
|
-
const state = !!(byte7 & 0b01111111);
|
|
41
|
-
const brightness = byte7 & 0b01111111;
|
|
42
|
-
const delay = byte8 & 0b10000000;
|
|
43
|
-
const preset = byte8 & 0b00001000;
|
|
44
|
-
const color_mode = byte8 & 0b00000111;
|
|
45
|
-
const speed = byte9 & 0b01111111;
|
|
46
|
-
const loop_index = byte10 & 0b11111110;
|
|
47
|
-
const data = {
|
|
29
|
+
const [, byte1, , byte3, byte4, byte5, byte6, byte7, byte8, byte9, byte10,] = manufacturerData;
|
|
30
|
+
return {
|
|
48
31
|
model: SwitchBotBLEModel.ColorBulb,
|
|
49
32
|
modelName: SwitchBotBLEModelName.ColorBulb,
|
|
50
33
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.ColorBulb,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
brightness,
|
|
58
|
-
delay,
|
|
59
|
-
preset,
|
|
60
|
-
color_mode,
|
|
61
|
-
speed,
|
|
62
|
-
loop_index,
|
|
34
|
+
power: byte1,
|
|
35
|
+
red: byte3,
|
|
36
|
+
green: byte4,
|
|
37
|
+
blue: byte5,
|
|
38
|
+
color_temperature: byte6,
|
|
39
|
+
state: !!(byte7 & 0b01111111),
|
|
40
|
+
brightness: byte7 & 0b01111111,
|
|
41
|
+
delay: !!(byte8 & 0b10000000),
|
|
42
|
+
preset: !!(byte8 & 0b00001000),
|
|
43
|
+
color_mode: byte8 & 0b00000111,
|
|
44
|
+
speed: byte9 & 0b01111111,
|
|
45
|
+
loop_index: byte10 & 0b11111110,
|
|
63
46
|
};
|
|
64
|
-
return data;
|
|
65
47
|
}
|
|
66
48
|
/**
|
|
67
|
-
*
|
|
49
|
+
* Reads the state of the bulb.
|
|
50
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true) or OFF (false).
|
|
68
51
|
*/
|
|
69
52
|
async readState() {
|
|
70
|
-
return
|
|
53
|
+
return this.operateBulb([0x57, 0x0F, 0x48, 0x01]);
|
|
71
54
|
}
|
|
72
55
|
/**
|
|
56
|
+
* Sets the state of the bulb.
|
|
57
|
+
* @param {number[]} reqByteArray - The request byte array.
|
|
58
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
73
59
|
* @private
|
|
74
60
|
*/
|
|
75
61
|
async setState(reqByteArray) {
|
|
76
62
|
const base = [0x57, 0x0F, 0x47, 0x01];
|
|
77
|
-
return
|
|
63
|
+
return this.operateBulb(base.concat(reqByteArray));
|
|
78
64
|
}
|
|
79
65
|
/**
|
|
80
|
-
*
|
|
66
|
+
* Turns on the bulb.
|
|
67
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true).
|
|
81
68
|
*/
|
|
82
69
|
async turnOn() {
|
|
83
|
-
return
|
|
70
|
+
return this.setState([0x01, 0x01]);
|
|
84
71
|
}
|
|
85
72
|
/**
|
|
86
|
-
*
|
|
73
|
+
* Turns off the bulb.
|
|
74
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is OFF (false).
|
|
87
75
|
*/
|
|
88
76
|
async turnOff() {
|
|
89
|
-
return
|
|
77
|
+
return this.setState([0x01, 0x02]);
|
|
90
78
|
}
|
|
91
79
|
/**
|
|
92
|
-
*
|
|
80
|
+
* Sets the brightness of the bulb.
|
|
81
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
82
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
93
83
|
*/
|
|
94
84
|
async setBrightness(brightness) {
|
|
95
|
-
if (
|
|
96
|
-
throw new
|
|
85
|
+
if (brightness < 0 || brightness > 100) {
|
|
86
|
+
throw new RangeError('Brightness must be between 0 and 100');
|
|
97
87
|
}
|
|
98
|
-
|
|
99
|
-
brightness = 100;
|
|
100
|
-
}
|
|
101
|
-
else if (brightness < 0) {
|
|
102
|
-
brightness = 0;
|
|
103
|
-
}
|
|
104
|
-
return await this.setState([0x02, 0x14, brightness]);
|
|
88
|
+
return this.setState([0x02, 0x14, brightness]);
|
|
105
89
|
}
|
|
106
90
|
/**
|
|
107
|
-
*
|
|
91
|
+
* Sets the color temperature of the bulb.
|
|
92
|
+
* @param {number} color_temperature - The color temperature percentage (0-100).
|
|
93
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
108
94
|
*/
|
|
109
95
|
async setColorTemperature(color_temperature) {
|
|
110
|
-
if (
|
|
111
|
-
throw new
|
|
112
|
-
}
|
|
113
|
-
else if (color_temperature > 100) {
|
|
114
|
-
color_temperature = 100;
|
|
96
|
+
if (color_temperature < 0 || color_temperature > 100) {
|
|
97
|
+
throw new RangeError('Color temperature must be between 0 and 100');
|
|
115
98
|
}
|
|
116
|
-
|
|
117
|
-
color_temperature = 0;
|
|
118
|
-
}
|
|
119
|
-
return await this.setState([0x02, 0x17, color_temperature]);
|
|
99
|
+
return this.setState([0x02, 0x17, color_temperature]);
|
|
120
100
|
}
|
|
121
101
|
/**
|
|
122
|
-
*
|
|
102
|
+
* Sets the RGB color of the bulb.
|
|
103
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
104
|
+
* @param {number} red - The red color value (0-255).
|
|
105
|
+
* @param {number} green - The green color value (0-255).
|
|
106
|
+
* @param {number} blue - The blue color value (0-255).
|
|
107
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
123
108
|
*/
|
|
124
109
|
async setRGB(brightness, red, green, blue) {
|
|
125
|
-
if (
|
|
126
|
-
throw new
|
|
127
|
-
}
|
|
128
|
-
if (typeof red !== 'number') {
|
|
129
|
-
throw new TypeError(`The type of target red is incorrect: ${typeof red}`);
|
|
130
|
-
}
|
|
131
|
-
if (typeof green !== 'number') {
|
|
132
|
-
throw new TypeError(`The type of target green is incorrect: ${typeof green}`);
|
|
110
|
+
if (brightness < 0 || brightness > 100 || red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) {
|
|
111
|
+
throw new RangeError('Invalid RGB or brightness values');
|
|
133
112
|
}
|
|
134
|
-
|
|
135
|
-
throw new TypeError(`The type of target blue is incorrect: ${typeof blue}`);
|
|
136
|
-
}
|
|
137
|
-
if (brightness > 100) {
|
|
138
|
-
brightness = 100;
|
|
139
|
-
}
|
|
140
|
-
else if (brightness < 0) {
|
|
141
|
-
brightness = 0;
|
|
142
|
-
}
|
|
143
|
-
if (red > 255) {
|
|
144
|
-
red = 255;
|
|
145
|
-
}
|
|
146
|
-
else if (red < 0) {
|
|
147
|
-
red = 0;
|
|
148
|
-
}
|
|
149
|
-
if (green > 255) {
|
|
150
|
-
green = 255;
|
|
151
|
-
}
|
|
152
|
-
else if (green < 0) {
|
|
153
|
-
green = 0;
|
|
154
|
-
}
|
|
155
|
-
if (blue > 255) {
|
|
156
|
-
blue = 255;
|
|
157
|
-
}
|
|
158
|
-
else if (blue < 0) {
|
|
159
|
-
blue = 0;
|
|
160
|
-
}
|
|
161
|
-
return await this.setState([0x02, 0x12, brightness, red, green, blue]);
|
|
113
|
+
return this.setState([0x02, 0x12, brightness, red, green, blue]);
|
|
162
114
|
}
|
|
163
115
|
/**
|
|
116
|
+
* Sends a command to the bulb.
|
|
117
|
+
* @param {number[]} bytes - The command bytes.
|
|
118
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
164
119
|
* @private
|
|
165
120
|
*/
|
|
166
121
|
async operateBulb(bytes) {
|
|
167
|
-
const
|
|
168
|
-
await this.command(
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
if (code === 0x00 || code === 0x80) {
|
|
174
|
-
const is_on = code === 0x80;
|
|
175
|
-
return is_on;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
throw new Error(`The device returned an error: 0x${res_buf.toString('hex')}`);
|
|
179
|
-
}
|
|
122
|
+
const reqBuf = Buffer.from(bytes);
|
|
123
|
+
const resBuf = await this.command(reqBuf);
|
|
124
|
+
if (resBuf.length === 2) {
|
|
125
|
+
const code = resBuf.readUInt8(1);
|
|
126
|
+
if (code === 0x00 || code === 0x80) {
|
|
127
|
+
return code === 0x80;
|
|
180
128
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
})
|
|
185
|
-
.catch((error) => {
|
|
186
|
-
throw error;
|
|
187
|
-
});
|
|
129
|
+
throw new Error(`The device returned an error: 0x${resBuf.toString('hex')}`);
|
|
130
|
+
}
|
|
131
|
+
throw new Error(`Expecting a 2-byte response, got instead: 0x${resBuf.toString('hex')}`);
|
|
188
132
|
}
|
|
189
133
|
}
|
|
190
134
|
//# sourceMappingURL=wobulb.js.map
|