dh-sdk 0.0.0-stage → 1.0.112601

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 don
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,236 @@
1
- # Temporary Holding Version
1
+ # dh-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ DoneHome BLE SDK — 微信小程序 BLE 模组控制 SDK
4
+
5
+ ## 特性
6
+
7
+ - 🎮 **微信小程序 (mina)** — 原生 wx BLE API
8
+ - 📦 **TypeScript** — 完整类型定义
9
+ - 🔧 **模块化设计** — Scanner / Connector / Provisioner / Auth / Controller
10
+
11
+ ## 安装
12
+
13
+ ```bash
14
+ npm install dh-sdk
15
+ ```
16
+
17
+ ## 快速开始
18
+
19
+ ```javascript
20
+ import { DoneHomeSDK, Scanner, Connector, Controller } from 'dh-sdk';
21
+
22
+ // 1. 初始化 SDK
23
+ const sdk = new DoneHomeSDK({ debug: true });
24
+ await sdk.init();
25
+
26
+ // 2. 使用 Scanner 扫描设备
27
+ const scanner = new Scanner(sdk);
28
+ await scanner.start({ service_uuid: '0000ff01-0000-1000-8000-00805f9b34fb', rssi_min: -80 });
29
+
30
+ // 获取发现的设备列表
31
+ const devices = scanner.getDevices();
32
+ console.log('发现设备:', devices);
33
+ await scanner.stop();
34
+
35
+ // 3. 使用 Connector 连接设备
36
+ const connector = new Connector(sdk);
37
+ await connector.connect(devices[0].deviceId, {
38
+ timeout_ms: 10000,
39
+ auto_reconnect: true,
40
+ reconnect_count: 3,
41
+ });
42
+
43
+ // 4. 使用 Controller 控制设备
44
+ const controller = new Controller(sdk);
45
+ await controller.send_cmd(devices[0].deviceId, {
46
+ code: 0x01,
47
+ payload: new Uint8Array([0x01, 0x02]),
48
+ require_ack: true,
49
+ timeout_ms: 5000,
50
+ });
51
+ ```
52
+
53
+ ## 模块说明
54
+
55
+ ### DoneHomeSDK(核心)
56
+
57
+ 初始化和管理 BLE 适配器,提供底层 BLE 操作。
58
+
59
+ ```javascript
60
+ const sdk = new DoneHomeSDK({ debug: true });
61
+ await sdk.init(); // 自动加载微信小程序适配器
62
+ ```
63
+
64
+ ### Scanner — 设备扫描
65
+
66
+ ```javascript
67
+ const scanner = new Scanner(sdk);
68
+
69
+ // 开始扫描(支持过滤)
70
+ await scanner.start({
71
+ service_uuid: '0000ff01-...', // 按服务 UUID 过滤
72
+ rssi_min: -80, // RSSI 最低值
73
+ });
74
+
75
+ // 获取已发现设备
76
+ const devices = scanner.getDevices();
77
+ // [{ deviceId: '...', name: '...', rssi: -65 }, ...]
78
+
79
+ // 停止扫描
80
+ await scanner.stop();
81
+ ```
82
+
83
+ **方法:**
84
+
85
+ | 方法 | 说明 |
86
+ |------|------|
87
+ | `start(filter?)` | 根据条件开始扫描,发现设备自动追加到列表 |
88
+ | `stop()` | 停止扫描 |
89
+ | `getDevices()` | 获取已发现的设备列表 |
90
+ | `getDevice(deviceId)` | 根据 ID 获取设备信息 |
91
+ | `clearDevices()` | 清空设备列表 |
92
+ | `isScanning()` | 是否正在扫描 |
93
+
94
+ ### Connector — 设备连接
95
+
96
+ ```javascript
97
+ const connector = new Connector(sdk);
98
+
99
+ // 连接设备
100
+ await connector.connect('device_id', {
101
+ timeout_ms: 10000,
102
+ auto_reconnect: true,
103
+ reconnect_count: 3,
104
+ });
105
+
106
+ // 获取连接状态
107
+ const state = connector.get_connect_state('device_id');
108
+ // 'disconnected' | 'connecting' | 'connected' | 'disconnecting'
109
+
110
+ // 断开连接
111
+ await connector.disconnect('device_id');
112
+ ```
113
+
114
+ **方法:**
115
+
116
+ | 方法 | 说明 |
117
+ |------|------|
118
+ | `connect(device_id, options?)` | 连接设备(支持超时、自动重连) |
119
+ | `disconnect(device_id)` | 断开连接 |
120
+ | `get_connect_state(device_id)` | 获取连接状态 |
121
+
122
+ ### Provisioner — 设备配网
123
+
124
+ ```javascript
125
+ const provisioner = new Provisioner(sdk);
126
+
127
+ // 发起配网
128
+ await provisioner.provision('device_id', {
129
+ ssid: 'MyWiFi',
130
+ password: 'password123',
131
+ });
132
+
133
+ // 取消配网
134
+ await provisioner.cancel('device_id');
135
+
136
+ // 获取配网状态
137
+ const state = provisioner.getState('device_id');
138
+ // 'idle' | 'provisioning' | 'success' | 'failed' | 'cancelled'
139
+ ```
140
+
141
+ **方法:**
142
+
143
+ | 方法 | 说明 |
144
+ |------|------|
145
+ | `provision(device_id, payload)` | 向设备发起配网 |
146
+ | `cancel(device_id)` | 取消配网操作 |
147
+ | `getState(device_id)` | 获取配网状态 |
148
+
149
+ ### Auth — 配网认证
150
+
151
+ ```javascript
152
+ const auth = new Auth(sdk);
153
+
154
+ // 发起认证(challenge-response)
155
+ const result = await auth.auth('device_id', {
156
+ key: 'your-secret-key',
157
+ timeout_ms: 10000,
158
+ });
159
+ console.log('session_key:', result.session_key);
160
+
161
+ // 刷新 session key
162
+ await auth.refresh_session('device_id');
163
+
164
+ // 获取缓存的 session
165
+ const session = auth.getSession('device_id');
166
+ ```
167
+
168
+ **方法:**
169
+
170
+ | 方法 | 说明 |
171
+ |------|------|
172
+ | `auth(device_id, options?)` | challenge-response 认证,返回 session_key |
173
+ | `refresh_session(device_id)` | 重置设备 SessionKey |
174
+ | `getSession(device_id)` | 获取缓存的 session |
175
+ | `clearSessions()` | 清除所有 session 缓存 |
176
+
177
+ ### Controller — 设备控制
178
+
179
+ ```javascript
180
+ const controller = new Controller(sdk);
181
+
182
+ // 发送指令(需要 ACK)
183
+ const ack = await controller.send_cmd('device_id', {
184
+ code: 0x01,
185
+ payload: new Uint8Array([0x01, 0x02]),
186
+ encrypt: false,
187
+ require_ack: true,
188
+ timeout_ms: 5000,
189
+ });
190
+
191
+ // 读取特征值
192
+ const data = await controller.read_char('device_id', 'characteristic-uuid');
193
+
194
+ // 写入特征值
195
+ await controller.write_char('device_id', 'characteristic-uuid', new Uint8Array([0x01]));
196
+
197
+ // 订阅特征值通知
198
+ await controller.sub_char('device_id', 'characteristic-uuid', (data) => {
199
+ console.log('收到数据:', new Uint8Array(data));
200
+ });
201
+
202
+ // 取消订阅
203
+ await controller.unsub_char('device_id', 'characteristic-uuid');
204
+ ```
205
+
206
+ **方法:**
207
+
208
+ | 方法 | 说明 |
209
+ |------|------|
210
+ | `send_cmd(device_id, cmd)` | 发送指令(支持加密、ACK、超时) |
211
+ | `read_char(device_id, uuid)` | 读取特征值数据 |
212
+ | `write_char(device_id, uuid, value)` | 写入特征值数据 |
213
+ | `sub_char(device_id, uuid, on_data)` | 订阅特征值通知 |
214
+ | `unsub_char(device_id, uuid)` | 取消订阅特征值通知 |
215
+
216
+ ## 静态工具方法
217
+
218
+ ```javascript
219
+ import { version, info } from 'dh-sdk';
220
+
221
+ console.log(version());
222
+ // { version: '1.0.1019', buildTime: '2026-11-26T...' }
223
+
224
+ console.log(info());
225
+ // { author: 'don' }
226
+ ```
227
+
228
+ ## 构建产物
229
+
230
+ | 格式 | 文件 | 用途 |
231
+ |------|------|------|
232
+ | CJS | `dist/wechat.js` | 微信小程序 |
233
+
234
+ ## License
235
+
236
+ MIT © don
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 微信小程序 BLE 适配器
3
+ * 适用于微信原生框架 (mina) 项目
4
+ */
5
+ import type { BLEAdapter, BLEDevice, BLECharacteristic, ConnectOptions, ScanOptions } from '../types';
6
+ import type { LoggerFn } from '../logger';
7
+ export declare class WechatBLEAdapter implements BLEAdapter {
8
+ readonly platform = "wechat";
9
+ private log;
10
+ private initialized;
11
+ private onDeviceFound;
12
+ private notifyCallbacks;
13
+ private connectionListeners;
14
+ private globalNotifyHandler;
15
+ constructor(log: LoggerFn);
16
+ init(): Promise<void>;
17
+ startScan(options: ScanOptions, onDevice: (device: BLEDevice) => void): Promise<void>;
18
+ stopScan(): Promise<void>;
19
+ connect(options: ConnectOptions): Promise<string>;
20
+ disconnect(deviceId: string): Promise<void>;
21
+ discoverServices(deviceId: string): Promise<string[]>;
22
+ discoverCharacteristics(deviceId: string, serviceUUID: string): Promise<BLECharacteristic[]>;
23
+ read(deviceId: string, serviceUUID: string, characteristicUUID: string): Promise<ArrayBuffer>;
24
+ write(deviceId: string, serviceUUID: string, characteristicUUID: string, data: ArrayBuffer | Uint8Array, _withoutResponse?: boolean): Promise<void>;
25
+ subscribe(deviceId: string, serviceUUID: string, characteristicUUID: string, callback: (data: ArrayBuffer) => void): Promise<void>;
26
+ unsubscribe(deviceId: string, serviceUUID: string, characteristicUUID: string): Promise<void>;
27
+ destroy(): Promise<void>;
28
+ private mapProperties;
29
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * DoneHomeSDK 核心层
3
+ * 负责 BLE 适配器管理、事件系统、底层 BLE 操作
4
+ */
5
+ import type { BLEAdapter, BLEDevice, BLECharacteristic, ConnectOptions, DoneHomeConfig, EventCallback, DoneHomeEvent, ScanOptions } from '../types';
6
+ import { type LoggerFn } from '../logger';
7
+ export declare class DoneHomeSDK {
8
+ private config;
9
+ /** 内部 BLE 适配器(模块可直接访问) */
10
+ adapter: BLEAdapter | null;
11
+ /** 日志器 */
12
+ log: LoggerFn;
13
+ /** 事件监听器 */
14
+ private listeners;
15
+ /** 当前平台 */
16
+ readonly platform = "wechat";
17
+ constructor(config?: DoneHomeConfig);
18
+ init(adapter?: BLEAdapter): Promise<void>;
19
+ ensureReady(): void;
20
+ startScan(options: ScanOptions, onDevice: (device: BLEDevice) => void): Promise<void>;
21
+ stopScan(): Promise<void>;
22
+ connect(options: ConnectOptions): Promise<string>;
23
+ disconnect(deviceId: string): Promise<void>;
24
+ discoverServices(deviceId: string): Promise<string[]>;
25
+ discoverCharacteristics(deviceId: string, serviceUUID: string): Promise<BLECharacteristic[]>;
26
+ read(deviceId: string, serviceUUID: string, characteristicUUID: string): Promise<ArrayBuffer>;
27
+ write(deviceId: string, serviceUUID: string, characteristicUUID: string, data: ArrayBuffer | Uint8Array, withoutResponse?: boolean): Promise<void>;
28
+ subscribe(deviceId: string, serviceUUID: string, characteristicUUID: string, callback: (data: ArrayBuffer) => void): Promise<void>;
29
+ unsubscribe(deviceId: string, serviceUUID: string, characteristicUUID: string): Promise<void>;
30
+ on(event: DoneHomeEvent, callback: EventCallback): this;
31
+ off(event: DoneHomeEvent, callback: EventCallback): this;
32
+ emit(event: string, ...args: unknown[]): void;
33
+ destroy(): Promise<void>;
34
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * DoneHome 加密工具
3
+ * 微信小程序环境的密钥对生成、内存存储、签名/验签
4
+ */
5
+ export interface KeyPair {
6
+ /** 私钥 */
7
+ privateKey: string;
8
+ /** 公钥 */
9
+ publicKey: string;
10
+ /** 导出的公钥(hex,用于传输给设备) */
11
+ publicKeyExported: string;
12
+ }
13
+ export interface CryptoAdapter {
14
+ /** 生成密钥对 */
15
+ generateKeyPair(): Promise<KeyPair>;
16
+ /** 使用私钥签名数据 */
17
+ sign(privateKey: string, data: ArrayBuffer): Promise<ArrayBuffer>;
18
+ /** 使用公钥验签 */
19
+ verify(publicKey: string, data: ArrayBuffer, signature: ArrayBuffer): Promise<boolean>;
20
+ /** 保存密钥对 */
21
+ saveKeyPair(keyId: string, keyPair: KeyPair): Promise<void>;
22
+ /** 加载已保存的密钥对,不存在返回 null */
23
+ loadKeyPair(keyId: string): Promise<KeyPair | null>;
24
+ /** 删除已保存的密钥对 */
25
+ deleteKeyPair(keyId: string): Promise<void>;
26
+ }
27
+ /** 获取加密适配器(单例,微信小程序环境) */
28
+ export declare function getCryptoAdapter(): CryptoAdapter;
29
+ /**
30
+ * 加载或生成密钥对
31
+ * 优先从本地存储加载,不存在则生成新密钥对并保存
32
+ */
33
+ export declare function loadOrCreateKeyPair(keyId: string): Promise<KeyPair>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * dh-sdk
3
+ * 微信小程序 BLE 模组控制 SDK
4
+ *
5
+ * 支持平台:微信小程序 (mina)
6
+ *
7
+ * 使用方式:
8
+ * import { Scanner, Connector, Provisioner, Auth, Controller } from 'dh-sdk'
9
+ */
10
+ export { DoneHomeSDK } from './core/sdk';
11
+ export { Scanner } from './modules/scanner';
12
+ export { Connector } from './modules/connector';
13
+ export { Provisioner } from './modules/provisioner';
14
+ export { Auth } from './modules/auth';
15
+ export { Controller } from './modules/controller';
16
+ /** 获取 SDK 版本信息 */
17
+ export declare function version(): {
18
+ version: string;
19
+ buildTime: string;
20
+ };
21
+ /** 获取 SDK 信息 */
22
+ export declare function info(): {
23
+ author: string;
24
+ };
25
+ export { getCryptoAdapter, loadOrCreateKeyPair } from './crypto';
26
+ export type { KeyPair, CryptoAdapter } from './crypto';
27
+ export type { BLEAdapter, BLEDevice, BLECharacteristic, ConnectOptions, DoneHomeConfig, DoneHomeEvent, EventCallback, ScanOptions, SDKInfo, VersionInfo, ScanFilter, ScannedDevice, ConnectionState, ConnectorOptions, ProvisionPayload, AuthOptions, AuthResult, CmdOptions, } from './types';
28
+ export { ProvisionState } from './modules/provisioner';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 日志工具
3
+ */
4
+ type LogLevel = 'info' | 'warn' | 'error';
5
+ export type LoggerFn = (level: LogLevel, ...args: unknown[]) => void;
6
+ export declare function createLogger(enabled: boolean, custom?: LoggerFn): LoggerFn;
7
+ export {};
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Auth 配网认证模块
3
+ * 基于 ECDSA P-256 密钥对的 challenge-response 认证流程
4
+ *
5
+ * 流程:
6
+ * 1. SDK 加载或生成本地密钥对
7
+ * 2. 发送认证请求 + 公钥 → 设备
8
+ * 3. 设备返回 challenge(随机字节)
9
+ * 4. SDK 使用私钥对 challenge 签名 → 发送给设备
10
+ * 5. 设备用公钥验签,通过后返回 session_key
11
+ */
12
+ import type { DoneHomeSDK } from '../core/sdk';
13
+ import type { AuthOptions, AuthResult } from '../types';
14
+ export declare class Auth {
15
+ /** 设备 session key 映射 */
16
+ private sessions;
17
+ /** SDK 实例引用 */
18
+ private sdk;
19
+ /** 密钥对缓存(keyId → KeyPair) */
20
+ private keyPairs;
21
+ constructor(sdk: DoneHomeSDK);
22
+ /**
23
+ * 向设备发起认证
24
+ * 执行 challenge-response 流程,返回 session_key
25
+ *
26
+ * @param device_id 设备 ID
27
+ * @param options 认证选项(key 为密钥标识,用于区分不同设备的密钥对)
28
+ * @returns 认证结果,包含 session_key
29
+ */
30
+ auth(device_id: string, options?: AuthOptions): Promise<AuthResult>;
31
+ /**
32
+ * 重置设备 SessionKey
33
+ * @param device_id 设备 ID
34
+ */
35
+ refresh_session(device_id: string): Promise<void>;
36
+ /**
37
+ * 获取缓存的 session key
38
+ * @param device_id 设备 ID
39
+ */
40
+ getSession(device_id: string): AuthResult | undefined;
41
+ /**
42
+ * 清除所有 session 缓存
43
+ */
44
+ clearSessions(): void;
45
+ /**
46
+ * 获取设备公钥(用于调试或手动注册到设备)
47
+ * @param keyId 密钥标识(默认 device_id)
48
+ */
49
+ getPublicKey(keyId: string): Promise<string>;
50
+ /**
51
+ * 删除设备密钥对(下次 auth 会自动生成新的)
52
+ * @param keyId 密钥标识
53
+ */
54
+ deleteKeyPair(keyId: string): Promise<void>;
55
+ /**
56
+ * 加载或生成密钥对(带内存缓存)
57
+ */
58
+ private loadKeyPair;
59
+ /**
60
+ * 将公钥编码为字节数组(用于 BLE 传输)
61
+ */
62
+ private encodePublicKey;
63
+ private bytesToHex;
64
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Connector 设备连接模块
3
+ * 负责 BLE 设备的连接、断开与状态管理
4
+ */
5
+ import type { DoneHomeSDK } from '../core/sdk';
6
+ import type { ConnectionState, ConnectorOptions } from '../types';
7
+ export declare class Connector {
8
+ /** 连接状态映射 */
9
+ private connections;
10
+ /** SDK 实例引用 */
11
+ private sdk;
12
+ /** 设备断开回调映射(用于事件清理) */
13
+ private disconnectHandlers;
14
+ constructor(sdk: DoneHomeSDK);
15
+ /**
16
+ * 根据设备 ID 连接设备
17
+ * @param device_id 设备 ID
18
+ * @param options 连接选项
19
+ */
20
+ connect(device_id: string, options?: ConnectorOptions): Promise<void>;
21
+ /**
22
+ * 根据设备 ID 断开连接
23
+ * @param device_id 设备 ID
24
+ */
25
+ disconnect(device_id: string): Promise<void>;
26
+ /**
27
+ * 根据设备 ID 获取连接状态
28
+ * @param device_id 设备 ID
29
+ * @returns 连接状态
30
+ */
31
+ get_connect_state(device_id: string): ConnectionState;
32
+ /**
33
+ * 获取所有连接状态
34
+ */
35
+ getAllStates(): Map<string, ConnectionState>;
36
+ private attemptReconnect;
37
+ /**
38
+ * 注册设备断开监听,自动更新状态并触发自动重连
39
+ */
40
+ private registerDisconnectHandler;
41
+ /**
42
+ * 移除设备断开监听
43
+ */
44
+ private removeDisconnectHandler;
45
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Controller 设备控制模块
3
+ * 负责指令发送、特征值读写与通知订阅
4
+ */
5
+ import type { DoneHomeSDK } from '../core/sdk';
6
+ import type { CmdOptions } from '../types';
7
+ export declare class Controller {
8
+ /** SDK 实例引用 */
9
+ private sdk;
10
+ constructor(sdk: DoneHomeSDK);
11
+ /**
12
+ * 发送指令到设备
13
+ * @param device_id 设备 ID
14
+ * @param cmd 指令参数
15
+ * @returns ACK 响应数据(如果 require_ack)
16
+ */
17
+ send_cmd(device_id: string, cmd: CmdOptions): Promise<ArrayBuffer | void>;
18
+ /**
19
+ * 读取特征值数据
20
+ * @param device_id 设备 ID
21
+ * @param uuid 特征值 UUID
22
+ */
23
+ read_char(device_id: string, uuid: string): Promise<ArrayBuffer>;
24
+ /**
25
+ * 写入特征值数据
26
+ * @param device_id 设备 ID
27
+ * @param uuid 特征值 UUID
28
+ * @param value 要写入的数据
29
+ */
30
+ write_char(device_id: string, uuid: string, value: ArrayBuffer | Uint8Array): Promise<void>;
31
+ /**
32
+ * 订阅特征值通知
33
+ * @param device_id 设备 ID
34
+ * @param uuid 特征值 UUID
35
+ * @param on_data 数据回调
36
+ */
37
+ sub_char(device_id: string, uuid: string, on_data: (data: ArrayBuffer) => void): Promise<void>;
38
+ /**
39
+ * 取消订阅特征值通知
40
+ * @param device_id 设备 ID
41
+ * @param uuid 特征值 UUID
42
+ */
43
+ unsub_char(device_id: string, uuid: string): Promise<void>;
44
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Provisioner 设备配网模块
3
+ * 负责向设备发送配网信息(如 WiFi 凭据等)
4
+ */
5
+ import type { DoneHomeSDK } from '../core/sdk';
6
+ import type { ProvisionPayload } from '../types';
7
+ /** 配网状态 */
8
+ export type ProvisionState = 'idle' | 'provisioning' | 'success' | 'failed' | 'cancelled';
9
+ export declare class Provisioner {
10
+ /** 设备配网状态 */
11
+ private states;
12
+ /** 设备配网取消回调(用于 cancel 时 reject 悬挂的 Promise) */
13
+ private cancelCallbacks;
14
+ /** SDK 实例引用 */
15
+ private sdk;
16
+ constructor(sdk: DoneHomeSDK);
17
+ /**
18
+ * 向设备发起配网
19
+ * @param device_id 设备 ID
20
+ * @param payload 配网载荷
21
+ */
22
+ provision(device_id: string, payload: ProvisionPayload): Promise<void>;
23
+ /**
24
+ * 取消配网操作
25
+ * @param device_id 设备 ID
26
+ */
27
+ cancel(device_id: string): Promise<void>;
28
+ /**
29
+ * 获取设备配网状态
30
+ * @param device_id 设备 ID
31
+ */
32
+ getState(device_id: string): ProvisionState;
33
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Scanner 设备扫描模块
3
+ * 负责 BLE 设备的发现与过滤
4
+ */
5
+ import type { DoneHomeSDK } from '../core/sdk';
6
+ import type { ScanFilter, ScannedDevice } from '../types';
7
+ export declare class Scanner {
8
+ /** 已发现的设备列表 */
9
+ private devices;
10
+ /** 是否正在扫描 */
11
+ private scanning;
12
+ /** SDK 实例引用 */
13
+ private sdk;
14
+ constructor(sdk: DoneHomeSDK);
15
+ /**
16
+ * 根据条件开始扫描设备
17
+ * 扫描到设备时自动追加到列表
18
+ * @param filter 筛选条件
19
+ */
20
+ start(filter?: ScanFilter): Promise<void>;
21
+ /**
22
+ * 停止扫描设备
23
+ */
24
+ stop(): Promise<void>;
25
+ /**
26
+ * 获取已发现的设备列表
27
+ */
28
+ getDevices(): ScannedDevice[];
29
+ /**
30
+ * 根据设备 ID 获取设备信息
31
+ */
32
+ getDevice(deviceId: string): ScannedDevice | undefined;
33
+ /**
34
+ * 清空设备列表
35
+ */
36
+ clearDevices(): void;
37
+ /**
38
+ * 是否正在扫描
39
+ */
40
+ isScanning(): boolean;
41
+ }