feat: add native Symcon archive trends and explicit room naming

This commit is contained in:
jhartworks committed 2026-11-11 12:00:51 +01:00
1 parent bb153490b0
commit cfc77787a0
28 files changed
+2449 -1250

No files matched your search

+103 -4
View File
@@ -20,6 +20,8 @@ try {
browser = await puppeteer.launch({ executablePath, headless: true, args: ["--use-angle=swiftshader", "--enable-unsafe-swiftshader"] });
const page = await browser.newPage();
const errors = [];
let trendAssetRequests = 0;
page.on("request", (r) => { if (r.url().includes("/nextfloor-trend.js")) trendAssetRequests++; });
page.on("pageerror", (e) => errors.push(String(e)));
await page.evaluateOnNewDocument(() => localStorage.setItem("nextfloor.cards", "0"));
await page.setViewport({ width: 1440, height: 1000 });
@@ -31,6 +33,7 @@ try {
window.humidityValue = 51.6;
window.bootstrapCalls = 0;
window.nativeCalls = [];
window.trendRequests = [];
window.presenceValue = true;
window.rainValue = false;
const raw = (id, name, type, value, unit, domain = "sensor") => ({ entity_id: `${domain}.${id}`, name, path: `Haus / DP KNX / OG Allgemein / Heizen Kühlen / RAT Teeküche / Weiterer Unterordner / Messwerte / ${name}`, state: domain === "cover" ? "open" : String(value), attributes: { symcon_id: id, symcon_variable_type: type, symcon_value: value, symcon_numeric_value: typeof value === "number" ? value : undefined, symcon_formatted: `${String(value).replace(".", ",")}${unit ? ` ${unit}` : ""}`, unit_of_measurement: unit } });
@@ -38,6 +41,15 @@ try {
window.fetch = async (url, init) => {
if (!String(url).includes("/hook/climate-fixture/")) return originalFetch(url, init);
const request = JSON.parse(init.body);
if (request.action === "archive/trend") {
window.trendRequests.push(request);
if (window.trendReject) return new Response(JSON.stringify({ error: "fixture_archive_unavailable" }), { status: 404 });
const span = request.end - request.start;
const aggregation = request.aggregation === "auto" ? span <= 172800 ? "raw" : "hour" : request.aggregation;
const type = request.entity_id.endsWith("219") ? 3 : request.entity_id.endsWith("213") ? 0 : 2;
const points = window.trendEmpty ? [] : Array.from({ length: 6 }, (_, i) => ({ t: request.start + Math.floor(span * i / 6), d: span / 6, v: type === 3 ? i ? "Raum belegt" : "=1+2" : type === 0 ? i % 2 : 20 + i / 3, min: 19, max: 23 }));
return new Response(JSON.stringify({ entity_id: request.entity_id, start: request.start, end: request.end, aggregation, counter: false, type, truncated: !!window.trendTruncated, points }));
}
if (request.action === "variables/action") { window.nativeCalls.push(request); return new Response("[]"); }
window.bootstrapCalls++;
const variables = [raw(201, "Raumtemperatur", 2, 21.5, "°C"), raw(202, "Messwert Raumfeuchtigkeit", 2, window.humidityValue, "%", "cover"), raw(203, "CO₂", 1, 780, "ppm"), raw(204, "Raumhelligkeit", 2, 320.5, "lx"), raw(205, "Zusatztemperatur", 2, 21.5, "°C")];
@@ -49,19 +61,22 @@ try {
status.attributes.symcon_formatted = "Besprechung";
variables.push(heating, raw(207, "Zuluft Volumenstrom", 2, 120, "m³/h"), raw(208, "Abluft Volumenstrom", 2, 110, "m³/h"), raw(209, "Zuluft Temperatur", 2, 19.6, "°C"), raw(210, "Abluft Temperatur", 2, 22.3, "°C"), reheat, status,
raw(213, "Hannes anwesend", 0, window.presenceValue, "", "light"), raw(214, "Regenkontakt", 0, window.rainValue, "", "cover"), raw(215, "Windmessung", 2, 8, "m/s", "climate"), raw(216, "Wolkenmessung", 1, 65, "%"));
variables.push(raw(219, "Raumtext", 3, "Frei", ""));
for (const v of variables) if ([201, 203, 206, 213, 215, 219].includes(v.attributes.symcon_id)) v.attributes.symcon_archive = { id: 999, counter: false, first: 1, last: 1794384000 };
for (const id of [217, 218]) variables.push({ entity_id: `schedule.${id}`, name: id === 217 ? "Heizzeiten" : "Lüftungszeiten", path: `Haus / Schaltuhren / ${id === 217 ? "Heizzeiten" : "Lüftungszeiten"}`, state: "on", attributes: { symcon_id: id, symcon_schedule: true, next_run: 1794387600, next_action: 2, actions: [{ id: 1, name: "Nacht", color: 255 }, { id: 2, name: "Tag", color: 16711680 }], groups: [{ id: 0, days: 31, points: [{ hour: 6, minute: 30, second: 0, action: 2 }, { hour: 20, minute: 0, second: 0, action: 1 }] }] } });
const objects = [{ object_id: 100, parent_id: 0, name: "Haus", path: "Haus", object_type: 0, position: 0, hidden: true, icon: "" },
const objects = [{ object_id: 100, parent_id: 0, name: "Technik", path: "Gebäude / OG / Technik", object_type: 0, position: 0, hidden: true, icon: "" },
...variables.map((v) => ({ object_id: v.attributes.symcon_id, parent_id: 100, entity_id: v.entity_id, name: v.name, path: v.path, object_type: v.attributes.symcon_schedule ? 4 : 2, position: 0, hidden: false, icon: "" }))];
return new Response(JSON.stringify({ state_revision: window.bootstrapCalls, building_revision: 1, variables, objects, areas: [] }));
return new Response(JSON.stringify({ state_revision: window.bootstrapCalls, building_revision: 1, variables, objects, areas: [{ area_id: "symcon-category-100", name: "Gebäude / OG / Technik" }] }));
};
window.__NEXTFLOOR_SYMCON__ = { endpoint: "/hook/climate-fixture", token: "fixture-only" };
const bridge = new window.SymconAdapter.SymconBridge();
await bridge.start();
bridge.stop();
const p = window.nfPanel;
const originalCallWS = p.hass.callWS;
const apply = () => {
const h = bridge.snapshot();
p.hass = { ...p.hass, language: "de", states: h.states, entities: h.entities, symconObjects: h.symconObjects, symconRefresh: h.symconRefresh, callService: h.callService };
p.hass = { ...p.hass, language: "de", states: h.states, entities: h.entities, areas: h.areas, symconObjects: h.symconObjects, symconRefresh: h.symconRefresh, callService: h.callService, callWS: (message) => message.type === "nextfloor/archive/trend" ? h.callWS(message) : originalCallWS(message) };
};
apply();
bridge.onChange(apply);
@@ -77,6 +92,16 @@ try {
window.climateFloorId = e._floorId;
e.selectItem("room", window.climateRoomId);
await e.updateComplete;
const name = [...e.shadowRoot.querySelectorAll("label.nf-field")].find((el) => el.textContent.trim() === e.t("room_name")).querySelector("input");
name.value = "Raum 12"; name.dispatchEvent(new Event("change", { bubbles: true }));
await e.updateComplete; await window.nfPanel.updateComplete; await e.updateComplete;
const area = [...e.shadowRoot.querySelectorAll("label.nf-field")].find((el) => el.textContent.trim().startsWith(e.t("area"))).querySelector("select");
area.value = "symcon-category-100"; area.dispatchEvent(new Event("change", { bubbles: true }));
await e.updateComplete; await window.nfPanel.updateComplete; await e.updateComplete;
if (e._doc.floors[0].rooms[0].name !== "Raum 12") throw new Error("Choosing an area must not rename a Symcon room");
e.shadowRoot.querySelector(".nf-take-area-name").click();
await e.updateComplete; await window.nfPanel.updateComplete; await e.updateComplete;
if (e._doc.floors[0].rooms[0].name !== "Technik") throw new Error("The explicit name button must copy only the native leaf category");
const section = [...e.shadowRoot.querySelectorAll("details.nf-points")].find((d) => d.querySelector("summary").textContent === "Raumklima");
section.open = true;
window.climateSection = section;
@@ -220,6 +245,80 @@ try {
assert.equal(await page.evaluate(() => window.climateView.hass.states["weather.nextfloor_symcon"].state), "rainy");
await page.waitForFunction(() => [...window.climateView.shadowRoot.querySelectorAll(".live-card-roomclimate")].every((c) => c.style.visibility === "visible"));
await page.screenshot({ path: join(out, "symcon-climate-desktop.png") });
assert.equal(trendAssetRequests, 0, "the chart bundle stays lazy until a trend is opened");
assert.equal(await page.evaluate(() => !!window.climateView.shadowRoot.querySelector(`.live-card[data-room="${window.climateRoomId}"] .live-climate-humidity nf-trend-button`)), false, "unlogged values have no trend icon");
await page.evaluate(async () => {
const b = window.climateView.shadowRoot.querySelector(`.live-card[data-room="${window.climateRoomId}"] .live-climate-temperature nf-trend-button`);
await b.updateComplete; b.shadowRoot.querySelector("button").click();
});
await page.waitForFunction(() => document.querySelector("nf-trend-dialog")?.shadowRoot.querySelector(".plot path"));
assert.equal(trendAssetRequests, 1);
await page.evaluate(() => { window.trendDialog = document.querySelector("nf-trend-dialog"); });
assert.equal(await page.evaluate(() => window.trendRequests.at(-1).entity_id), "sensor.201");
await page.evaluate(async () => {
const d = window.trendDialog;
if (!d.shadowRoot.querySelector("dialog").open) throw new Error("Trend must open as a modal");
[...d.shadowRoot.querySelectorAll(".presets button")].find((b) => b.textContent === "7 Tage").click();
});
await page.waitForFunction(() => window.trendDialog.series[0]?.aggregation === "hour");
assert.equal(await page.evaluate(() => { const r = window.trendRequests.at(-1); return r.end - r.start; }), 604800);
await page.evaluate(async () => {
const d = window.trendDialog; d.shadowRoot.querySelector(".settings").open = true;
const inputs = d.shadowRoot.querySelectorAll('input[type="number"]');
for (const [i, value] of [[0, "15"], [1, "30"]]) { inputs[i].value = value; inputs[i].dispatchEvent(new Event("input", { bubbles: true })); }
const selects = d.shadowRoot.querySelectorAll(".settings select"); selects[0].value = "bar"; selects[0].dispatchEvent(new Event("change", { bubbles: true }));
await d.updateComplete;
if (!d.shadowRoot.querySelector(".plot g rect")) throw new Error("Selectable bar chart is missing");
const resolution = d.shadowRoot.querySelector("form select"); resolution.value = "day"; resolution.dispatchEvent(new Event("change", { bubbles: true }));
});
await page.waitForFunction(() => window.trendDialog.series[0]?.aggregation === "day");
await page.evaluate(async () => {
const d = window.trendDialog, min = d.shadowRoot.querySelector('input[type="number"]'); min.value = "40"; min.dispatchEvent(new Event("input", { bubbles: true })); await d.updateComplete;
if (!d.shadowRoot.textContent.includes("kleiner")) throw new Error("Invalid manual value range must be explained");
min.value = "15"; min.dispatchEvent(new Event("input", { bubbles: true })); await d.updateComplete;
const from = d.shadowRoot.querySelectorAll('input[type="datetime-local"]')[0]; from.value = "2099-01-01T00:00"; from.dispatchEvent(new Event("change", { bubbles: true }));
d.shadowRoot.querySelector("form").dispatchEvent(new Event("submit", { bubbles: true, cancelable: true })); await d.updateComplete;
if (!d.shadowRoot.textContent.includes("Ende muss nach")) throw new Error("Invalid time range must be explained");
d.shadowRoot.querySelector(".presets button").click();
});
await page.waitForFunction(() => window.trendDialog.series[0]?.points.length === 6);
await page.evaluate(async () => {
window.trendEmpty = true;
[...window.trendDialog.shadowRoot.querySelectorAll("button")].find((b) => b.textContent === "Aktualisieren").click();
});
await page.waitForFunction(() => window.trendDialog.shadowRoot.textContent.includes("Keine Archivwerte"));
await page.evaluate(() => { window.trendEmpty = false; window.trendReject = true; [...window.trendDialog.shadowRoot.querySelectorAll("button")].find((b) => b.textContent === "Aktualisieren").click(); });
await page.waitForFunction(() => window.trendDialog.shadowRoot.textContent.includes("fixture_archive_unavailable"));
await page.evaluate(() => { window.trendReject = false; window.trendTruncated = true; [...window.trendDialog.shadowRoot.querySelectorAll("button")].find((b) => b.textContent === "Aktualisieren").click(); });
await page.waitForFunction(() => window.trendDialog.shadowRoot.textContent.includes("10.000 Einträge"));
await page.evaluate(async () => {
const original = URL.createObjectURL.bind(URL), click = HTMLAnchorElement.prototype.click;
URL.createObjectURL = (blob) => { window.exportedTrendCsv = blob; return original(blob); };
HTMLAnchorElement.prototype.click = function() { if (this.download !== "Symcon-Trend.csv") return click.call(this); };
[...window.trendDialog.shadowRoot.querySelectorAll("button")].find((b) => b.textContent === "CSV").click();
URL.createObjectURL = original; HTMLAnchorElement.prototype.click = click;
if (!(await window.exportedTrendCsv.text()).includes("Zeit;Wert")) throw new Error("CSV export is missing");
window.trendTruncated = false;
[...window.trendDialog.shadowRoot.querySelectorAll("button")].find((b) => b.textContent === "Aktualisieren").click();
});
await page.waitForFunction(() => window.trendDialog.series[0]?.points.length === 6 && !window.trendDialog.loading);
await page.screenshot({ path: join(out, "symcon-trend-desktop.png") });
await page.setViewport({ width: 390, height: 844 });
await page.waitForFunction(() => window.trendDialog.width < 400);
assert.equal(await page.evaluate(() => { const r = window.trendDialog.shadowRoot.querySelector("dialog").getBoundingClientRect(); return r.left >= 0 && r.right <= innerWidth; }), true);
await page.screenshot({ path: join(out, "symcon-trend-mobile.png") });
await page.keyboard.press("Escape");
await page.waitForFunction(() => !document.querySelector("nf-trend-dialog"));
for (const [ids, table] of [[["sensor.219"], true], [["light.213"], false], [["sensor.201", "sensor.203"], false]]) {
await page.evaluate(async (ids) => {
const b = document.createElement("nf-trend-button"); Object.assign(b, { hass: window.nfPanel.hass, ids, label: "Raumwerte" }); document.body.append(b); await b.updateComplete; b.shadowRoot.querySelector("button").click(); window.testTrendButton = b;
}, ids);
await page.waitForFunction(() => document.querySelector("nf-trend-dialog")?.series.length);
assert.equal(await page.evaluate(() => !!document.querySelector("nf-trend-dialog").shadowRoot.querySelector("table")), table);
if (ids.length === 2) assert.equal(await page.evaluate(() => document.querySelector("nf-trend-dialog").shadowRoot.querySelectorAll(".chart-group").length), 2, "different units have separate axes");
await page.keyboard.press("Escape"); await page.waitForFunction(() => !document.querySelector("nf-trend-dialog"));
await page.evaluate(() => window.testTrendButton.remove());
}
await page.setViewport({ width: 390, height: 844 });
await page.evaluate(() => { window.nfPanel.narrow = true; });
await page.waitForFunction(() => [...window.climateView.shadowRoot.querySelectorAll(".live-card-roomclimate")].every((c) => { const r = c.getBoundingClientRect(); return r.left >= 0 && r.right <= innerWidth; }));
@@ -230,7 +329,7 @@ try {
await page.evaluate(() => window.climateView.shadowRoot.querySelector(".nf-card-toggle").click());
await page.waitForFunction(() => !window.climateView.shadowRoot.querySelector(".live-card-roomclimate"));
assert.deepEqual(errors, []);
console.log("OK: native float humidity picker, saved per-room card setting, temperature/humidity/CO2 values, missing data, live reload, no-energy toggle, desktop/mobile and opened-room cards");
console.log("OK: native climate/HVAC/schedules/weather/presence; explicit area leaf-name adoption; lazy archive trends with time/resolution/Y range, raw/Boolean/string data, CSV, error/empty/limit states, separate units and desktop/mobile dialogs");
} finally {
await browser?.close();
await new Promise((done) => server.close(done));