38 lines
2.2 KiB
TypeScript
38 lines
2.2 KiB
TypeScript
import { createDriver } from '../drivers/factory';
|
|
|
|
(async () => {
|
|
const d = createDriver();
|
|
await d.createSession();
|
|
const KW = process.env.LIGHT_CARD || 'Color Bulb 7E';
|
|
const W = 1080, H = 2400;
|
|
const sleep = (m: number) => new Promise((r) => setTimeout(r, m));
|
|
const fullSub = async (): Promise<string> => {
|
|
const s = await d.getSource();
|
|
const t = Array.from(s.matchAll(/text="([^"]+)"/g)).map((m) => m[1]);
|
|
const i = t.findIndex((x) => x.includes(KW));
|
|
return i >= 0 ? `${t[i + 1] || ''} | ${t[i + 2] || ''} | ${t[i + 3] || ''}` : '';
|
|
};
|
|
try {
|
|
await d.dismissPopupIfPresent(); await d.goBackToHomepage(); await sleep(800);
|
|
let el: string | null = null;
|
|
for (let i = 0; i < 10; i++) { el = await d.findElementRaw('-android uiautomator', `new UiSelector().textContains("${KW}")`).catch(() => null); if (el) break; await d.swipe(540, 1500, 540, 700, 0.4).catch(() => {}); await sleep(800); }
|
|
const r = await d.getElementRect(el!); await d.tap(r.x + r.width / 2, r.y + r.height / 2); await sleep(2500);
|
|
// 开灯
|
|
const src = await d.getSource();
|
|
const pw = Array.from(src.matchAll(/clickable="true"[^>]*?bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"/g))
|
|
.map((m) => { const x1 = +m[1], y1 = +m[2], x2 = +m[3], y2 = +m[4]; return { w: x2 - x1, h: y2 - y1, cx: (x1 + x2) / 2, cy: (y1 + y2) / 2 }; })
|
|
.filter((b) => b.w >= 150 && b.w <= 320 && b.h >= 150 && b.h <= 320 && Math.abs(b.cx - W / 2) < W * 0.15 && b.cy > H * 0.4);
|
|
if (!/\d+\s*%/.test(await fullSub()) && pw.length) { await d.tap(Math.round(pw[0].cx), Math.round(pw[0].cy)); await sleep(3500); }
|
|
console.log('开灯后副标题(含后2字段)=' + JSON.stringify(await fullSub()));
|
|
|
|
// 色温条 y1737:拖最左 / 中 / 最右,各看副标题
|
|
const left = 58, right = 1022, y = 1737;
|
|
for (const [lbl, f] of [['左', 0.05], ['中', 0.5], ['右', 0.95]] as Array<[string, number]>) {
|
|
// 从中点起拖(色温滑块当前位置未知,先试中点抓)
|
|
await d.swipe(540, y, Math.round(left + f * (right - left)), y, 0.8); await sleep(2000);
|
|
console.log(`色温拖${lbl}(f=${f}) → 副标题=${JSON.stringify(await fullSub())}`);
|
|
}
|
|
} catch (e: any) { console.error('FAIL:', e.message); }
|
|
finally { await d.destroySession(); }
|
|
})();
|