fix: support Symcon numeric dimmers and independent blind slat controls
This commit is contained in:
1 parent
b934f78b9a
commit
24188f96f7
36 files changed
+1105
-683
No files matched your search
@@ -5,6 +5,7 @@ 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";
|
||||
import { build } from "esbuild";
|
||||
|
||||
const root = resolve(import.meta.dirname, "..");
|
||||
const types = { ".html": "text/html", ".js": "text/javascript", ".json": "application/json", ".png": "image/png" };
|
||||
@@ -109,8 +110,127 @@ try {
|
||||
const r = window.nfPanel.shadowRoot.querySelector(".nf-reload-variables").getBoundingClientRect();
|
||||
return r.left >= 0 && r.right <= innerWidth;
|
||||
}), true, "reload button fits the mobile title bar");
|
||||
|
||||
// Exercise the actual adapter's numeric roles and the designer's real object-tree fields.
|
||||
const adapter = await build({ entryPoints: [join(root, "frontend/src/symcon-bridge.ts")], bundle: true, write: false, format: "iife", globalName: "SymconAdapter", logLevel: "silent" });
|
||||
await page.addScriptTag({ content: adapter.outputFiles[0].text });
|
||||
await page.setViewport({ width: 1440, height: 1000 });
|
||||
await page.evaluate(async () => {
|
||||
const raw = (id, name, max, value, entity = `sensor.${id}`) => ({ entity_id: entity, name, path: `Haus / KNX / ${name}`, state: String(value), attributes: { symcon_id: id, symcon_variable_type: 1, symcon_numeric_value: value, symcon_min: 0, symcon_max: max, symcon_step: 1, symcon_has_action: true } });
|
||||
const variables = [raw(42, "Dimmerwert", 255, 128, "cover.42"), raw(101, "Behang Position", 100, 40), raw(102, "Lamellen Position", 255, 128)];
|
||||
const objects = [{ object_id: 100, parent_id: 0, name: "Haus", path: "Haus", object_type: 0, position: 0, hidden: true, icon: "" },
|
||||
...variables.map((v) => ({ object_id: v.attributes.symcon_id, parent_id: 100, name: v.name, path: v.path, entity_id: v.entity_id, object_type: 2, position: 0, hidden: false, icon: "" }))];
|
||||
const originalFetch = window.fetch;
|
||||
window.actuatorCalls = [];
|
||||
window.fetch = async (url, init) => {
|
||||
if (!String(url).includes("/hook/controls-fixture/")) return originalFetch(url, init);
|
||||
const request = JSON.parse(init.body);
|
||||
if (request.action === "variables/action") { window.actuatorCalls.push(request); return new Response("[]"); }
|
||||
return new Response(JSON.stringify({ state_revision: 1, building_revision: 1, variables, objects, areas: [] }));
|
||||
};
|
||||
window.__NEXTFLOOR_SYMCON__ = { endpoint: "/hook/controls-fixture", token: "fixture-only" };
|
||||
const bridge = new window.SymconAdapter.SymconBridge();
|
||||
const h = await bridge.start();
|
||||
bridge.stop();
|
||||
const p = window.nfPanel;
|
||||
p.hass = { ...p.hass, states: h.states, entities: h.entities, symconObjects: h.symconObjects, callService: h.callService };
|
||||
await p.updateComplete;
|
||||
const e = window.ed;
|
||||
await e.updateComplete;
|
||||
const f = e._doc.floors[0];
|
||||
const lamp = f.furniture.find((m) => m.type.startsWith("lamp_"));
|
||||
lamp.x = f.rooms[0].points.reduce((sum, p) => sum + p[0], 0) / f.rooms[0].points.length;
|
||||
lamp.z = f.rooms[0].points.reduce((sum, p) => sum + p[1], 0) / f.rooms[0].points.length;
|
||||
window.controlLamp = lamp.id;
|
||||
lamp.entity = "none";
|
||||
e.selectItem("furniture", lamp.id);
|
||||
await e.updateComplete;
|
||||
window.chooseControl = async (picker, objectId, name) => {
|
||||
await picker.updateComplete;
|
||||
const native = picker.shadowRoot.querySelector("nf-symcon-object-picker");
|
||||
await native.updateComplete;
|
||||
native.shadowRoot.querySelector(".trigger").click();
|
||||
await native.updateComplete;
|
||||
const input = native.shadowRoot.querySelector(".search");
|
||||
input.value = name;
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
await native.updateComplete;
|
||||
const row = native.shadowRoot.querySelector(`#object-${objectId}`);
|
||||
if (!row?.classList.contains("selectable")) throw new Error(`Variable ${name} is not selectable for its explicit role`);
|
||||
row.click();
|
||||
await native.updateComplete;
|
||||
native.shadowRoot.querySelector(".apply").click();
|
||||
await e.updateComplete;
|
||||
};
|
||||
const picker = [...e.shadowRoot.querySelectorAll("nf-entity-picker")].find((p) => p.options.some((o) => o.id === "light.42"));
|
||||
await window.chooseControl(picker, 42, "Dimmerwert");
|
||||
const opening = e._doc.floors[0].openings.find((o) => o.type === "window");
|
||||
window.controlWindow = opening.id;
|
||||
opening.room_id = e._doc.floors[0].rooms[0].id;
|
||||
opening.cover = "none";
|
||||
opening.cover_tilt = null;
|
||||
opening.blind = "venetian";
|
||||
e.selectItem("opening", opening.id);
|
||||
await e.updateComplete;
|
||||
const field = (label) => [...e.shadowRoot.querySelectorAll("label.nf-field")].find((el) => el.textContent.trim().startsWith(label))?.querySelector("nf-entity-picker");
|
||||
if (!field("Lamellenposition")) throw new Error("Slat selector must already exist before a position is selected");
|
||||
await window.chooseControl(field("Position (Behang)"), 101, "Behang Position");
|
||||
await window.chooseControl(field("Lamellenposition"), 102, "Lamellen Position");
|
||||
const roomPanel = document.createElement("nf-room-panel");
|
||||
Object.assign(roomPanel, { hass: p.hass, building: e._doc, floor: e._doc.floors[0], room: e._doc.floors[0].rooms[0] });
|
||||
roomPanel.id = "controls-room";
|
||||
roomPanel.style = "position:fixed;right:12px;top:80px;width:370px;max-height:85vh;overflow:auto;z-index:1000;background:#202020";
|
||||
document.body.append(roomPanel);
|
||||
await roomPanel.updateComplete;
|
||||
const quick = document.createElement("nf-quick-menu");
|
||||
Object.assign(quick, { hass: p.hass, entity: "cover.101", tiltEntity: "cover.102" });
|
||||
quick.id = "controls-quick";
|
||||
quick.style = "position:fixed;left:30px;top:270px;z-index:1001";
|
||||
document.body.append(quick);
|
||||
await quick.updateComplete;
|
||||
});
|
||||
assert.deepEqual(await page.evaluate(() => {
|
||||
const f = window.ed._doc.floors[0];
|
||||
const o = f.openings.find((o) => o.id === window.controlWindow);
|
||||
return [f.furniture.find((m) => m.id === window.controlLamp).entity, o.cover, o.cover_tilt];
|
||||
}), ["light.42", "cover.101", "cover.102"], "object-tree confirmations retain distinct native integer variables");
|
||||
await page.evaluate(async () => {
|
||||
const panel = document.querySelector("#controls-room");
|
||||
const set = (input, value) => { if (!input) throw new Error("Expected control slider is missing"); input.value = value; input.dispatchEvent(new Event("change", { bubbles: true })); };
|
||||
const rows = [...panel.shadowRoot.querySelectorAll(".nf-rp-row")];
|
||||
const light = rows.find((r) => r.textContent.includes("Dimmerwert"));
|
||||
set(light?.querySelector('input[type="range"]'), "25");
|
||||
const blind = rows.find((r) => r.textContent.includes("Behang Position"));
|
||||
const sliders = blind?.querySelectorAll('input[type="range"]');
|
||||
set(sliders?.[0], "60");
|
||||
set(sliders?.[1], "30");
|
||||
const quick = document.querySelector("#controls-quick");
|
||||
set(quick.shadowRoot.querySelector(".qm-tilt input"), "70");
|
||||
const off = { ...panel.hass.states["light.42"], state: "off", attributes: { ...panel.hass.states["light.42"].attributes, brightness: 0 } };
|
||||
panel.hass = { ...panel.hass, states: { ...panel.hass.states, "light.42": off } };
|
||||
await panel.updateComplete;
|
||||
const offRow = [...panel.shadowRoot.querySelectorAll(".nf-rp-row")].find((r) => r.textContent.includes("Dimmerwert"));
|
||||
if (!offRow?.querySelector('input[type="range"]')) throw new Error("An off dimmer lost its brightness slider");
|
||||
});
|
||||
await page.waitForFunction(() => window.actuatorCalls.length === 4);
|
||||
assert.deepEqual(await page.evaluate(() => window.actuatorCalls.map((c) => [c.domain, c.service, c.data])), [
|
||||
["light", "turn_on", { entity_id: "light.42", brightness_pct: 25 }],
|
||||
["cover", "set_cover_position", { entity_id: "cover.101", position: 60 }],
|
||||
["cover", "set_cover_tilt_position", { entity_id: "cover.102", tilt_position: 30 }],
|
||||
["cover", "set_cover_tilt_position", { entity_id: "cover.102", tilt_position: 70 }],
|
||||
]);
|
||||
await page.evaluate(async () => {
|
||||
const e = window.ed;
|
||||
e._doc.floors[0].placements.push({ entity_id: "cover.101", x: 1, z: 1, y: null });
|
||||
e.selectItem("device", "cover.101");
|
||||
await e.updateComplete;
|
||||
const field = [...e.shadowRoot.querySelectorAll("label.nf-field")].find((el) => el.textContent.trim().startsWith("Lamellenposition"));
|
||||
await window.chooseControl(field.querySelector("nf-entity-picker"), 102, "Lamellen Position");
|
||||
});
|
||||
assert.equal(await page.evaluate(() => window.ed._doc.floors[0].placements.find((p) => p.entity_id === "cover.101").cover_tilt), "cover.102", "standalone blinds also expose the actual native slat picker");
|
||||
await page.screenshot({ path: join(out, "symcon-dimmer-blind-controls.png") });
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("OK: collapsible walls, reload progress/error/duplicate protection, unchanged plan, updated object pickers, KNX temperature selection and mobile header");
|
||||
console.log("OK: collapsible walls, variable reload, KNX temperature, numeric dimmer/position/slat tree bindings, off-state dimming and independent room/quick-menu commands");
|
||||
} finally {
|
||||
await browser?.close();
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
|
||||
Reference in new issue
Block a user