AI_UIAutomation/tests/curtain/curtain3_2025_connect.test.ts

74 lines
3.2 KiB
TypeScript

import { describe, it, beforeAll, afterAll, expect } from 'vitest';
import { DeviceDriver } from '../../drivers/types';
import { createDriver } from '../../drivers/factory';
import { TestReporter } from '../../utils/test-reporter';
import {
addDeviceWithSerialPairing,
findDeviceNameOnHomepage,
saveAddedDevice,
curtain3PostConnect,
setupResilientHooks,
} from '../../utils/common';
import * as dotenv from 'dotenv';
import * as path from 'path';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
// Curtain 3 2025:入口品类=Curtain(与 curtain/curtain3 同入口),relay ch6。
// **添加流程与 Curtain 3 完全一致**(用户确认 2026-06-23)→ 连接后统一走 curtain3PostConnect,不再分支 POST_FLOW。
const CATEGORY = process.env.CURTAIN3_2025_CATEGORY || 'Curtain';
const deviceName = process.env.CURTAIN3_2025_DEVICE || 'Curtain';
const CALIBRATE = process.env.CURTAIN_CALIBRATE === '1';
// 添加向导内联改名(首页都叫 "Curtain XX",靠改名区分型号);skip/home 校验按该名
const RENAME_TO = process.env.CURTAIN3_2025_RENAME || 'Curtain3 2025 Auto';
const ADD_ANCHOR = '[P0][ONES:265933]';
describe('Curtain3 2025 Connect - 添加Curtain 3 2025(入口Curtain)', () => {
let driver: DeviceDriver;
let reporter: TestReporter;
setupResilientHooks(() => driver);
beforeAll(async () => {
driver = createDriver();
await driver.createSession();
reporter = new TestReporter('Curtain3_2025_Connect', driver.platform.toUpperCase());
});
afterAll(async () => {
reporter.generate();
await driver.destroySession();
});
it(`${ADD_ANCHOR} 通过BLE添加Curtain 3 2025`, { timeout: 360000 }, async () => {
const start = Date.now();
try {
const existing = await findDeviceNameOnHomepage(driver, RENAME_TO);
if (existing) {
console.log(`${existing}已在首页,跳过重新添加`);
saveAddedDevice('curtain', existing);
reporter.record(`${ADD_ANCHOR} 添加Curtain 3 2025`, 'SKIP', Date.now() - start, `${existing}已存在`);
return;
}
const result = await addDeviceWithSerialPairing(driver, {
categoryName: CATEGORY, // 入口=Curtain
deviceKeyword: deviceName,
relayDevice: 'curtain3_2025', // ch6 开关键 2s
registryCategory: 'curtain',
namePattern: RENAME_TO, // 向导内联改名后落首页即该名
preferNamePattern: true, // "Curtain3 2025 Auto" 含 "Curtain" 子串 → 优先按 namePattern 回写真实名(否则塌成通用 "Curtain")
// 连接后:选模式 + 内联改名 + 校准 —— 与 Curtain 3 完全相同流程。
postConnectSteps: (d) => curtain3PostConnect(d, { calibrate: CALIBRATE, renameTo: RENAME_TO }),
});
expect(result).toBe(true);
const elapsed = ((Date.now() - start) / 1000).toFixed(1);
reporter.record(`${ADD_ANCHOR} 添加Curtain 3 2025`, 'PASS', Date.now() - start, `添加成功(同Curtain3流程${CALIBRATE ? ',含校准' : ''}), 耗时${elapsed}s`);
} catch (e: any) {
const ss = await driver.screenshot().catch(() => '');
reporter.record(`${ADD_ANCHOR} 添加Curtain 3 2025`, 'FAIL', Date.now() - start, e.message, ss);
throw e;
}
});
});