feat: add native status bindings for hydraulic circuits and freshwater stations

This commit is contained in:
jhartworks committed 2026-11-16 16:48:46 +01:00
1 parent 984d9af232
commit 2407e09456
21 files changed
+1073 -974

No files matched your search

@@ -29,6 +29,7 @@ export function renderFreshwaterForm(host: EditorHost, item: Furniture, update:
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})}
${ref("Status (optional)",s.status,[0,1,2,3],(status)=>patch({status}))}
${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}))}
@@ -25,6 +25,7 @@ export function renderHydronicForm(host: EditorHost, item: Furniture, update: (p
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 })}
${ref("Status (optional)", c.status, [0, 1, 2, 3], (status) => patch({ status }))}
${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}
@@ -36,6 +37,7 @@ export function renderHydronicForm(host: EditorHost, item: Furniture, update: (p
</div></details>`;
};
return html`<section class="nf-hydronic-form">
<div class="nf-form">${ref("Anlagenstatus (optional)", h.status, [0, 1, 2, 3], (status) => set({ status }))}</div>
<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>
+14 -9
View File
@@ -31,6 +31,10 @@ function stationRows(hass:HomeAssistant,station:FreshwaterStation):HydronicReadi
}
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>`;
const statusRow = (hass: HomeAssistant, id?: string | null, label = "Status") => {
const row = hydronicReading(hass, label, id);
return row ? html`<div class="reading status-reading" data-source=${row.id}><span>${label}</span><b><span class="status-text" title=${row.text}>${row.text}</span>${trendButton(hass, [row.id], label)}</b></div>` : nothing;
};
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;
@@ -40,6 +44,7 @@ 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}
.status-reading{grid-template-columns:auto minmax(0,1fr)}.status-reading b{min-width:0}.status-text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.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}
@@ -51,14 +56,14 @@ class HydronicCard extends LitElement {
render() {
if (!this.hass || !this.item) return nothing;
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}
${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>`)}
return html`<button class="title" @click=${() => openHydronic(this.hass, this.item, this.readOnly)} aria-haspopup="dialog">${nameOf(this.item)} ⚙</button><div class="content">${statusRow(this.hass,h.status,"Anlagenstatus")}
${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>${statusRow(this.hass,c.status)}${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}
${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}${statusRow(this.hass,s.status)}</div>`;})}`:stations.map((s)=>html`<section class="circuit">${statusRow(this.hass,s.status)}${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}
${this.item.type !== "heating_manifold" && this.item.type!=="freshwater_station" && !rows.length && !realRef(h.status) ? html`<p class="empty">Noch keine Fühler verknüpft</p>` : nothing}
</div>`;
}
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}`];
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>.status-reading{grid-column:1/-1}.station-summary b{white-space:nowrap;font-variant-numeric:tabular-nums}`];
}
class HydronicDialog extends LitElement {
@@ -93,12 +98,12 @@ class HydronicDialog extends LitElement {
render() {
if (!this.hass || !this.item) return nothing;
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}
${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>`)}
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">${statusRow(this.hass,h.status,"Anlagenstatus")}
${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>${statusRow(this.hass,c.status)}${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}
${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>${statusRow(this.hass,s.status)}${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}
${!rows.length && !realRef(h.status) && 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>`;
}
+15
View File
@@ -30,6 +30,21 @@ test("independent station feedback keeps zero/offline values and never falls bac
visual=hydronicVisual(h,f,"g",.7);assert.equal(visual.stations?.[0].pump,null);assert.equal(visual.stations?.[0].temperatures[3],null);assert.equal(visual.stations?.[1].pump,true);
});
test("shared and individual station statuses survive migration and persistence; removal releases only that unit",()=>{
const original={status:"lock.10",flow:"cover.1"};
const legacy=freshwaterStations(item({hydronic:original}));
const hydronic=withFreshwaterStations(original,[{...legacy[0],status:"light.11"},{...newFreshwaterStation("second"),status:"cover.12"}]);
const f=item({hydronic});
assert.equal(hydronic.status,"lock.10");
const b=normalizeBuilding(JSON.parse(JSON.stringify({...emptyBuilding(),floors:[floorWith([],{furniture:[f]})]})));
assert.deepEqual(b.floors[0].furniture[0].hydronic,JSON.parse(JSON.stringify(hydronic)));
assert.deepEqual(hydronicRefs(f).sort(),["lock.10","light.11","cover.12","cover.1"].sort());
hydronic.stations=hydronic.stations!.slice(0,1);
assert.ok(!hydronicRefs(f).includes("cover.12"));
assert.ok(hydronicRefs(f).includes("lock.10"));
assert.equal(newFreshwaterStation("new").status,undefined);
});
test("all cascade and common circulation links are watched; removed stations and disabled valves release their refs",()=>{
const f=item({hydronic:{buffer_id:"buffer-object",stations:[{id:"a",name:"A",flow:"cover.1",pump:{command:"light.2",feedback:"lock.3"},valve:{command:"cover.4",feedback:"light.5"},power:"climate.6"},{id:"b",name:"B",hot_water:"sensor.7",cold_water:"sensor.8"}],circulation:{feedback:"sensor.9"}}});
const b={...emptyBuilding(),floors:[floorWith([],{furniture:[f]})]},h=hassOf([],{}, {symconObjects:[]});
+1
View File
@@ -4,6 +4,7 @@ import type { HydronicConfig, HydronicControl } from "./hydronic-model.ts";
export const MAX_FRESHWATER_STATIONS = 16;
export interface FreshwaterStation {
id: string; name: string;
status?: string | null;
flow?: string | null; return?: string | null; hot_water?: string | null; cold_water?: string | null; power?: string | null;
pump?: HydronicControl; valve?: HydronicControl; has_valve?: boolean;
}
+5 -3
View File
@@ -11,11 +11,13 @@ export interface HydronicCircuit {
valve_type?: "mixing" | "two_way";
pump?: HydronicControl; valve?: HydronicControl;
flow?: EntityRef; return?: EntityRef; power?: EntityRef;
status?: EntityRef;
mode_entity?: EntityRef; cooling_value?: number;
}
export interface HydronicProbe { id: string; name: string; entity: EntityRef; level: number }
export interface HydronicConfig {
card?: boolean;
status?: EntityRef;
circuits?: HydronicCircuit[];
sensors?: HydronicProbe[];
flow?: EntityRef; return?: EntityRef;
@@ -41,9 +43,9 @@ const controlRefs = (c: HydronicControl | undefined) => [c?.command, c?.feedback
export function hydronicRefs(item: Pick<Furniture, "type" | "hydronic">): string[] {
if (!isHydronic(item.type)) return [];
const h = hydronicConfig(item);
return [...new Set([...(item.type === "freshwater_station" ? [] : [h.flow, h.return]),
...(item.type === "heating_manifold" ? (h.circuits ?? []).flatMap((c) => [c.flow, c.return, c.power, c.mode_entity, ...(hasPump(c) ? controlRefs(c.pump) : []), ...(hasValve(c) ? controlRefs(c.valve) : [])]) : []),
return [...new Set([h.status, ...(item.type === "freshwater_station" ? [] : [h.flow, h.return]),
...(item.type === "heating_manifold" ? (h.circuits ?? []).flatMap((c) => [c.status, c.flow, c.return, c.power, c.mode_entity, ...(hasPump(c) ? controlRefs(c.pump) : []), ...(hasValve(c) ? controlRefs(c.valve) : [])]) : []),
...(item.type === "buffer_tank" ? (h.sensors ?? []).map((s) => s.entity) : []),
...(item.type === "freshwater_station" ? [h.circulation_temperature, ...controlRefs(h.circulation), ...freshwaterStations(item).flatMap((s) => [s.flow, s.return, s.hot_water, s.cold_water, s.power, ...controlRefs(s.pump), ...(stationHasValve(s) ? controlRefs(s.valve) : [])])] : []),
...(item.type === "freshwater_station" ? [h.circulation_temperature, ...controlRefs(h.circulation), ...freshwaterStations(item).flatMap((s) => [s.status, s.flow, s.return, s.hot_water, s.cold_water, s.power, ...controlRefs(s.pump), ...(stationHasValve(s) ? controlRefs(s.valve) : [])])] : []),
].filter(realRef))];
}
+20
View File
@@ -9,6 +9,26 @@ import { watchedEntities } from "./components/view3d/watch-list.ts";
const piece = (type: string, extra: Partial<Furniture> = {}): Furniture => { const [w,d,h] = FURNITURE_SIZE[type as keyof typeof FURNITURE_SIZE]; return { id: "hyd", type, x: 0, z: 0, w,d,h,rotation:0,variant:null, ...extra }; };
const native = (id: string, value: number | boolean, extra: Record<string, unknown> = {}) => entity(id, "open", { symcon_id: 123, symcon_variable_type: typeof value === "boolean" ? 0 : 2, symcon_value: value, symcon_min: 0, symcon_max: 100, ...extra });
test("hydronic status retains native integer aliases, including zero, and shows missing readings explicitly", () => {
const h = hassOf([native("cover.arbitrary", 0, {symcon_variable_type:1, symcon_formatted:"Bereitschaft", symcon_has_action:true})]);
assert.equal(hydronicReading(h, "Status", "cover.arbitrary")!.text, "Bereitschaft");
h.states["cover.arbitrary"] = native("cover.arbitrary", 7, {symcon_variable_type:1, symcon_formatted:"Warmwasserbereitung"});
assert.equal(hydronicReading(h, "Status", "cover.arbitrary")!.text, "Warmwasserbereitung");
h.states["cover.arbitrary"].state = "unavailable";
assert.equal(hydronicReading(h, "Status", "cover.arbitrary")!.text, "–");
assert.equal(hydronicReading(h, "Status", null), null);
});
test("plant and circuit statuses persist and are watched even for valve-free pumps without other bindings", () => {
const item = piece("heating_manifold", {hydronic:{status:"lock.42",circuits:[{...newCircuit("feed"),kind:"pump",status:"cover.43"}]}});
const b = normalizeBuilding(JSON.parse(JSON.stringify({...emptyBuilding(),floors:[floorWith([],{furniture:[item]})]})));
assert.deepEqual(b.floors[0].furniture[0].hydronic,item.hydronic);
const watched = watchedEntities({hass:hassOf([]),building:b,openingLinks:new Map(),furnitureLinks:new Map(),needsRoomSensors:false,alertSources:null,weatherEntityId:null});
assert.ok(["lock.42","cover.43"].every((id)=>watched.includes(id)));
item.hydronic!.circuits![0].status = null;
assert.deepEqual(hydronicRefs(item),["lock.42"]);
});
test("a buffer starts with seven unique probes from top to bottom and remains freely configurable after persistence", () => {
const item = piece("buffer_tank", { hydronic: defaultHydronic("buffer_tank") });
item.hydronic!.sensors!.forEach((s, i) => assert.ok(Math.abs(s.level - (6 - i) / 6) < 1e-10));