feat: reveal device cards progressively with camera zoom
This commit is contained in:
1 parent
e62f987563
commit
a2a119d3ee
18 files changed
+458
-265
No files matched your search
+2
-1
@@ -115,7 +115,8 @@ function copySymconAssets() {
|
||||
// Hydronic geometry/readouts load separately; only model references, anchors and the loader join the host.
|
||||
// Metered-device detail discovery adds about 2 KB; keep a small, explicit margin.
|
||||
// Charging telemetry, native time/duration formatting and labels add another 5 KB.
|
||||
const BUDGET = { "nextfloor.js": 680 * 1024, "nextfloor-3d.js": 1000 * 1024, "nextfloor-editor.js": 720 * 1024, "nextfloor-card-editor.js": 240 * 1024, "nextfloor-trend.js": 100 * 1024, "nextfloor-hydronics.js": 100 * 1024 };
|
||||
// Zoom detail levels and bounded device-card layouts add about 1.5 KB.
|
||||
const BUDGET = { "nextfloor.js": 682 * 1024, "nextfloor-3d.js": 1000 * 1024, "nextfloor-editor.js": 720 * 1024, "nextfloor-card-editor.js": 240 * 1024, "nextfloor-trend.js": 100 * 1024, "nextfloor-hydronics.js": 100 * 1024 };
|
||||
|
||||
copyAssets();
|
||||
copySymconAssets();
|
||||
|
||||
@@ -42,6 +42,7 @@ import { isHeatPump, readHeatPump, type HeatPumpInfo } from "../live/heat-pump.t
|
||||
import { coverageColor, isAccessPoint, networkHealth, readAccessPoint } from "../live/wifi.ts";
|
||||
import type { FurnitureColors } from "../furniture-colors.ts";
|
||||
import { renderLhCards, liveCardStyles, unstackLhCards, type LiveCard } from "../live/cards.ts";
|
||||
import { cardDetail, cardVisibleAtZoom } from "../live/card-visibility.ts";
|
||||
import { readCar, type CarInfo } from "../live/car.ts";
|
||||
import { mediaNow, multiroom, type MediaNow } from "../live/media.ts";
|
||||
import { SHOW_PRESENCE } from "../flags.ts";
|
||||
@@ -2697,17 +2698,27 @@ export class NfView3d extends LitElement {
|
||||
if (JSON.stringify(cards) !== JSON.stringify(this._liveCards)) this._liveCards = cards;
|
||||
v.setLiveAnchors(
|
||||
cards.map((c) => c.at),
|
||||
cards.length ? (i, x, y, visible) => this.placeLhCard(i, x, y, visible) : null,
|
||||
cards.length ? (i, x, y, visible, density) => this.placeLhCard(i, x, y, visible, density) : null,
|
||||
);
|
||||
}
|
||||
|
||||
/** Called by the viewer after every frame: moves a card to its point without a Lit render. */
|
||||
private placeLhCard(i: number, x: number, y: number, visible: boolean): void {
|
||||
private placeLhCard(i: number, x: number, y: number, visible: boolean, density: number): void {
|
||||
const el = this.renderRoot.querySelector<HTMLElement>(`.live-card[data-i="${i}"]`);
|
||||
if (!el) return;
|
||||
const card = this._liveCards[i], key = `${card.kind}:${card.at.floorId}:${card.at.x}:${card.at.z}`;
|
||||
const wasVisible = el.dataset.zoomKey === key && el.dataset.zoomVisible === "1";
|
||||
const active = this.shadowRoot?.activeElement;
|
||||
const focused = !!active && el.contains(active);
|
||||
const zoomVisible = focused || cardVisibleAtZoom(card, density, wasVisible);
|
||||
el.dataset.zoomKey = key;
|
||||
el.dataset.zoomVisible = zoomVisible ? "1" : "0";
|
||||
el.dataset.density = String(Math.round(density));
|
||||
el.dataset.priority = String(focused ? 110 : cardDetail(card).priority);
|
||||
el.dataset.focused = focused ? "1" : "0";
|
||||
el.dataset.x = String(x);
|
||||
el.dataset.y = String(y);
|
||||
el.style.visibility = visible ? "visible" : "hidden";
|
||||
el.style.visibility = visible && zoomVisible ? "visible" : "hidden";
|
||||
// the last card of the frame: lay them all out so none covers another
|
||||
if (i === this._liveCards.length - 1) unstackLhCards(this.renderRoot);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import type { FurniturePowerCard } from "./furniture-power-card.ts";
|
||||
import type { HouseCard, HydronicCard } from "./cards.ts";
|
||||
import { cardDetail, cardVisibleAtZoom } from "./card-visibility.ts";
|
||||
|
||||
const power=(w: number|null): FurniturePowerCard=>({kind:"power",id:"wallbox",name:"Wallbox",powerEntity:"sensor.power",power:w,at:{floorId:"f",x:0,y:1,z:0}});
|
||||
const house: HouseCard={kind:"house",at:{floorId:"f",x:0,y:5,z:0},summary:{grid:0,solar:0,battery:null,soc:null,tariff:null,consumption:0},autarky:null};
|
||||
const hydraulic: HydronicCard={kind:"hydronic",at:{floorId:"f",x:0,y:2,z:0},readOnly:false,item:{id:"h",type:"heating_manifold",x:0,z:0,w:1.5,d:.35,h:1.1,rotation:0,variant:null}};
|
||||
|
||||
test("distant views retain the summary while small device cards wait for more zoom",()=>{
|
||||
assert.equal(cardVisibleAtZoom(house,0,false),true);
|
||||
for(const card of [power(0),power(7400),hydraulic]) assert.equal(cardVisibleAtZoom(card,15,false),false);
|
||||
assert.equal(cardVisibleAtZoom(hydraulic,50,false),true);
|
||||
assert.equal(cardVisibleAtZoom(power(7400),60,false),true);
|
||||
assert.equal(cardVisibleAtZoom(power(0),60,false),false);
|
||||
assert.equal(cardVisibleAtZoom(power(0),90,false),true);
|
||||
});
|
||||
|
||||
test("live consumption and export appear before idle devices, without discarding the zero value",()=>{
|
||||
assert.ok(cardDetail(power(7400)).priority>cardDetail(power(0)).priority);
|
||||
assert.equal(cardVisibleAtZoom(power(-1500),60,false),true);
|
||||
assert.equal(cardVisibleAtZoom(power(0),90,false),true);
|
||||
assert.equal(power(0).power,0);
|
||||
assert.equal(cardVisibleAtZoom(power(null),40,false),false);
|
||||
});
|
||||
|
||||
test("hysteresis keeps a visible card stable near its boundary and restores it after zooming back in",()=>{
|
||||
const c=power(0),threshold=cardDetail(c).density;
|
||||
assert.equal(cardVisibleAtZoom(c,threshold,false),false);
|
||||
assert.equal(cardVisibleAtZoom(c,threshold,true),true);
|
||||
assert.equal(cardVisibleAtZoom(c,threshold*.85,true),false);
|
||||
assert.equal(cardVisibleAtZoom(c,threshold*1.15,false),true);
|
||||
for(const density of [NaN,Infinity,-1,0]) assert.equal(cardVisibleAtZoom(c,density,true),false);
|
||||
});
|
||||
|
||||
test("charging telemetry follows detail zoom even without a power link",()=>{
|
||||
const c={...power(null),powerEntity:null,readings:[{id:"soc",entity:"sensor.soc",label:"SoC",icon:"🔋",text:"0 %"}]};
|
||||
assert.equal(cardVisibleAtZoom(c,30,false),false);
|
||||
assert.equal(cardVisibleAtZoom(c,70,false),true);
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { LiveCard } from "./cards.ts";
|
||||
|
||||
/** Screen pixels per plan metre at the anchor, independent of building size and camera angle. */
|
||||
export function cardDetail(card: LiveCard): { density: number; priority: number } {
|
||||
switch (card.kind) {
|
||||
case "house": return { density:0,priority:100 };
|
||||
case "roomclimate": return { density:24,priority:80 };
|
||||
case "hydronic": return { density:42,priority:45 };
|
||||
case "power": {
|
||||
const active=card.power!==null&&Math.abs(card.power)>1;
|
||||
return active ? {density:48,priority:60} : card.readings?.length ? {density:56,priority:30} : {density:card.power===null?64:72,priority:20};
|
||||
}
|
||||
case "car": return {density:card.car.charging?36:60,priority:card.car.charging?60:20};
|
||||
case "printer": return {density:card.printer.printing?36:60,priority:card.printer.printing?60:20};
|
||||
case "heatpump": return {density:card.pump.mode!=="idle"?36:60,priority:card.pump.mode!=="idle"?60:20};
|
||||
case "media": return {density:48,priority:40};
|
||||
}
|
||||
}
|
||||
|
||||
/** A small dead band prevents cards flickering at a zoom boundary. Summary cards keep their existing visibility. */
|
||||
export function cardVisibleAtZoom(card: LiveCard, density: number, previouslyVisible: boolean): boolean {
|
||||
const limit=cardDetail(card).density;
|
||||
if (!limit) return true;
|
||||
return Number.isFinite(density) && density >= limit * (previouslyVisible ? .88 : 1.12);
|
||||
}
|
||||
@@ -246,7 +246,7 @@ function mediaCard(hass: HomeAssistant | undefined, c: MediaCard, i: number, act
|
||||
* before it (lower on screen first) moves up above it. Its thread to the anchor stretches.
|
||||
*/
|
||||
export function unstackLhCards(root: ParentNode): void {
|
||||
const cards = [...root.querySelectorAll<HTMLElement>(".live-card")].filter((el) => el.style.visibility !== "hidden");
|
||||
const cards = [...root.querySelectorAll<HTMLElement>(".live-card")].filter((el) => el.style.visibility !== "hidden" && el.offsetWidth > 0);
|
||||
const placed: { x0: number; x1: number; y0: number; y1: number }[] = [];
|
||||
// a card near the edge slides back into the view (on a phone it was cut off); its thread still points home
|
||||
const width = cards[0]?.parentElement?.clientWidth ?? 0;
|
||||
@@ -258,7 +258,7 @@ export function unstackLhCards(root: ParentNode): void {
|
||||
el.style.setProperty("--live-dx", `${Math.round(anchor - x)}px`);
|
||||
return { el, x, y: Number(el.dataset.y), w, h: el.offsetHeight };
|
||||
})
|
||||
.sort((a, b) => b.y - a.y);
|
||||
.sort((a, b) => Number(b.el.dataset.priority || 0) - Number(a.el.dataset.priority || 0) || b.y - a.y);
|
||||
for (const it of items) {
|
||||
let bottom = it.y;
|
||||
// Multi-reading equipment cards use nearby free columns before stacking out of view.
|
||||
@@ -278,8 +278,14 @@ export function unstackLhCards(root: ParentNode): void {
|
||||
if (!hit) break;
|
||||
bottom = hit.y0 - 8;
|
||||
}
|
||||
placed.push({ x0: it.x - it.w / 2, x1: it.x + it.w / 2, y0: bottom - it.h, y1: bottom });
|
||||
const lift = it.y - bottom;
|
||||
// Device details wait for a closer view instead of forming long towers or leaving the stage.
|
||||
const detail = !it.el.classList.contains("live-card-house") && !it.el.classList.contains("live-card-roomclimate") && it.el.dataset.focused !== "1";
|
||||
const multi = it.el.classList.contains("live-card-hydronic") || it.el.classList.contains("live-card-charging");
|
||||
if (detail && height > 0 && (bottom-it.h < 8 || bottom > height-8 || (!multi && Math.abs(lift) > Math.max(100,Math.min(180,height*.25))))) {
|
||||
it.el.style.visibility="hidden"; continue;
|
||||
}
|
||||
placed.push({ x0: it.x - it.w / 2, x1: it.x + it.w / 2, y0: bottom - it.h, y1: bottom });
|
||||
it.el.style.setProperty("--live-dx", `${Math.round(Number(it.el.dataset.x) - it.x)}px`);
|
||||
it.el.style.transform = `translate(${Math.round(it.x)}px, ${Math.round(bottom)}px) translate(-50%, -100%)`;
|
||||
it.el.style.setProperty("--live-thread", `${Math.round(18 + lift)}px`);
|
||||
|
||||
@@ -267,7 +267,7 @@ export interface LivePictureInput {
|
||||
export type LiveScreenInput = Omit<LiveScreen, "x" | "z" | "rotation" | "rect"> & { furnitureId: string };
|
||||
|
||||
/** Called after every frame for each card anchor: where it is on screen (CSS pixels) and whether it shows. */
|
||||
export type LiveAnchorCallback = (index: number, x: number, y: number, visible: boolean) => void;
|
||||
export type LiveAnchorCallback = (index: number, x: number, y: number, visible: boolean, pixelsPerMeter: number) => void;
|
||||
|
||||
export interface PersonPin {
|
||||
id: string;
|
||||
@@ -1274,11 +1274,14 @@ export class NextFloorViewer {
|
||||
const cb = this.liveAnchorCb;
|
||||
if (!cb || !this.liveAnchors.length) return;
|
||||
const v = new Vector3();
|
||||
const view = this.camera.matrixWorldInverse.elements, focal = this.size.h * this.camera.projectionMatrix.elements[5] / 2;
|
||||
this.liveAnchors.forEach((p, i) => {
|
||||
const l = this.liftOf(p.floorId);
|
||||
v.set(p.x, l.y + p.y, p.z).project(this.camera);
|
||||
const visible = l.visible && v.z < 1 && Math.abs(v.x) < 1.15 && Math.abs(v.y) < 1.15;
|
||||
cb(i, ((v.x + 1) / 2) * this.size.w, ((1 - v.y) / 2) * this.size.h, visible);
|
||||
v.set(p.x, l.y + p.y, p.z);
|
||||
const depth = -(view[2]*v.x+view[6]*v.y+view[10]*v.z+view[14]);
|
||||
v.project(this.camera);
|
||||
const visible = l.visible && v.z > -1 && v.z < 1 && Math.abs(v.x) < 1.15 && Math.abs(v.y) < 1.15;
|
||||
cb(i, ((v.x + 1) / 2) * this.size.w, ((1 - v.y) / 2) * this.size.h, visible, depth > 0 ? focal / depth : 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// Real camera projection, wheel zoom, active/idle priorities and clustered cards in the built UI.
|
||||
import assert from "node:assert/strict";
|
||||
import { createServer } from "node:http";
|
||||
import { existsSync,mkdirSync,readFileSync } from "node:fs";
|
||||
import { extname,join,relative,resolve } from "node:path";
|
||||
import puppeteer from "puppeteer-core";
|
||||
|
||||
const root=resolve(import.meta.dirname,".."),out=join(root,"preview/screenshots");mkdirSync(out,{recursive:true});
|
||||
const server=createServer((req,res)=>{
|
||||
const file=resolve(root,`.${decodeURIComponent(new URL(req.url,"http://localhost").pathname)}`);
|
||||
if(relative(root,file).startsWith("..")||!existsSync(file))return res.writeHead(404).end();
|
||||
res.writeHead(200,{"content-type":({".html":"text/html",".js":"text/javascript",".json":"application/json"})[extname(file)]??"application/octet-stream"}).end(readFileSync(file));
|
||||
});
|
||||
await new Promise((done)=>server.listen(0,"127.0.0.1",done));let browser;
|
||||
try{
|
||||
const executablePath=[process.env.CHROME_PATH,"C:/Program Files/Google/Chrome/Application/chrome.exe","C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"].find((p)=>p&&existsSync(p));
|
||||
browser=await puppeteer.launch({executablePath,headless:true,args:["--use-angle=swiftshader","--enable-unsafe-swiftshader"]});
|
||||
const page=await browser.newPage(),errors=[];page.on("pageerror",(e)=>errors.push(String(e)));await page.setViewport({width:1440,height:1000});
|
||||
await page.evaluateOnNewDocument(()=>localStorage.setItem("nextfloor.cards","1"));
|
||||
await page.goto(`http://127.0.0.1:${server.address().port}/preview/index.html?noshowcase`,{waitUntil:"networkidle0"});
|
||||
await page.waitForFunction(()=>window.nfPanel?.data.building?.floors.length);
|
||||
await page.evaluate(async()=>{
|
||||
const p=window.nfPanel,b=structuredClone(p.data.building),f=b.floors[0];b.floors=[f];
|
||||
f.rooms=[{...f.rooms[0],id:"garage",name:"Garage",points:[[-12,-10],[12,-10],[12,10],[-12,10]],area_id:null,climate_card:true,climate:{temperature:"cover.200"}}];
|
||||
Object.assign(f,{openings:[],placements:[],furniture:[],outdoor:[],walls:[],background:null,power_entity:null,utility_meters:{electricity:{power:"cover.101",energy:"sensor.201"}},start_view:null});
|
||||
b.settings.roof.type="none";b.settings.start_view=null;for(const k of Object.keys(b.energy))b.energy[k]=null;b.energy.consumption="cover.101";
|
||||
const point=(id,value,unit)=>({entity_id:id,state:"open",attributes:{symcon_id:Number(id.split(".")[1]),symcon_variable_type:2,symcon_value:value,symcon_numeric_value:value,unit_of_measurement:unit}});
|
||||
const states={"cover.100":point("cover.100",0,"W"),"cover.101":point("cover.101",7400,"W"),"cover.200":point("cover.200",22.4,"°C"),"sensor.201":point("sensor.201",123,"kWh")};
|
||||
const piece=(id,type,x,z,extra={})=>({id,type,name:id,x,z,w:.3,d:.3,h:.4,rotation:0,variant:null,entity:"none",power:"cover.100",power_card:true,...extra});
|
||||
for(let i=0;i<7;i++)f.furniture.push(piece(`Standby ${i+1}`,"wallbox",-1,-1.5+i*.5));
|
||||
f.furniture.push(piece("Lädt","wallbox",1.5,-1,{power:"cover.101"}));
|
||||
f.furniture.push(piece("Verteiler","heating_manifold",3.5,0,{w:1.5,d:.35,h:1.1,power:"none",power_card:false}));
|
||||
p.data.edit(b);p.hass={...p.hass,language:"de",states,symconObjects:[]};await p.updateComplete;window.zoomFloor=f.id;
|
||||
[...p.shadowRoot.querySelectorAll("[role=tab]")].find((b)=>b.textContent.trim()==="3D").click();
|
||||
});
|
||||
await page.waitForFunction(()=>window.nfPanel.shadowRoot.querySelector("nf-view3d")?.viewer);
|
||||
await page.evaluate(async()=>{window.zoomView=window.nfPanel.shadowRoot.querySelector("nf-view3d");window.nfPanel.openFloor(window.zoomFloor);await window.nfPanel.updateComplete;});
|
||||
await page.waitForFunction(()=>window.zoomView.shadowRoot.querySelectorAll(".live-card-power").length===8&&window.zoomView.shadowRoot.querySelector(".live-card-hydronic"));
|
||||
const camera=async(radius,target={x:0,y:1,z:0})=>{
|
||||
await page.evaluate(({radius,target})=>window.zoomView.viewer.showView({target,radius,phi:1,theta:.3},0),{radius,target});
|
||||
await page.waitForFunction((radius)=>Math.abs(window.zoomView.viewer.getView().radius-radius)<.1,{},radius);
|
||||
await page.evaluate(()=>new Promise((done)=>requestAnimationFrame(()=>requestAnimationFrame(done))));
|
||||
};
|
||||
const snapshot=()=>page.evaluate(()=>{
|
||||
const root=window.zoomView.shadowRoot;
|
||||
const cards=[...root.querySelectorAll(".live-card")].map((c)=>({name:c.dataset.furniture||c.className,visible:c.style.visibility==="visible",zoom:c.dataset.zoomVisible,density:Number(c.dataset.density),priority:Number(c.dataset.priority),box:c.getBoundingClientRect().toJSON(),stage:c.parentElement.getBoundingClientRect().toJSON()}));
|
||||
return{cards,radius:window.zoomView.viewer.getView().radius,top:root.querySelector("nf-utility-overview[inline]")?.shadowRoot.textContent};
|
||||
});
|
||||
await camera(85);let s=await snapshot();
|
||||
assert.equal(s.cards.filter((c)=>c.name.startsWith("Standby")&&c.visible).length,0);
|
||||
assert.equal(s.cards.find((c)=>c.name==="Lädt").visible,false);
|
||||
assert.equal(s.cards.find((c)=>c.name==="Verteiler").visible,false);
|
||||
assert.ok(s.cards.some((c)=>c.name.includes("live-card-house")&&c.visible),"the building summary survives the far overview");
|
||||
assert.match(s.top,/7,4 kW/);assert.match(s.top,/123 kWh/);
|
||||
await page.screenshot({path:join(out,"symcon-card-zoom-far.png")});
|
||||
await camera(19);s=await snapshot();
|
||||
assert.equal(s.cards.find((c)=>c.name==="Lädt").visible,true,"a charging device appears at medium zoom");
|
||||
assert.equal(s.cards.filter((c)=>c.name.startsWith("Standby")&&c.visible).length,0,"zero-W cards wait for a closer view");
|
||||
assert.equal(s.cards.find((c)=>c.name==="Verteiler").zoom,"1");
|
||||
await page.screenshot({path:join(out,"symcon-card-zoom-medium.png")});
|
||||
const stage=await page.evaluate(()=>window.zoomView.shadowRoot.querySelector(".nf-stage").getBoundingClientRect().toJSON());
|
||||
await page.mouse.move(stage.left+stage.width*.6,stage.top+stage.height*.8);await page.mouse.wheel({deltaY:900});
|
||||
await page.waitForFunction(()=>window.zoomView.viewer.getView().radius>50);
|
||||
await page.waitForFunction(()=>window.zoomView.shadowRoot.querySelector('[data-furniture="Lädt"]').style.visibility==="hidden");
|
||||
await page.mouse.wheel({deltaY:-1500});
|
||||
await page.waitForFunction(()=>[...window.zoomView.shadowRoot.querySelectorAll(".live-card-power")].some((c)=>c.dataset.furniture.startsWith("Standby")&&c.style.visibility==="visible"));
|
||||
s=await snapshot();const idle=s.cards.filter((c)=>c.name.startsWith("Standby")&&c.visible);
|
||||
assert.ok(idle.length>0&&idle.length<7,"the crowded standby cluster never becomes a seven-card tower");
|
||||
for(const c of s.cards.filter((c)=>c.visible&&!c.name.includes("live-card-house")))assert.ok(c.box.top>=c.stage.top&&c.box.bottom<=c.stage.bottom&&c.box.left>=c.stage.left&&c.box.right<=c.stage.right,`visible card leaves the stage: ${c.name}`);
|
||||
assert.equal(await page.evaluate(()=>window.zoomView.shadowRoot.querySelector('[data-furniture="Standby 1"] b').textContent),"0 W","zoom visibility never changes the underlying reading");
|
||||
await page.screenshot({path:join(out,"symcon-card-zoom-near.png")});
|
||||
await camera(4,{x:-1,y:1,z:1.5});
|
||||
await page.waitForFunction(()=>window.zoomView.shadowRoot.querySelector('[data-furniture="Standby 7"]').style.visibility==="visible");
|
||||
await camera(85);await page.setViewport({width:390,height:844});
|
||||
await page.waitForFunction(()=>window.zoomView.viewer.size.w===390);
|
||||
await camera(85);s=await snapshot();assert.ok(s.cards.filter((c)=>c.name.startsWith("Standby")).every((c)=>!c.visible));
|
||||
await camera(4,{x:-1,y:1,z:1.5});
|
||||
await page.waitForFunction(()=>window.zoomView.shadowRoot.querySelector('[data-furniture="Standby 7"]').style.visibility==="visible");
|
||||
s=await snapshot();assert.ok(s.cards.some((c)=>c.name.startsWith("Standby")&&c.visible));
|
||||
assert.ok(s.cards.filter((c)=>c.visible&&!c.name.includes("live-card-house")).every((c)=>c.box.top>=c.stage.top&&c.box.bottom<=c.stage.bottom&&c.box.left>=0&&c.box.right<=390));
|
||||
await page.screenshot({path:join(out,"symcon-card-zoom-mobile.png")});
|
||||
await page.evaluate(()=>window.zoomView.shadowRoot.querySelector(".nf-card-toggle").click());
|
||||
await page.waitForFunction(()=>!window.zoomView.shadowRoot.querySelector(".live-card"));
|
||||
assert.deepEqual(errors,[]);console.log("OK: actual perspective zoom and wheel gestures, idle/active device levels, hydronic/room detail levels, preserved totals, bounded clusters, close-up recovery, mobile view and global card switch");
|
||||
}finally{await browser?.close();await new Promise((done)=>server.close(done));}
|
||||
@@ -43,7 +43,7 @@ try {
|
||||
variable(306,"light",7,1,"Stecker verriegelt");
|
||||
variable(307,"switch",false,0,"Aus");
|
||||
variable(308,"cover",0,2,"0 W","W");
|
||||
window.chargingFloor = f.id; window.chargingRoom = room.id; window.chargingWrites = [];
|
||||
window.chargingFloor = f.id; window.chargingRoom = room.id; window.chargingWrites = []; window.chargingAt = {x:x+.5,y:f.elevation+1,z};
|
||||
p.data.edit(b); p.hass = { ...p.hass,language:"de",states,symconObjects:objects,callService:async (...args) => { window.chargingWrites.push(args); } };
|
||||
await p.updateComplete;
|
||||
[...p.shadowRoot.querySelectorAll("[role=tab]")].find((b) => b.textContent.includes("Editor")).click();
|
||||
@@ -84,7 +84,7 @@ try {
|
||||
[...p.shadowRoot.querySelectorAll("[role=tab]")].find((b) => b.textContent.trim()==="3D").click();
|
||||
});
|
||||
await page.waitForFunction(() => window.nfPanel.shadowRoot.querySelector("nf-view3d")?.viewer);
|
||||
await page.evaluate(async () => { window.chargingView=window.nfPanel.shadowRoot.querySelector("nf-view3d"); window.nfPanel.openFloor(window.chargingFloor); await window.nfPanel.updateComplete; });
|
||||
await page.evaluate(async () => { window.chargingView=window.nfPanel.shadowRoot.querySelector("nf-view3d"); window.nfPanel.openFloor(window.chargingFloor); await window.nfPanel.updateComplete; window.chargingView.viewer.showView({target:window.chargingAt,radius:8,phi:.9,theta:.35},0); });
|
||||
await page.waitForFunction(() => window.chargingView.shadowRoot.querySelector('.live-card-power[data-furniture="Ladestation"]')?.querySelectorAll(".live-charging-row").length===6);
|
||||
const readings = () => page.evaluate(() => [...window.chargingView.shadowRoot.querySelectorAll('.live-card-power[data-furniture="Ladestation"] .live-charging-row')].map((r)=>[r.dataset.reading,r.querySelector("b").textContent]));
|
||||
assert.deepEqual(await readings(),[["soc","0 %"],["start","12.11.2026, 14:30"],["end","18:00"],["duration","1:30:00"],["energy","12,7 kWh"],["lock","Stecker verriegelt"]]);
|
||||
@@ -103,7 +103,7 @@ try {
|
||||
await page.screenshot({path:join(out,"symcon-charging-desktop.png")});
|
||||
await page.setViewport({width:390,height:844});
|
||||
await page.waitForFunction(() => window.chargingView.viewer?.size.w===390);
|
||||
await page.evaluate(async () => { window.chargingView.resetView(); await new Promise((done)=>setTimeout(done,900)); });
|
||||
await page.evaluate(async () => { window.chargingView.viewer.showView({target:window.chargingAt,radius:6,phi:.9,theta:.35},0); await new Promise((done)=>setTimeout(done,100)); });
|
||||
assert.ok(await page.evaluate(() => [...window.chargingView.shadowRoot.querySelectorAll(".live-card-charging")].every((c)=>{const r=c.getBoundingClientRect(),s=c.parentElement.getBoundingClientRect();return c.style.visibility==="visible"&&r.left>=0&&r.right<=innerWidth&&r.top>=s.top&&r.bottom<=s.bottom;})),"charging cards fit narrow stage bounds");
|
||||
await page.screenshot({path:join(out,"symcon-charging-mobile.png")});
|
||||
await page.evaluate(() => [...window.nfPanel.shadowRoot.querySelectorAll("[role=tab]")].find((b)=>b.textContent.includes("Editor")).click());
|
||||
|
||||
@@ -39,7 +39,7 @@ try {
|
||||
};
|
||||
const node = (object_id, parent_id, name, object_type = 0, extra = {}) => ({ object_id, parent_id, name, object_type, path: `Haus / Garage / ${name}`, hidden: true, position: 0, icon: "", ...extra });
|
||||
const objects = [node(100, 0, "Haus"), node(101, 100, "Garage"), node(201, 101, "Wallbox Gesamtleistung", 2, { entity_id: "cover.201" }), node(202, 101, "Andere Leistung", 2, { entity_id: "sensor.202" })];
|
||||
window.powerFloor = f.id; window.powerRoom = room.id;
|
||||
window.powerFloor = f.id; window.powerRoom = room.id; window.powerAt = {x:x+3,y:f.elevation+1.2,z:z+1};
|
||||
p.data.edit(b); p.hass = { ...p.hass, language: "de", states, symconObjects: objects };
|
||||
await p.updateComplete;
|
||||
[...p.shadowRoot.querySelectorAll("[role=tab]")].find((b) => b.textContent.includes("Editor")).click();
|
||||
@@ -79,6 +79,7 @@ try {
|
||||
const toggle = v.shadowRoot.querySelector(".nf-card-toggle");
|
||||
if (toggle.getAttribute("aria-pressed") !== "false") throw new Error("Cards should begin disabled for this test");
|
||||
toggle.click();
|
||||
v.viewer.showView({target:window.powerAt,radius:8,phi:.9,theta:.35},0);
|
||||
});
|
||||
await page.waitForFunction(() => window.powerView.shadowRoot.querySelector('.live-card-power[data-furniture="Wallbox"]')?.style.visibility === "visible");
|
||||
const values = () => page.evaluate(() => [...window.powerView.shadowRoot.querySelectorAll(".live-card-power")].map((c) => [c.dataset.furniture, c.querySelector("b").textContent]));
|
||||
@@ -102,6 +103,7 @@ try {
|
||||
await page.evaluate(() => window.nfPanel.openFloor(null));
|
||||
await page.waitForFunction(() => window.powerView.shadowRoot.querySelectorAll(".live-card-power").length === 4);
|
||||
await page.evaluate(() => { window.nfPanel.openFloor(window.powerFloor); window.nfPanel._roomId = window.powerRoom; });
|
||||
await page.evaluate(()=>window.powerView.viewer.showView({target:window.powerAt,radius:8,phi:.9,theta:.35},0));
|
||||
await page.waitForFunction(() => window.powerView.shadowRoot.querySelector('.live-card-power[data-furniture="Wallbox"]')?.style.visibility === "visible");
|
||||
assert.ok((await values()).every(([name]) => name !== "Oben"), "selected rooms exclude furniture from other floors");
|
||||
await page.evaluate(async () => { window.nfPanel._roomId = null; await window.nfPanel.updateComplete; });
|
||||
@@ -110,16 +112,17 @@ try {
|
||||
const v = window.powerView, stage = v.shadowRoot.querySelector(".nf-stage");
|
||||
return v.viewer?.size.w === innerWidth && v.viewer.size.h === stage.clientHeight;
|
||||
});
|
||||
await page.evaluate(async () => { window.powerView.resetView(); await new Promise((done) => setTimeout(done, 900)); });
|
||||
await page.evaluate(async () => { window.powerView.viewer.showView({target:window.powerAt,radius:8,phi:.9,theta:.35},0); await new Promise((done) => setTimeout(done, 100)); });
|
||||
await page.waitForFunction(() => {
|
||||
const cards = [...window.powerView.shadowRoot.querySelectorAll(".live-card-power")];
|
||||
return cards.length === 3 && cards.every((c) => { const r = c.getBoundingClientRect(); return c.style.visibility === "visible" && r.left >= 0 && r.right <= innerWidth; });
|
||||
const visible=cards.filter((c)=>c.style.visibility==="visible");
|
||||
return cards.length === 3 && visible.length>0 && visible.every((c) => { const r = c.getBoundingClientRect(); return r.left >= 0 && r.right <= innerWidth; });
|
||||
}, { timeout: 5000 }).catch(async (error) => {
|
||||
console.log(await page.evaluate(() => ({ floor: window.powerView.floorId, room: window.powerView.roomId, cards: [...window.powerView.shadowRoot.querySelectorAll(".live-card-power")].map((c) => ({ name: c.dataset.furniture, visibility: c.style.visibility, rect: c.getBoundingClientRect().toJSON(), parent: c.parentElement.getBoundingClientRect().toJSON(), transform: c.style.transform, x: c.dataset.x, y: c.dataset.y })) })));
|
||||
await page.screenshot({ path: join(out, "symcon-power-cards-mobile-failure.png") });
|
||||
throw error;
|
||||
});
|
||||
const mobileCards = await page.evaluate(() => [...window.powerView.shadowRoot.querySelectorAll(".live-card-power")].map((c) => {
|
||||
const mobileCards = await page.evaluate(() => [...window.powerView.shadowRoot.querySelectorAll(".live-card-power")].filter((c)=>c.style.visibility==="visible").map((c) => {
|
||||
const r = c.getBoundingClientRect(), stage = c.parentElement.getBoundingClientRect();
|
||||
return { name: c.dataset.furniture, top: r.top, bottom: r.bottom, stageTop: stage.top, stageBottom: stage.bottom };
|
||||
}));
|
||||
|
||||
Reference in new issue
Block a user