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

+31 -3
View File
@@ -18,6 +18,8 @@ import { curvePath } from "./day-curves.ts";
import type { PrinterInfo } from "./printer.ts";
import type { HeatPumpInfo } from "./heat-pump.ts";
import type { PlanPoint } from "../viewer/live-energy.ts";
import type { RoomClimateCard } from "./room-climate-card.ts";
import { fromCelsius, tempUnit } from "../devices.ts";
export interface HouseCard {
kind: "house";
@@ -60,7 +62,7 @@ export interface HeatPumpCard {
pump: HeatPumpInfo;
}
export type LiveCard = HouseCard | CarCard | MediaCard | PrinterCard | HeatPumpCard;
export type LiveCard = HouseCard | CarCard | MediaCard | PrinterCard | HeatPumpCard | RoomClimateCard;
/** A button on a card was pressed: the 3D view calls the service (with extra data such as the volume). */
export type LiveCardAction = (domain: string, service: string, entity: string, data?: Record<string, unknown>) => void;
@@ -312,10 +314,21 @@ function heatPumpCard(hass: HomeAssistant | undefined, c: HeatPumpCard, i: numbe
</div>`;
}
export function renderLhCards(hass: HomeAssistant | undefined, cards: readonly LiveCard[], act: LiveCardAction, fold?: LiveCardFold): TemplateResult | typeof nothing {
function roomClimateCard(hass: HomeAssistant | undefined, c: RoomClimateCard, i: number): TemplateResult {
const value = (n: number | null, digits: number, unit: string) => n === null ? "–" : `${formatNumber(hass, n, digits)} ${unit}`;
return html`<div class="live-card live-card-roomclimate" data-i=${i} data-room=${c.roomId}>
<div class="live-title">${c.name || translate(hass, "room")}</div>
<div class="live-row live-climate-temperature"><span>🌡 ${translate(hass, "climate_temperature")}</span><b>${value(c.temperature === null ? null : hass ? fromCelsius(hass, c.temperature) : c.temperature, 1, hass ? tempUnit(hass) : "°C")}</b></div>
<div class="live-row live-climate-humidity"><span>💧 ${translate(hass, "climate_humidity")}</span><b>${value(c.humidity, 0, "%")}</b></div>
<div class="live-row live-climate-co2"><span>${translate(hass, "climate_co2")}</span><b>${value(c.co2, 0, "ppm")}</b></div>
${c.temperature === null && c.humidity === null && c.co2 === null ? html`<small class="live-status">${translate(hass, "climate_card_missing")}</small>` : nothing}
</div>`;
}
export function renderLhCards(hass: HomeAssistant | undefined, cards: readonly LiveCard[], act: LiveCardAction, fold?: LiveCardFold, climateOnly = false): TemplateResult | typeof nothing {
if (!cards.length) return nothing;
return html`<div class="live-cards">
${cards.map((c, i) => (c.kind === "house" ? houseCard(hass, c, i, fold) : c.kind === "car" ? carCard(hass, c, i, act) : c.kind === "printer" ? printerCard(hass, c, i) : c.kind === "heatpump" ? heatPumpCard(hass, c, i) : mediaCard(hass, c, i, act)))}
${cards.map((c, i) => (c.kind === "roomclimate" ? roomClimateCard(hass, c, i) : climateOnly ? nothing : c.kind === "house" ? houseCard(hass, c, i, fold) : c.kind === "car" ? carCard(hass, c, i, act) : c.kind === "printer" ? printerCard(hass, c, i) : c.kind === "heatpump" ? heatPumpCard(hass, c, i) : mediaCard(hass, c, i, act)))}
</div>`;
}
@@ -418,6 +431,21 @@ export const liveCardStyles = css`
gap: 2px;
min-width: 150px;
}
.live-card-roomclimate {
display: grid;
gap: 4px;
min-width: 190px;
max-width: calc(100vw - 24px);
box-sizing: border-box;
}
.live-card-roomclimate .live-title {
overflow: hidden;
text-overflow: ellipsis;
max-width: 220px;
}
.live-climate-temperature b { color: color-mix(in srgb, #ffca8a 80%, var(--nf-text)); }
.live-climate-humidity b { color: color-mix(in srgb, #7dd3fc 80%, var(--nf-text)); }
.live-climate-co2 b { color: color-mix(in srgb, #c4b5fd 80%, var(--nf-text)); }
.live-row {
display: flex;
justify-content: space-between;