Files
NextFloor/frontend/src/components/editor/forms/hydronic.ts
T

54 lines
7.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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";
import { renderFreshwaterForm } from "./freshwater.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) ? selectField(host, "Ventilbauart", c.valve_type ?? "mixing", [["mixing", "Mischer (Dreiwegeventil)"], ["two_way", "Durchgangsventil (Zweiwege)" ]], (valve_type) => patch({ valve_type }), { wide: true }) : 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" ? renderFreshwaterForm(host,item,update) : nothing}
${renderDeviceValues(host, item.values, (values) => update({ values }))}
</section>`;
}