44 lines
2.1 KiB
TypeScript
44 lines
2.1 KiB
TypeScript
import * as dotenv from 'dotenv';
|
|
import * as path from 'path';
|
|
dotenv.config({ path: path.resolve(__dirname, '../.env') });
|
|
import { createDriver } from '../drivers/factory';
|
|
import { ensureHomeTab } from '../utils/common/navigation.helper';
|
|
import { sleep } from '../utils/common/element.helper';
|
|
|
|
// 探索:首页房间标签 + 长按设备卡进入删除模式后出现什么
|
|
async function main() {
|
|
const cardText = process.argv[2] || 'Meter';
|
|
const driver = createDriver();
|
|
await driver.createSession();
|
|
try {
|
|
await ensureHomeTab(driver);
|
|
await driver.dismissPopupIfPresent();
|
|
await sleep(1500);
|
|
|
|
const dump = async (label: string) => {
|
|
const src = await driver.getSource();
|
|
const t = Array.from(src.matchAll(/text="([^"]{1,40})"/g)).map((m) => m[1]).filter(Boolean);
|
|
const d = Array.from(src.matchAll(/content-desc="([^"]{1,40})"/g)).map((m) => m[1]).filter(Boolean);
|
|
console.log(`\n=== ${label} ===\n text:`, Array.from(new Set(t)).join(' | '), '\n desc:', Array.from(new Set(d)).join(' | '));
|
|
};
|
|
// 房间标签
|
|
const rooms = await driver.findElementsRaw('id', 'com.theswitchbot.switchbot:id/clSelectRoom');
|
|
console.log('房间标签数:', rooms.length);
|
|
for (const r of rooms) { const tx = await driver.getElementAttribute(r, 'text').catch(() => ''); if (tx) console.log(' 房间:', tx); }
|
|
|
|
await dump('首页(长按前)');
|
|
|
|
// 找设备卡 → 长按其中心
|
|
let card = await driver.findElementRaw('-android uiautomator', `new UiSelector().textContains("${cardText}")`);
|
|
if (!card) { console.log(`未找到含"${cardText}"的卡片`); return; }
|
|
const rect = await driver.getElementRect(card);
|
|
console.log(`长按 "${cardText}" 卡片中心 (${Math.round(rect.x + rect.width / 2)}, ${Math.round(rect.y + rect.height / 2)})`);
|
|
await driver.longPress(Math.round(rect.x + rect.width / 2), Math.round(rect.y + rect.height / 2), 1.2);
|
|
await sleep(2500);
|
|
await dump('长按后(删除/管理模式?)');
|
|
} finally {
|
|
await driver.destroySession();
|
|
}
|
|
}
|
|
main().catch((e) => { console.error('ERR:', e.message); process.exit(1); });
|