feat: add fresh-water cascades with independent stations and buffer links

This commit is contained in:
jhartworks committed 2026-11-12 16:16:01 +01:00
1 parent a2a119d3ee
commit 992c3e18f2
30 files changed
+2199 -1578

No files matched your search

@@ -0,0 +1,46 @@
import { html, nothing } from "lit";
import { repeat } from "lit/directives/repeat.js";
import { uid, type Furniture } from "../../../model.ts";
import { hydronicConfig, type HydronicControl } from "../../../hydronic-model.ts";
import { freshwaterStations, MAX_FRESHWATER_STATIONS, newFreshwaterStation, stationHasValve, withFreshwaterStations, type FreshwaterStation } from "../../../freshwater-model.ts";
import { entityOptions } from "../entities.ts";
import { checkField, entityField, hint, selectField, textField } from "../fields.ts";
import type { EditorHost } from "../host.ts";
export function renderFreshwaterForm(host: EditorHost, item: Furniture, update: (patch: Partial<Furniture>) => void) {
const h=hydronicConfig(item),stations=freshwaterStations(item),options=entityOptions(host.hass,()=>true);
const save=(next:FreshwaterStation[],resize=false)=>update({hydronic:withFreshwaterStations(h,next),...(resize?{w:Math.round(item.w/stations.length*next.length*1000)/1000}:{})});
const ref=(label:string,value:string|null|undefined,types:number[],set:(id:string|null)=>void)=>entityField(host,label,value??null,undefined,options,(v)=>set(v==="none"?null:v),{types});
const numeric=(label:string,value:string|null|undefined,set:(id:string|null)=>void)=>ref(label,value,[1,2],set);
const control=(label:string,value:HydronicControl|undefined,set:(c:HydronicControl)=>void)=>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)=>set({...value,feedback}))}
${ref("Befehl / Sollwert (optional)",value?.command,[0,1,2],(command)=>set({...value,command}))}
${hint("Eine zugewiesene Rückmeldung bestimmt die Anzeige auch bei Ausfall. Nur ohne Rückmeldung wird der Sollwert verwendet. Bedienbare Variablen verwenden ihre native Symcon-Schaltaktion und ihren unveränderten Wertebereich.","nf-wide")}
</div></details>`;
const floor=host.doc.floors.find((f)=>f.furniture.some((m)=>m.id===item.id));
const buffers=(floor?.furniture??[]).filter((m)=>m.type==="buffer_tank");
const choices:[string,string][]=[["","Keiner"],...buffers.map((m,i):[string,string]=>[m.id,m.name||`Pufferspeicher ${i+1}`])];
if(h.buffer_id&&!buffers.some((b)=>b.id===h.buffer_id))choices.push([h.buffer_id,"Verknüpfter Puffer nicht im Stockwerk vorhanden"]);
return html`<section class="nf-freshwater-form">
<div class="nf-form">${selectField(host,"Pufferspeicher im Plan",h.buffer_id??"",choices,(id)=>update({hydronic:{...h,buffer_id:id||null}}),{wide:true})}
${hint("Die Zuordnung zeichnet Vorlauf und Rücklauf zum platzierten Puffer im selben Stockwerk. Datenpunkte werden für jede Station separat aus dem Objektbaum gewählt. Eine Kaskade teilt sich die Sammelleitungen; die Zirkulationspumpe gehört zur gemeinsamen Leitung. Das Hinzufügen einer Station verbreitert das Bauteil, neue Stationen starten ohne Datenpunkt-Verknüpfungen.","nf-wide")}
</div>
${repeat(stations,(s)=>s.id,(s,i)=>{
const patch=(p:Partial<FreshwaterStation>)=>save(stations.map((old)=>old.id===s.id?{...old,...p}:old));
return html`<details class="nf-freshwater-station" data-station=${s.id} ?open=${i===0}><summary>K${i+1} · ${s.name||`Station ${i+1}`}</summary><div class="nf-form">
${textField(host,"Name",s.name,(name)=>patch({name}),{wide:true,maxlength:100})}
${numeric("Vorlauf",s.flow,(flow)=>patch({flow}))}${numeric("Rücklauf",s.return,(back)=>patch({return:back}))}
${numeric("Trinkwarmwasser",s.hot_water,(hot_water)=>patch({hot_water}))}${numeric("Kaltwasser",s.cold_water,(cold_water)=>patch({cold_water}))}
${control("Ladepumpe",s.pump,(pump)=>patch({pump}))}
${numeric("Pumpenleistung (optional)",s.power,(power)=>patch({power}))}
${checkField(host,"Kaskadenventil vorhanden",stationHasValve(s),(has_valve)=>patch({has_valve}))}
${stationHasValve(s)?control("Kaskadenventil (Kaltwasser)",s.valve,(valve)=>patch({valve})):nothing}
${stations.length>1?html`<button class="nf-link nf-wide nf-freshwater-remove" ?disabled=${!host.admin} @click=${()=>save(stations.filter((old)=>old.id!==s.id),true)}>× Station entfernen</button>`:nothing}
</div></details>`;
})}
<button class="nf-btn nf-freshwater-add" ?disabled=${!host.admin||stations.length>=MAX_FRESHWATER_STATIONS} @click=${()=>save([...stations,newFreshwaterStation(uid("station"),`Station ${stations.length+1}`)],true)}>+ Station hinzufügen</button>
<div class="nf-form">${numeric("Zirkulationstemperatur",h.circulation_temperature,(circulation_temperature)=>update({hydronic:{...h,circulation_temperature}}))}
${control("Zirkulationspumpe",h.circulation,(circulation)=>update({hydronic:{...h,circulation}}))}
</div>
</section>`;
}
@@ -6,6 +6,7 @@ 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);
@@ -46,7 +47,7 @@ export function renderHydronicForm(host: EditorHost, item: Furniture, update: (p
<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}
${item.type === "freshwater_station" ? renderFreshwaterForm(host,item,update) : nothing}
${renderDeviceValues(host, item.values, (values) => update({ values }))}
</section>`;
}
+23 -15
View File
@@ -6,6 +6,7 @@ import { hydronicReading, readControl, temperatureC, type HydronicReading } from
import { nativeBool, nativeNumber, nativeText, nativeValue } from "../entities/symcon-values.ts";
import { tokens } from "../styles.ts";
import { trendButton } from "./trend-button.ts";
import { freshwaterStations, stationHasValve, type FreshwaterStation } from "../freshwater-model.ts";
export { hydronicVisual } from "../hydronic-values.ts";
const names: Record<string, string> = { heating_manifold: "Heiz-/Kühlkreisverteiler", buffer_tank: "Pufferspeicher", freshwater_station: "Frischwasserstation" };
@@ -19,12 +20,16 @@ const delta = (hass: HomeAssistant, flow?: string | null, back?: string | null)
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);
const h = hydronicConfig(item), rows = item.type === "freshwater_station" ? [] : 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); }
if (item.type === "freshwater_station") { const row=hydronicReading(hass,"Zirkulation",h.circulation_temperature);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;
}
function stationRows(hass:HomeAssistant,station:FreshwaterStation):HydronicReading[] {
return [...parts(hass,station.flow,station.return),...[ ["Kaltwasser",station.cold_water],["Trinkwarmwasser",station.hot_water],["Pumpenleistung",station.power] ].flatMap(([label,id])=>{const row=hydronicReading(hass,label!,id);return row?[row]:[];})];
}
const stationName=(station:FreshwaterStation,i:number)=>`K${i+1} · ${station.name||`Station ${i+1}`}`;
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);
@@ -45,22 +50,24 @@ class HydronicCard extends LitElement {
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);
const h = hydronicConfig(this.item), rows = rootRows(this.hass, this.item),stations=this.item.type==="freshwater_station"?freshwaterStations(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}
${stations.length>1?html`<small class="cascade-count">Kaskade · ${stations.length} Stationen</small>${stations.map((s,i)=>{const pump=readControl(this.hass,s.pump),row=hydronicReading(this.hass,"Trinkwarmwasser",s.hot_water)||hydronicReading(this.hass,"Vorlauf",s.flow);return html`<div class="station-summary" data-station=${s.id}><button class="station-name" @click=${()=>openHydronic(this.hass,this.item,this.readOnly,s.id)}><i class="lamp" title=${`Pumpe: ${pump.id?nativeText(this.hass.states[pump.id]):"–"}`} style=${`background:${pump.running===null?"#888":pump.running?"#6fe1a2":"#a82638"}`}></i>${stationName(s,i)}</button><b>${row?.text||"–"}</b>${row?trendButton(this.hass,[row.id],`${stationName(s,i)} · ${row.label}`):nothing}</div>`;})}`:stations.map((s)=>html`<section class="circuit">${stationRows(this.hass,s).map((r)=>rowTemplate(this.hass,r))}${controlRow(this.hass,"Ladepumpe",s.pump)}${stationHasValve(s)?controlRow(this.hass,"Kaskadenventil",s.valve):nothing}</section>`)}
${rows.map((r) => rowTemplate(this.hass, r))}${this.item.type === "freshwater_station" ? controlRow(this.hass, "Zirkulationspumpe", h.circulation) : nothing}
${this.item.type !== "heating_manifold" && this.item.type!=="freshwater_station" && !rows.length ? html`<p class="empty">Noch keine Fühler verknüpft</p>` : nothing}
</div>`;
}
static styles = [tokens, styles];
static styles = [tokens, styles,css`.cascade-count{color:var(--nf-muted)}.station-summary{display:grid;grid-template-columns:minmax(0,1fr) auto 18px;align-items:center;gap:6px;width:100%;padding:5px 0;font-size:11px}.station-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding:0;background:none;border:0;text-align:left}.station-summary b{white-space:nowrap;font-variant-numeric:tabular-nums}`];
}
class HydronicDialog extends LitElement {
static properties = { hass: { attribute: false }, item: { attribute: false }, readOnly: { type: Boolean }, pending: { state: true }, error: { state: true } };
static properties = { hass: { attribute: false }, item: { attribute: false }, readOnly: { type: Boolean }, focusStation: { attribute:false }, pending: { state: true }, error: { state: true } };
declare hass: HomeAssistant; declare item: Furniture; declare readOnly: boolean;
declare focusStation: string | undefined;
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(); }
async show() { await this.updateComplete; this.shadowRoot!.querySelector("dialog")!.showModal();if(this.focusStation)this.shadowRoot!.querySelector(`[data-station="${CSS.escape(this.focusStation)}"]`)?.scrollIntoView({block:"start"}); }
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;
@@ -85,23 +92,24 @@ class HydronicDialog extends LitElement {
}
render() {
if (!this.hass || !this.item) return nothing;
const h = hydronicConfig(this.item), rows = rootRows(this.hass, this.item);
const h = hydronicConfig(this.item), rows = rootRows(this.hass, this.item),stations=this.item.type==="freshwater_station"?freshwaterStations(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}
${stations.map((s,i)=>html`<details class="freshwater-unit" data-station=${s.id} ?open=${i===0||this.focusStation===s.id}><summary>${stationName(s,i)}</summary>${stationRows(this.hass,s).map((r)=>rowTemplate(this.hass,r))}${delta(this.hass,s.flow,s.return)}${this.control("Ladepumpe",s.pump)}${stationHasValve(s)?this.control("Kaskadenventil",s.valve):nothing}</details>`)}
${rows.map((r) => rowTemplate(this.hass, r))}${this.item.type === "buffer_tank" ? delta(this.hass, h.flow, h.return) : nothing}
${this.item.type === "freshwater_station" ? this.control("Zirkulationspumpe", h.circulation) : nothing}
${!rows.length && this.item.type !== "heating_manifold" && this.item.type!=="freshwater_station" ? 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}`];
static styles = [tokens, styles, css`:host{max-width:none;min-width:0}.freshwater-unit{border-bottom:1px solid var(--nf-line);padding:8px 0}.freshwater-unit>summary{cursor:pointer;font-weight:600;padding:4px 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> {
export async function openHydronic(hass: HomeAssistant, item: Furniture, readOnly = false, focusStation?:string): 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();
activeDialog = dialog; Object.assign(dialog, { hass, item, readOnly,focusStation }); document.body.append(dialog); await dialog.show();
}
export function refreshHydronic(hass: HomeAssistant, building: Building, readOnly = false): void {
if (!activeDialog) return;