修自动连接型设备误判 not found in BLE scan(彩灯等)

彩灯等设备配对后自动连接、直接进配网页,无"从扫描列表选设备"步 → waitForDeviceInScan 等不到设备名元素 30s 超时报 not found in BLE scan,实际已在配网页。
修:waitForDeviceInScan 增 advanceKeywords,轮询时若已直达配网/连接页则提前返回;Step3 未选到设备时检查"是否已推进到配网/连接页",已推进则跳过选设备步继续。
验证:Color Bulb 现完整 PASS(自动连接→ASUS_30 配网成功 15s→落账号)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
woan 2026-06-25 14:59:20 +08:00
parent 1f0b8fd576
commit fb1c13e086
1 changed files with 37 additions and 27 deletions

View File

@ -208,20 +208,23 @@ export async function selectDeviceCategory(driver: DeviceDriver, categoryName: s
export async function waitForDeviceInScan(
driver: DeviceDriver,
deviceKeyword: string,
timeout = 30000
timeout = 30000,
advanceKeywords?: string[]
): Promise<string | null> {
if (driver.platform === 'android') {
// 轮询:出现"扫描列表里的设备项"→返回它;若已**直达配网/连接页**(自动连接型设备,无选设备步)→返回 null(由调用方识别"已推进")。
const start = Date.now();
while (Date.now() - start < timeout) {
const el = await driver.findElementRaw('-android uiautomator', `new UiSelector().textContains("${deviceKeyword}")`);
const el = driver.platform === 'android'
? await driver.findElementRaw('-android uiautomator', `new UiSelector().textContains("${deviceKeyword}")`).catch(() => null)
: await driver.findElementRaw('name', deviceKeyword).catch(() => null);
if (el) return el;
if (advanceKeywords && advanceKeywords.length) {
const src = await driver.getSource();
if (advanceKeywords.some((k) => src.includes(k)) || /Configure Wi-?Fi|Wi-?Fi password|Enter Wi-?Fi|Connecting|Verifying|连接中|正在连接/i.test(src)) return null;
}
await sleep(1000);
}
return null;
}
// iOS
return await waitForElement(driver, 'name', deviceKeyword, timeout);
}
export async function waitForConnection(
@ -270,11 +273,9 @@ export async function addDeviceViaBLE(driver: DeviceDriver, options: AddDeviceOp
// Step 3: Wait for device in BLE scan (skip for auto-connect devices like AI Hub)
if (!skipScanStep) {
const deviceEl = await waitForDeviceInScan(driver, deviceKeyword, scanTimeout);
if (!deviceEl) {
console.log(`FAIL: ${deviceKeyword} not found in BLE scan`);
return false;
}
const advanceKw = connectionKeywords || DEFAULT_CONNECTION_KEYWORDS;
const deviceEl = await waitForDeviceInScan(driver, deviceKeyword, scanTimeout, advanceKw);
if (deviceEl) {
await driver.tapElement(deviceEl);
await sleep(500);
@ -289,6 +290,15 @@ export async function addDeviceViaBLE(driver: DeviceDriver, options: AddDeviceOp
}
await sleep(2000);
}
} else {
// 没在扫描列表选到设备 → 但很多设备(彩灯等)是**自动连接、直接进配网/连接页**(无"从列表选设备"步)。
// 已进配网/连接页则跳过选择继续(原来一律报 not found → 误判失败,实际已在配网页)。
const src = await driver.getSource();
const advanced = advanceKw.some((k) => src.includes(k))
|| /Configure Wi-?Fi|Wi-?Fi password|Enter Wi-?Fi|Connecting|Verifying|连接中|正在连接/i.test(src);
if (!advanced) { console.log(`FAIL: ${deviceKeyword} not found in BLE scan`); return false; }
console.log(`${deviceKeyword} 已自动连接/直达配网页(无扫描列表选择步,跳过)`);
}
}
// Step 5: Wait for connection连接失败时点 App 的"重试"再等,最多重试 2 次)