feat: add 3D hydronic manifolds buffer tanks and fresh water stations

This commit is contained in:
jhartworks committed 2026-11-12 14:28:30 +01:00
1 parent 93c015ec77
commit 173d02e3cc
37 files changed
+3253 -1815

No files matched your search

@@ -17,6 +17,8 @@ import { dataField, TARGET_EXAMPLES } from "./house.ts";
import { parkingForm } from "./parking.ts";
import { stairForm } from "./stairs.ts";
import { DEFAULT_STAIR } from "../../../geometry/stairs.ts";
import { isHydronic } from "../../../hydronic-model.ts";
import { renderHydronicForm } from "./hydronic.ts";
export interface FurnitureActions extends FurnitureLinkActions {
rotate(delta: number): void;
@@ -239,7 +241,7 @@ export function renderFurnitureForm(host: EditorHost, item: Furniture, actions:
<div class="nf-h3row"><h3>${item.name || host.t("furniture")}</h3>${actions.lockButton}</div>
<div class="nf-form">${nameFields(host, item, actions)} ${kindField(host, item, actions.packs, actions)} ${geometryFields(host, item, actions)}</div>
${typeNotes(host, item, actions)} ${item.type === "stairs" && item.stair ? stairForm(host, item, actions) : nothing} ${variantField(host, item, actions)} ${paintField(host, item, actions)}
${links} ${item.type.endsWith(":sprinkler") ? html`<div class="nf-form">${numberField(host, host.t("spray_reach"), item.spray ?? 3, (v) => actions.update({ spray: Math.min(15, Math.max(0.5, v)) }), 0.5, 0.5)}${hint(host.t("spray_hint"), "nf-wide")}</div>` : nothing}
${isHydronic(item.type) ? renderHydronicForm(host, item, (patch) => actions.update(patch)) : links} ${item.type.endsWith(":sprinkler") ? html`<div class="nf-form">${numberField(host, host.t("spray_reach"), item.spray ?? 3, (v) => actions.update({ spray: Math.min(15, Math.max(0.5, v)) }), 0.5, 0.5)}${hint(host.t("spray_hint"), "nf-wide")}</div>` : nothing}
${hasPicture(item.type) ? pictureFields(host, item, actions) : nothing}
${packItem(item.type)?.pet
? html`<div class="nf-form nf-links">${entityField(host, host.t("pet_room_sensor"), item.room_sensor ?? null, undefined, entityOptions(host.hass, (id) => /^(sensor|device_tracker|input_select|select)\./.test(id)), (v) => actions.update({ room_sensor: v && v !== "none" ? v : null }))}${hint(host.t("pet_room_hint"), "nf-wide")}</div>`
@@ -0,0 +1,51 @@
import { html, nothing } from "lit";
import { repeat } from "lit/directives/repeat.js";
import { uid, type Furniture } from "../../../model.ts";
import { hasPump, hasValve, hydronicConfig, newCircuit, type HydronicConfig, type HydronicControl, type HydronicCircuit } from "../../../hydronic-model.ts";
import { entityOptions } from "../entities.ts";
import { checkField, entityField, hint, numberField, pinShiftField, selectField, textField } from "../fields.ts";
import { renderDeviceValues } from "../device-values.ts";
import type { EditorHost } from "../host.ts";
export function renderHydronicForm(host: EditorHost, item: Furniture, update: (patch: Partial<Furniture>) => void) {
const h = hydronicConfig(item), options = entityOptions(host.hass, () => true);
const set = (patch: Partial<HydronicConfig>) => update({ hydronic: { ...h, ...patch } });
const ref = (label: string, value: string | null | undefined, types: number[], save: (id: string | null) => void) => entityField(host, label, value ?? null, undefined, options, (v) => save(v === "none" ? null : v), { types });
const numeric = (label: string, value: string | null | undefined, save: (id: string | null) => void) => ref(label, value, [1, 2], save);
const control = (label: string, value: HydronicControl | undefined, save: (c: HydronicControl) => void, valve = false) => html`<details class="nf-wide nf-hydronic-control"><summary>${label}</summary><div class="nf-form">
${ref("Rückmeldung / Istwert", value?.feedback, [0, 1, 2], (feedback) => save({ ...value, feedback }))}
${ref("Befehl / Sollwert (optional)", value?.command, [0, 1, 2], (command) => save({ ...value, command }))}
${valve ? checkField(host, "Ventil nur in 3D umkehren", !!value?.inverted, (inverted) => save({ ...value, inverted })) : nothing}
${hint("Eine zugewiesene Rückmeldung bestimmt die 3D-Anzeige, auch wenn sie gerade nicht verfügbar ist. Ohne Rückmeldung wird der verknüpfte Sollwert verwendet. Befehle werden über die Symcon-Schaltaktion in ihrem nativen Wertebereich gesendet. Die 3D-Umkehrung verändert weder Anzeige- noch Schreibwerte.", "nf-wide")}
</div></details>`;
const temperatures = html`${numeric("Vorlauf", h.flow, (flow) => set({ flow }))}${numeric("Rücklauf", h.return, (back) => set({ return: back }))}`;
const circuit = (c: HydronicCircuit, i: number) => {
const patch = (p: Partial<HydronicCircuit>) => set({ circuits: (h.circuits ?? []).map((old) => old.id === c.id ? { ...old, ...p } : old) });
return html`<details class="nf-hydronic-circuit" data-circuit=${c.id} ?open=${i === 0}><summary>${c.name || `Kreis ${i + 1}`}</summary><div class="nf-form">
${textField(host, "Name", c.name, (name) => patch({ name }), { wide: true, maxlength: 100 })}
${selectField(host, "Kreisart", c.kind, [["heating", "Heizkreis"], ["cooling", "Kühlkreis"], ["changeover", "Heizen / Kühlen"], ["pump", "Einspeise- / Vorschubpumpe (ohne Ventil)"]], (kind) => patch({ kind, ...(kind === "pump" ? { has_pump: true, has_valve: false } : {}) }), { wide: true })}
${c.kind !== "pump" ? html`${checkField(host, "Pumpe vorhanden", hasPump(c), (has_pump) => patch({ has_pump }))}${checkField(host, "Ventil vorhanden", hasValve(c), (has_valve) => patch({ has_valve }))}` : nothing}
${hasPump(c) ? control("Pumpe", c.pump, (pump) => patch({ pump })) : nothing}
${hasValve(c) ? control("Ventil", c.valve, (valve) => patch({ valve }), true) : nothing}
${numeric("Vorlauf", c.flow, (flow) => patch({ flow }))}${numeric("Rücklauf", c.return, (back) => patch({ return: back }))}
${hasPump(c) ? numeric("Pumpenleistung (optional)", c.power, (power) => patch({ power })) : nothing}
${c.kind === "changeover" ? html`${ref("Umschaltung Heizen / Kühlen", c.mode_entity, [0, 1], (mode_entity) => patch({ mode_entity }))}${numberField(host, "Kühlbetrieb bei Wert", c.cooling_value ?? 1, (cooling_value) => patch({ cooling_value: Math.round(cooling_value) }), 1)}` : nothing}
<button class="nf-link nf-wide nf-hydronic-remove" ?disabled=${!host.admin} @click=${() => set({ circuits: (h.circuits ?? []).filter((old) => old.id !== c.id) })}>× Kreis entfernen</button>
</div></details>`;
};
return html`<section class="nf-hydronic-form">
<div class="nf-form">${checkField(host, "Schwebende 3D-Kachel", h.card !== false, (card) => set({ card }))}${pinShiftField(host, item.pin_offset, (pin_offset) => update({ pin_offset }))}${hint("Verknüpfe jeden Datenpunkt über den Objektbaum. Namen und Pfade schränken die Auswahl nicht ein. Nicht verknüpfte Werte bleiben in der 3D-Kachel ausgeblendet. Das Bauteil öffnet beim Antippen seine Werte und Bedienung.", "nf-wide")}</div>
${item.type === "heating_manifold" ? html`${repeat(h.circuits ?? [], (c) => c.id, circuit)}<button class="nf-btn nf-hydronic-add" title="Bis zu 32 Kreise" ?disabled=${!host.admin || (h.circuits?.length ?? 0) >= 32} @click=${() => set({ circuits: [...(h.circuits ?? []), newCircuit(uid("circuit"), `Kreis ${(h.circuits?.length ?? 0) + 1}`)] })}>+ Kreis hinzufügen</button>` : nothing}
${item.type === "buffer_tank" ? html`<div class="nf-form">${temperatures}${hint("Die sieben Startplätze liegen von oben nach unten. Höhe 100 % liegt oben, 0 % unten. Fühlerplätze können ergänzt, entfernt und frei in der Höhe positioniert werden; die Anzeige sortiert sie von oben nach unten.", "nf-wide")}</div>
${repeat([...(h.sensors ?? [])].sort((a, b) => b.level - a.level), (probe) => probe.id, (probe) => {
const patch = (change: Partial<typeof probe>) => set({ sensors: (h.sensors ?? []).map((s) => s.id === probe.id ? { ...s, ...change } : s) });
return html`<details class="nf-hydronic-probe" data-probe=${probe.id}><summary>${probe.name || "Fühler"} · ${Math.round(probe.level * 100)} %</summary><div class="nf-form">
${textField(host, "Bezeichnung", probe.name, (name) => patch({ name }), { wide: true, maxlength: 100 })}${numeric("Temperatur", probe.entity, (entity) => patch({ entity }))}
${numberField(host, "Höhe (%) · 100 = oben", Math.round(probe.level * 1000) / 10, (v) => patch({ level: Math.max(0, Math.min(1, v / 100)) }), .1, 0)}
<button class="nf-link nf-wide" ?disabled=${!host.admin} @click=${() => set({ sensors: (h.sensors ?? []).filter((s) => s.id !== probe.id) })}>× Fühlerplatz entfernen</button>
</div></details>`;
})}<button class="nf-btn nf-hydronic-add-probe" title="Bis zu 64 Fühlerplätze" ?disabled=${!host.admin || (h.sensors?.length ?? 0) >= 64} @click=${() => set({ sensors: [...(h.sensors ?? []), { id: uid("probe"), name: `Fühler ${(h.sensors?.length ?? 0) + 1}`, entity: null, level: .5 }] })}>+ Fühlerplatz hinzufügen</button>` : nothing}
${item.type === "freshwater_station" ? html`<div class="nf-form">${temperatures}${numeric("Zirkulationstemperatur", h.circulation_temperature, (circulation_temperature) => set({ circulation_temperature }))}${numeric("Trinkwarmwasser", h.hot_water, (hot_water) => set({ hot_water }))}${control("Ladepumpe", h.pump, (pump) => set({ pump }))}${control("Zirkulationspumpe", h.circulation, (circulation) => set({ circulation }))}</div>` : nothing}
${renderDeviceValues(host, item.values, (values) => update({ values }))}
</section>`;
}
@@ -25,6 +25,7 @@ import {
type Vec2,
} from "../../../model.ts";
import { furnitureSize } from "../../../packs.ts";
import { defaultHydronic, isHydronic } from "../../../hydronic-model.ts";
const thousandths = (v: number) => Math.round(v * 1000) / 1000;
const quarterTurns = (degrees: number, by: number) => (((degrees + by) % 360) + 360) % 360;
@@ -74,6 +75,7 @@ export function newFurniture(type: string, doc: Building, floor: Floor, at: Vec2
const above = doc.floors.filter((f) => f.elevation > floor.elevation).sort((p, q) => p.elevation - q.elevation)[0];
const h = type === "stairs" ? thousandths(above ? above.elevation - floor.elevation : floor.height + 0.25) : height;
const item: Furniture = { id: uid("furniture"), type, x: thousandths(at[0]), z: thousandths(at[1]), rotation: 0, w, d, h, variant: null };
if (isHydronic(type)) item.hydronic = defaultHydronic(type);
// new stairs are shaped stairs: shape, turn and steps are set in the form, and they open only the floor they need
if (type === "stairs") item.stair = { ...DEFAULT_STAIR };
return item;
+4
View File
@@ -2003,4 +2003,8 @@ export const editorStyles = css`
font-size: 12.5px;
color: var(--nf-warm);
}
.nf-hydronic-form>details { border:1px solid var(--nf-line); border-radius:10px; padding:10px; margin:8px 0; }
.nf-hydronic-form summary { cursor:pointer; font-weight:500; }
.nf-hydronic-form details[open]>.nf-form { margin-top:9px; }
.nf-hydronic-control { border-top:1px solid var(--nf-line); padding-top:7px; }
`;
+113
View File
@@ -0,0 +1,113 @@
import { css, html, LitElement, nothing } from "lit";
import type { Building, Furniture } from "../model.ts";
import type { HomeAssistant } from "../types.ts";
import { hasPump, hasValve, hydronicConfig, isHydronic, realRef, type HydronicCircuit, type HydronicControl } from "../hydronic-model.ts";
import { hydronicReading, readControl, temperatureC, type HydronicReading } from "../hydronic-values.ts";
import { nativeBool, nativeNumber, nativeText, nativeValue } from "../entities/symcon-values.ts";
import { tokens } from "../styles.ts";
import { trendButton } from "./trend-button.ts";
export { hydronicVisual } from "../hydronic-values.ts";
const names: Record<string, string> = { heating_manifold: "Heiz-/Kühlkreisverteiler", buffer_tank: "Pufferspeicher", freshwater_station: "Frischwasserstation" };
const nameOf = (item: Furniture) => item.name || names[item.type];
const titleOf = (c: HydronicCircuit) => c.name || ({ heating: "Heizkreis", cooling: "Kühlkreis", changeover: "Heizen / Kühlen", pump: "Vorschubpumpe" })[c.kind];
const modeOf = (hass: HomeAssistant, c: HydronicCircuit) => c.kind === "pump" ? "Pumpenkreis" : c.kind === "cooling" ? "Kühlen" : c.kind === "heating" ? "Heizen"
: realRef(c.mode_entity) && nativeValue(hass.states[c.mode_entity]) === null ? "Betriebsart –" : Number(realRef(c.mode_entity) ? nativeValue(hass.states[c.mode_entity]) : 0) === (c.cooling_value ?? 1) ? "Kühlen" : "Heizen";
const parts = (hass: HomeAssistant, flow?: string | null, back?: string | null): HydronicReading[] => [hydronicReading(hass, "Vorlauf", flow), hydronicReading(hass, "Rücklauf", back)].filter((r): r is HydronicReading => r !== null);
const delta = (hass: HomeAssistant, flow?: string | null, back?: string | null) => {
const a = temperatureC(hass, flow), b = temperatureC(hass, back);
return a === null || b === null ? nothing : html`<div class="reading delta"><span>ΔT · VL − RL</span><b>${(a - b).toLocaleString(hass.language, { maximumFractionDigits: 1 })} K</b></div>`;
};
function rootRows(hass: HomeAssistant, item: Furniture): HydronicReading[] {
const h = hydronicConfig(item), rows = parts(hass, h.flow, h.return);
if (item.type === "buffer_tank") rows.unshift(...[...(h.sensors ?? [])].sort((a, b) => b.level - a.level).flatMap((s) => { const row = hydronicReading(hass, s.name || "Fühler", s.entity); return row ? [row] : []; }));
if (item.type === "freshwater_station") for (const [label, id] of [["Zirkulation", h.circulation_temperature], ["Trinkwarmwasser", h.hot_water]] as const) { const row = hydronicReading(hass, label, id); if (row) rows.push(row); }
for (const v of item.values ?? []) { const row = hydronicReading(hass, v.label || String(v.entity && hass.states[v.entity]?.attributes.friendly_name || "Wert"), v.entity); if (row) rows.push({ ...row, icon: v.icon }); }
return rows;
}
const rowTemplate = (hass: HomeAssistant, row: HydronicReading) => html`<div class="reading" data-source=${row.id}><span>${row.icon?.startsWith("mdi:") ? html`<ha-icon icon=${row.icon}></ha-icon>` : row.icon || nothing} ${row.label}</span><b>${row.text}${trendButton(hass, [row.id], row.label)}</b></div>`;
function controlRow(hass: HomeAssistant, label: string, binding?: HydronicControl) {
const state = readControl(hass, binding);
return state.id ? html`<div class="reading" data-source=${state.id}><span>${label}<small>${state.feedback ? "Ist" : "Soll"}</small></span><b><i class="lamp" style=${`background:${state.running === null ? "#888" : state.running ? "#6fe1a2" : "#465361"}`}></i>${nativeText(hass.states[state.id])}${trendButton(hass, [state.id], label)}</b></div>` : nothing;
}
const styles = css`
:host{display:block;color:var(--nf-text);font:12px/1.4 system-ui,sans-serif;min-width:170px;max-width:300px}
button{font:inherit;color:inherit;background:var(--nf-fill,#ffffff10);border:1px solid var(--nf-line);border-radius:7px;padding:5px 8px;cursor:pointer}button:disabled,input:disabled{opacity:.45;cursor:default}button:focus-visible,input:focus-visible{outline:2px solid var(--nf-accent);outline-offset:2px}
.title{display:block;width:100%;padding:0 0 5px;border:0;background:none;font-weight:600;text-align:left;white-space:normal}.content{max-height:250px;overflow:auto;overscroll-behavior:contain}.circuit{border-top:1px solid var(--nf-line);padding:5px 0}.circuit-name{font-size:11px;font-weight:600;margin-bottom:3px}.reading{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px;align-items:center;min-height:22px}.reading>span{color:var(--nf-muted);white-space:normal}.reading b{display:flex;align-items:center;justify-content:flex-end;white-space:nowrap;font-variant-numeric:tabular-nums;font-weight:500}.reading small{font-size:9px;margin-left:5px;opacity:.75}.delta{font-size:10px}.lamp{display:inline-block;flex:none;width:6px;height:6px;border-radius:50%;margin-right:5px}.empty{color:var(--nf-muted);font-size:11px;white-space:normal;margin:5px 0}nf-trend-button{margin-left:3px}
.circuit-name small,h3 small{font-size:10px;color:var(--nf-muted);font-weight:normal;margin-left:5px}
ha-icon{--mdc-icon-size:13px;width:13px;height:13px;vertical-align:middle}
dialog{box-sizing:border-box;width:min(620px,calc(100vw - 24px));max-width:none;max-height:calc(100dvh - 24px);padding:0;color:var(--nf-text);background:var(--nf-chrome-solid,#1c1c1c);border:1px solid var(--nf-line);border-radius:14px;box-shadow:0 20px 70px #0008;font:13px/1.4 system-ui,sans-serif}dialog::backdrop{background:#050b16a6;backdrop-filter:blur(3px)}header{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:14px 18px;border-bottom:1px solid var(--nf-line)}h2{font-size:17px;margin:0}.body{padding:12px 18px;max-height:calc(100dvh - 120px);overflow:auto;overscroll-behavior:contain}h3{font-size:13px;margin:12px 0 7px}fieldset{min-width:0;margin:8px 0;padding:10px;border:1px solid var(--nf-line);border-radius:9px}legend{font-size:12px;color:var(--nf-muted)}.command{display:flex;align-items:center;gap:12px;margin-top:8px}.command input[type=range]{flex:1;min-width:0;accent-color:var(--nf-accent)}.command input[type=number]{width:90px;box-sizing:border-box;background:var(--nf-fill,#ffffff10);border:1px solid var(--nf-line);border-radius:6px;color:inherit;padding:5px}.command output{font-variant-numeric:tabular-nums;min-width:45px;text-align:right}.error{color:#ff9b9b}.readonly{color:var(--nf-muted);font-size:11px;margin:4px 0}.body .reading{padding:4px 0}.body .circuit{padding-bottom:12px}
`;
class HydronicCard extends LitElement {
static properties = { hass: { attribute: false }, item: { attribute: false }, readOnly: { type: Boolean } };
declare hass: HomeAssistant; declare item: Furniture; declare readOnly: boolean;
render() {
if (!this.hass || !this.item) return nothing;
const h = hydronicConfig(this.item), rows = rootRows(this.hass, this.item);
return html`<button class="title" @click=${() => openHydronic(this.hass, this.item, this.readOnly)} aria-haspopup="dialog">${nameOf(this.item)} ⚙</button><div class="content">
${this.item.type === "heating_manifold" ? (h.circuits ?? []).map((c) => html`<section class="circuit"><div class="circuit-name">${titleOf(c)} <small>${modeOf(this.hass, c)}</small></div>${hasPump(c) ? controlRow(this.hass, "Pumpe", c.pump) : nothing}${hasValve(c) ? controlRow(this.hass, "Ventil", c.valve) : nothing}${parts(this.hass, c.flow, c.return).map((r) => rowTemplate(this.hass, r))}${hydronicReading(this.hass, "Leistung", c.power) ? rowTemplate(this.hass, hydronicReading(this.hass, "Leistung", c.power)!) : nothing}</section>`) : nothing}
${rows.map((r) => rowTemplate(this.hass, r))}${this.item.type === "freshwater_station" ? html`${controlRow(this.hass, "Ladepumpe", h.pump)}${controlRow(this.hass, "Zirkulationspumpe", h.circulation)}` : nothing}
${this.item.type !== "heating_manifold" && !rows.length ? html`<p class="empty">Noch keine Fühler verknüpft</p>` : nothing}
</div>`;
}
static styles = [tokens, styles];
}
class HydronicDialog extends LitElement {
static properties = { hass: { attribute: false }, item: { attribute: false }, readOnly: { type: Boolean }, pending: { state: true }, error: { state: true } };
declare hass: HomeAssistant; declare item: Furniture; declare readOnly: boolean;
private declare pending: Set<string>; private declare error: string;
constructor() { super(); this.pending = new Set(); this.error = ""; this.readOnly = false; }
async show() { await this.updateComplete; this.shadowRoot!.querySelector("dialog")!.showModal(); }
private async send(id: string, value: number | boolean) {
const st = this.hass.states[id];
if (this.readOnly || !st?.attributes.symcon_has_action || nativeValue(st) === null || this.pending.has(id)) return;
this.pending = new Set([...this.pending, id]); this.error = "";
try { await this.hass.callService("symcon", "set_value", { entity_id: id, value }); }
catch (error) { this.error = error instanceof Error ? error.message : String(error); }
finally { this.pending = new Set([...this.pending].filter((v) => v !== id)); }
}
private control(label: string, binding?: HydronicControl) {
if (!realRef(binding?.command) && !realRef(binding?.feedback)) return nothing;
const id = realRef(binding?.command) ? binding.command : null, st = id ? this.hass.states[id] : undefined;
const a = st?.attributes, value = nativeValue(st), writable = !!id && !!a?.symcon_has_action && value !== null && !this.readOnly && !this.pending.has(id);
const min = Number(a?.symcon_min ?? 0), max = Number(a?.symcon_max ?? 100), step = Number(a?.symcon_step || (a?.symcon_variable_type === 1 ? 1 : .1));
const number = nativeNumber(st);
const writeNumber = (event: Event) => { const input = event.target as HTMLInputElement; if (id && input.value.trim() && input.checkValidity() && Number.isFinite(input.valueAsNumber)) void this.send(id, input.valueAsNumber); };
return html`<fieldset data-control=${label}><legend>${label}</legend>${controlRow(this.hass, label, binding)}
${id ? html`<div class="reading"><span>Befehl / Sollwert</span><b>${nativeText(st)}${trendButton(this.hass, [id], `${label} · Sollwert`)}</b></div>
${a?.symcon_variable_type === 0 ? html`<div class="command"><button data-command=${id} ?disabled=${!writable} @click=${() => void this.send(id, !nativeBool(st))}>${nativeBool(st) ? "Ausschalten / Schließen" : "Einschalten / Öffnen"}</button></div>`
: [1, 2].includes(Number(a?.symcon_variable_type)) ? html`<div class="command"><input type="range" aria-label=${`${label} Sollwert`} data-command=${id} min=${min} max=${max} step=${step} .value=${String(number ?? min)} ?disabled=${!writable} @change=${writeNumber}/><input type="number" aria-label=${`${label} nativer Sollwert`} min=${min} max=${max} step=${step} .value=${number === null ? "" : String(number)} ?disabled=${!writable} @change=${writeNumber}/></div>` : nothing}
${this.readOnly ? html`<p class="readonly">Historische Ansicht · nur Anzeige</p>` : !a?.symcon_has_action ? html`<p class="readonly">Nur Anzeige · keine Symcon-Schaltaktion hinterlegt</p>` : nothing}` : nothing}
</fieldset>`;
}
render() {
if (!this.hass || !this.item) return nothing;
const h = hydronicConfig(this.item), rows = rootRows(this.hass, this.item);
return html`<dialog @close=${() => { this.remove(); if (activeDialog === this) activeDialog = null; }} @keydown=${(e: Event) => e.stopPropagation()}><header><h2>${nameOf(this.item)}</h2><button aria-label="Schließen" @click=${() => this.shadowRoot!.querySelector("dialog")!.close()}>×</button></header><div class="body">
${this.item.type === "heating_manifold" ? (h.circuits ?? []).map((c) => html`<section class="circuit" data-circuit=${c.id}><h3>${titleOf(c)} <small>${modeOf(this.hass, c)}</small></h3>${hasPump(c) ? this.control("Pumpe", c.pump) : nothing}${hasValve(c) ? this.control("Ventil", c.valve) : nothing}${parts(this.hass, c.flow, c.return).map((r) => rowTemplate(this.hass, r))}${delta(this.hass, c.flow, c.return)}${hydronicReading(this.hass, "Pumpenleistung", c.power) ? rowTemplate(this.hass, hydronicReading(this.hass, "Pumpenleistung", c.power)!) : nothing}</section>`) : nothing}
${rows.map((r) => rowTemplate(this.hass, r))}${this.item.type !== "heating_manifold" ? delta(this.hass, h.flow, h.return) : nothing}
${this.item.type === "freshwater_station" ? html`${this.control("Ladepumpe", h.pump)}${this.control("Zirkulationspumpe", h.circulation)}` : nothing}
${!rows.length && this.item.type !== "heating_manifold" ? html`<p class="empty">Die Fühler lassen sich im Editor über den Objektbaum zuweisen.</p>` : nothing}
${this.error ? html`<p class="error" role="alert">${this.error}</p>` : nothing}
</div></dialog>`;
}
static styles = [tokens, styles, css`:host{max-width:none;min-width:0}`];
}
let activeDialog: HydronicDialog | null = null;
export function closeHydronic() { activeDialog?.remove(); activeDialog = null; }
export async function openHydronic(hass: HomeAssistant, item: Furniture, readOnly = false): Promise<void> {
activeDialog?.remove();
const dialog = document.createElement("nf-hydronic-dialog") as HydronicDialog;
activeDialog = dialog; Object.assign(dialog, { hass, item, readOnly }); document.body.append(dialog); await dialog.show();
}
export function refreshHydronic(hass: HomeAssistant, building: Building, readOnly = false): void {
if (!activeDialog) return;
const item = building.floors.flatMap((f) => f.furniture).find((f) => f.id === activeDialog!.item.id);
if (!item || !isHydronic(item.type)) { activeDialog.remove(); activeDialog = null; return; }
Object.assign(activeDialog, { hass, item, readOnly });
}
if (!customElements.get("nf-hydronic-card")) customElements.define("nf-hydronic-card", HydronicCard);
if (!customElements.get("nf-hydronic-dialog")) customElements.define("nf-hydronic-dialog", HydronicDialog);
+31 -1
View File
@@ -32,6 +32,8 @@ import { chosenEffects, readSkyWeather, withDensity } from "../live/sky-weather.
import { energyPicture, houseHub, type EnergyPicture } from "../live/energy-flow.ts";
import { roomClimateCards } from "../live/room-climate-card.ts";
import { furniturePowerCards } from "../live/furniture-power-card.ts";
import { isHydronic } from "../hydronic-model.ts";
import { loadHydronics } from "../load-hydronics.ts";
import { loadWeek, type WeekBars } from "../live/week-bars.ts";
import { binsDue, loadToday, sortDay, type TodayItem } from "../live/today.ts";
import { forecastDays, loadForecast } from "../live/forecast.ts";
@@ -413,6 +415,8 @@ export class NfView3d extends LitElement {
private declare _utilityOverviewVisible: boolean;
private viewer: NextFloorViewer | null = null;
private hydronicModule: Awaited<ReturnType<typeof loadHydronics>> | null = null;
private hydronicGeneration = 0;
private starting = false;
/** States of the placed entities as last sent to the viewer. */
private shownStates = new Map<string, HassEntity | undefined>();
@@ -549,6 +553,7 @@ export class NfView3d extends LitElement {
disconnectedCallback(): void {
super.disconnectedCallback();
this.hydronicGeneration++; this.hydronicModule?.closeHydronic();
this.stopPlugins?.();
this.stopPlugins = null;
this.listenToAnnouncements(false);
@@ -859,6 +864,7 @@ export class NfView3d extends LitElement {
// a piece shown only while a helper is on (seasonal decoration) comes and goes with it
if (hiddenFurniture(hass, b).join(",") !== this.shownFor?.key) v.setBuilding(this.shownBuilding(hass));
this.shownStates = new Map(this.watched.map((id) => [id, hass.states[id]]));
this.syncHydronics(v, b, hass);
this.refreshToday(b);
this.refreshForecast(b);
@@ -1380,6 +1386,7 @@ export class NfView3d extends LitElement {
}
// an item with its own tap action shows what it shows as usual; a tap on it or on its pin runs the action
const own = ownTaps(b, markers);
for (const f of b.floors.flatMap((fl) => fl.furniture)) if (isHydronic(f.type)) targets.set(f.id, `hydronic:${f.id}`);
this.tapPins = own.pins;
for (const f of b.floors.flatMap((fl) => fl.furniture)) if (f.tap?.action) targets.set(f.id, `tap:${f.id}`);
// one without a pin of its own gets one above it, like a device's, that does the same
@@ -2323,6 +2330,11 @@ export class NfView3d extends LitElement {
if (entityId.startsWith("lamp:")) return;
// in the past nothing is switched
if (this._travel) return;
if (entityId.startsWith("hydronic:")) {
const item = this.building?.floors.flatMap((f) => f.furniture).find((f) => f.id === entityId.slice(9));
if (item && this.hass) void loadHydronics().then((mod) => { if (this.isConnected && this.hass) { this.hydronicModule = mod; return mod.openHydronic(this.hass, item); } }).catch((err) => { this._error = String(err); });
return;
}
const ownTap = entityId.startsWith("tap:") ? entityId.slice(4) : this.tapPins.get(entityId);
if (ownTap) {
const f = this.building?.floors.flatMap((fl) => fl.furniture).find((it) => it.id === ownTap);
@@ -2639,6 +2651,18 @@ export class NfView3d extends LitElement {
.catch(() => (this.dayCurves = null));
}
private syncHydronics(v: NextFloorViewer, b: Building, hass: HomeAssistant): void {
const generation = ++this.hydronicGeneration;
const items = this.shownBuilding(hass).floors.filter((floor) => !this.floorId || floor.id === this.floorId).flatMap((floor) => floor.furniture.filter((item) => isHydronic(item.type)).map((item) => ({ floor, item })));
if (!items.length) { v.setHydronics([]); this.hydronicModule?.refreshHydronic(hass, b, !!this._travel); return; }
void loadHydronics().then((mod) => {
if (generation !== this.hydronicGeneration || this.viewer !== v || !this.isConnected) return;
this.hydronicModule = mod;
v.setHydronics(items.map(({ floor, item }) => ({ ...mod.hydronicVisual(hass, item, floor.id, mountBase(floor, item)), animate: !this.dimmed && !this._travel })));
mod.refreshHydronic(hass, b, !!this._travel);
}).catch((err) => { this._error = String(err); });
}
private syncLhCards(v: NextFloorViewer, b: Building, pic: EnergyPicture, cars: ReturnType<NfView3d["liveCars"]>, media: MediaNow[], hass: HomeAssistant): void {
const cards: LiveCard[] = [];
const s = pic.summary;
@@ -2663,6 +2687,12 @@ export class NfView3d extends LitElement {
if (this.liveCardsOn && !this.dimmed) {
cards.push(...roomClimateCards(hass, b, this.floorId, this.roomId));
cards.push(...furniturePowerCards(hass, b, this.furnitureLinks ?? new Map(), this.floorId, this.roomId));
for (const floor of b.floors) for (const item of floor.furniture) {
if (!isHydronic(item.type) || item.hydronic?.card === false || (this.floorId && floor.id !== this.floorId) || !furnitureShown(hass, item)) continue;
const room = this.roomId ? floor.rooms.find((r) => r.id === this.roomId) : null;
if (this.roomId && (!room || !pointInPolygon([item.x, item.z], room.points))) continue;
cards.push({ kind: "hydronic", item, readOnly: !!this._travel, at: { floorId: floor.id, x: item.x + (item.pin_offset?.x ?? 0), z: item.z + (item.pin_offset?.z ?? 0), y: mountBase(floor, item) + item.h + .3 + (item.pin_offset?.y ?? 0) } });
}
}
if (JSON.stringify(cards) !== JSON.stringify(this._liveCards)) this._liveCards = cards;
v.setLiveAnchors(
@@ -2714,7 +2744,7 @@ export class NfView3d extends LitElement {
const own = this.ownSensors();
const e = this._liveEnergy?.summary;
const energy = !!e && !this.roomId && this.showEnergy && !!this.hass && !(e.consumption === null && e.grid === null && e.solar === null && e.battery === null);
const climate = this.building?.floors.some((f) => f.rooms.some((r) => r.climate_card) || f.furniture.some((m) => m.power_card));
const climate = this.building?.floors.some((f) => f.rooms.some((r) => r.climate_card) || f.furniture.some((m) => m.power_card || (isHydronic(m.type) && m.hydronic?.card !== false)));
const climateToggle = climate ? this.renderCardToggle() : nothing;
const roomNames = this.roomNamesButton ? html`<button class="nf-energy-item nf-flow-toggle nf-room-names-toggle" aria-pressed=${this.roomLabels} title=${translate(this.hass, "room_names_toggle_hint")} @click=${() => {
this.roomLabels = !this.roomLabels;
@@ -11,6 +11,7 @@ import { pluginWatched } from "../../plugins/registry.ts";
import type { HomeAssistant } from "../../types.ts";
import { weatherEntity } from "../../weather.ts";
import { utilityWatched } from "../../utilities.ts";
import { hydronicRefs } from "../../hydronic-model.ts";
export interface WatchInputs {
hass: HomeAssistant;
@@ -44,6 +45,7 @@ function furnitureIds(inputs: WatchInputs): MaybeId[] {
// a washer's, dryer's or dishwasher's time left comes from a sensor next to its switch
...pieces.filter((m) => m.type === "washer" || m.type === "dryer" || m.type === "dishwasher").flatMap((m) => deviceSiblings(hass, furnitureLinks.get(m.id)?.entity ?? furnitureLinks.get(m.id)?.power).filter((id) => id.startsWith("sensor."))),
...pieces.flatMap((m) => [m.door_left, m.door_right, m.soc, m.status, m.charge, m.export, m.temp_entity, m.temp_entity2, ...(m.values ?? []).map((v) => v.entity)]),
...pieces.flatMap(hydronicRefs),
...pieces.filter((m) => m.type === "robot_vacuum").map((m) => robotRoomSensor(hass, furnitureLinks.get(m.id)?.entity ?? null, m.room_sensor)),
...pieces.flatMap((m) => (m.pictures ?? []).flatMap((rule) => [rule.entity, ...(rule.image.startsWith("camera:") ? [rule.image.slice("camera:".length)] : [])])),
];