feat: add floating room climate cards and fix Symcon humidity selection

This commit is contained in:
jhartworks committed 2026-11-09 17:04:46 +01:00
1 parent 24188f96f7
commit ff54f4461a
21 files changed
+764 -398

No files matched your search

@@ -5,7 +5,7 @@ import { entityAreaId, entityKind, entityName, groupByDevice, isClimateValueSens
import { iconPath } from "../../../icons.ts";
import { pointInPolygon, type Room } from "../../../model.ts";
import { entityOptions } from "../entities.ts";
import { deviceIcon, entityField, hint } from "../fields.ts";
import { checkField, deviceIcon, entityField, hint } from "../fields.ts";
import type { EditorHost } from "../host.ts";
import { matchesQuery, placedElsewhere, placedInRoom, rankedBy, takeFirst, withToggled } from "../ops/device-list.ts";
import type { SideState } from "../side-state.ts";
@@ -133,10 +133,10 @@ export function renderRoomClimate(host: EditorHost, room: Room, patch: (patch: P
};
const field = (key: ClimateKey, label: string) => {
const found = roomClimateSensors(hass, host.floor ?? null, { ...room, climate: null }, key);
const wanted = entityOptions(hass, (id) => isClimateValueSensor(hass, id, key));
const picked = [room.climate?.[key] ?? null].flat();
const wanted = entityOptions(hass, (id) => isClimateValueSensor(hass, id, key, true) && (!hass.states[id]?.attributes.symcon_source_entity || picked.includes(id)));
// the room's own sensors first, then the others; device temperatures (a printer, a heat pump) come last
const options = rankedBy(wanted, (id) => (entityAreaId(hass, id) === room.area_id ? 0 : 1) + (isRoomClimateSensor(hass, id) ? 0 : 2));
const picked = [room.climate?.[key] ?? null].flat();
// several sensors are averaged: once one is chosen, another can be added; "none" in a slot drops it
const save = (list: (string | null)[]) => {
const ids = list.filter((id): id is string => !!id && id !== "none");
@@ -146,9 +146,11 @@ export function renderRoomClimate(host: EditorHost, room: Room, patch: (patch: P
const slots = real ? [...picked, null] : picked;
return slots.map((id, i) => entityField(host, i ? host.t("climate_more") : label, id, i ? undefined : (found[0] ?? null), options, (v) => save(slots.map((x, j) => (j === i ? v : x)))));
};
return html`<details class="nf-points" ?open=${chosen}>
return html`<details class="nf-points" ?open=${chosen || !!room.climate_card}>
<summary>${host.t("climate")}</summary>
<div class="nf-form">${field("temperature", host.t("climate_temperature"))} ${field("humidity", host.t("climate_humidity"))} ${field("co2", host.t("climate_co2"))}</div>
${checkField(host, host.t("climate_card"), !!room.climate_card, (on) => patch({ climate_card: on || undefined }))}
${hint(host.t("climate_card_hint"))}
${hint(host.t("climate_hint"))}
</details>`;
}