fix: retain Symcon webhook registration and show configured view title
This commit is contained in:
1 parent
8845efdc23
commit
510aece983
14 files changed
+145
-44
No files matched your search
@@ -372,13 +372,14 @@ export class NextFloorPanel extends LitElement {
|
||||
}
|
||||
|
||||
private renderHeader(building: Building | null) {
|
||||
const title = this.hass?.symconTitle?.trim() || "NextFloor";
|
||||
const saveState = this.data.saveState;
|
||||
const tab = (mode: Mode, label: string, extra = "") =>
|
||||
html`<button role="tab" class=${extra} aria-pressed=${this._mode === mode} @click=${() => this.setMode(mode)}>${label}</button>`;
|
||||
const saveLabel: Key = saveState === "saving" ? "saving" : saveState === "saved" ? "saved" : "save_error";
|
||||
return html`<header class="nf-header">
|
||||
<ha-menu-button .hass=${this.hass} .narrow=${this.narrow}></ha-menu-button>
|
||||
<h1>${NEXTFLOOR_MARK}NextFloor</h1>
|
||||
<h1 title=${title}>${NEXTFLOOR_MARK}<span class="nf-view-title">${title}</span></h1>
|
||||
${this.isAdmin ? html`<div class="nf-seg" role="tablist">${tab("view", this.t("view"))}${tab("editor", this.t("editor"))}${tab("extensions", `✦ ${this.t("ext_tab")}`, "nf-tab-ext")}</div>` : nothing}
|
||||
<span class="nf-grow"></span>
|
||||
${this._mode === "view" && building?.floors.some((f) => f.rooms.length) ? html`<button class="nf-chip nf-room-names-toggle" aria-pressed=${this._prefs.roomNames} title=${this.t("room_names_toggle_hint")} @click=${() => this.setPref("roomNames", !this._prefs.roomNames)}>${this.t("room_names_short")}</button>` : nothing}
|
||||
|
||||
@@ -52,10 +52,17 @@ export const panelStyles = css`
|
||||
white-space: nowrap;
|
||||
}
|
||||
.nf-mark {
|
||||
flex: none;
|
||||
width: 26px;
|
||||
height: 28px;
|
||||
color: var(--nf-accent);
|
||||
}
|
||||
.nf-view-title {
|
||||
min-width: 0;
|
||||
max-width: min(340px, 45vw);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.nf-notices {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
|
||||
@@ -4,15 +4,22 @@ import { SymconBridge } from "./symcon-bridge.ts";
|
||||
import { entityOptions } from "./components/editor/entities.ts";
|
||||
import { areaEntities } from "./entities/registry.ts";
|
||||
|
||||
function mockWindow(context: TestContext): void {
|
||||
function mockWindow(context: TestContext, title?: string): void {
|
||||
const previous = Object.getOwnPropertyDescriptor(globalThis, "window");
|
||||
Object.defineProperty(globalThis, "window", { configurable: true, value: { __NEXTFLOOR_SYMCON__: { endpoint: "/hook/test", token: "fixture" } } });
|
||||
Object.defineProperty(globalThis, "window", { configurable: true, value: { __NEXTFLOOR_SYMCON__: { endpoint: "/hook/test", token: "fixture", title } } });
|
||||
context.after(() => {
|
||||
if (previous) Object.defineProperty(globalThis, "window", previous);
|
||||
else Reflect.deleteProperty(globalThis, "window");
|
||||
});
|
||||
}
|
||||
|
||||
test("configured view names are exposed to the header with a safe empty-name fallback", (context) => {
|
||||
mockWindow(context, " Haus & Büro <West> ");
|
||||
assert.equal(new SymconBridge().snapshot().symconTitle, "Haus & Büro <West>");
|
||||
window.__NEXTFLOOR_SYMCON__!.title = " ";
|
||||
assert.equal(new SymconBridge().snapshot().symconTitle, "NextFloor");
|
||||
});
|
||||
|
||||
test("numeric control roles stay selectable in the real tree without duplicating automatic device lists", async (context) => {
|
||||
mockWindow(context);
|
||||
context.mock.method(globalThis, "fetch", async () => new Response(JSON.stringify({ state_revision: 1, building_revision: 1, areas: [{ area_id: "room", name: "Raum" }],
|
||||
|
||||
@@ -81,6 +81,7 @@ export class SymconBridge {
|
||||
entities: this.entities,
|
||||
areas: this.areas,
|
||||
symconObjects: [],
|
||||
symconTitle: this.settings.title?.trim() || "NextFloor",
|
||||
symconRefresh: () => this.refresh(true),
|
||||
config: { unit_system: { temperature: "°C" } },
|
||||
themes: { darkMode: window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? true },
|
||||
|
||||
@@ -76,6 +76,8 @@ export interface HomeAssistant {
|
||||
devices?: Record<string, HassDevice>;
|
||||
/** Present only in the Symcon host. The full native hierarchy, including non-variable nodes. */
|
||||
symconObjects?: readonly SymconObject[];
|
||||
/** Configured visualization name of this Symcon instance. */
|
||||
symconTitle?: string;
|
||||
/** Reload variables, effective presentations and the native object tree without reloading the plan. */
|
||||
symconRefresh?: () => Promise<void>;
|
||||
states: Record<string, HassEntity>;
|
||||
|
||||
@@ -25,6 +25,7 @@ try {
|
||||
await page.setViewport({ width: 1440, height: 1000 });
|
||||
await page.goto(`http://127.0.0.1:${server.address().port}/preview/index.html`, { waitUntil: "networkidle0" });
|
||||
await page.waitForFunction(() => window.nfPanel?.data.building?.floors.length);
|
||||
assert.equal(await page.evaluate(() => window.nfPanel.shadowRoot.querySelector("h1").textContent.trim()), "NextFloor", "the normal preview retains the default title");
|
||||
await page.evaluate(async () => {
|
||||
const p = window.nfPanel;
|
||||
p._floorId = p.data.building.floors[0].id;
|
||||
@@ -167,13 +168,14 @@ try {
|
||||
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" };
|
||||
window.__NEXTFLOOR_SYMCON__ = { endpoint: "/hook/controls-fixture", token: "fixture-only", title: "Haus & Büro <West>" };
|
||||
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 };
|
||||
p.hass = { ...p.hass, states: h.states, entities: h.entities, symconObjects: h.symconObjects, symconTitle: h.symconTitle, callService: h.callService };
|
||||
await p.updateComplete;
|
||||
if (p.shadowRoot.querySelector("h1 .nf-view-title").textContent !== "Haus & Büro <West>" || p.shadowRoot.querySelector("h1 west")) throw new Error("Configured view name must replace the brand text as plain text");
|
||||
const e = window.ed;
|
||||
await e.updateComplete;
|
||||
const f = e._doc.floors[0];
|
||||
|
||||
Reference in new issue
Block a user