feat: add native Symcon archive trends and explicit room naming

This commit is contained in:
jhartworks committed 2026-11-11 12:00:51 +01:00
1 parent bb153490b0
commit cfc77787a0
28 files changed
+2449 -1250

No files matched your search

+17 -16
View File
@@ -12,6 +12,7 @@ import { isSymcon, nativeText } from "../entities/symcon-values.ts";
import "./room-hvac.ts";
import "./utility-report.ts";
import { roomUtilityReadings, utilityText } from "../utilities.ts";
import { trendButton } from "./trend-button.ts";
import type { Building, Floor, LightMood, LightSetting, Room } from "../model.ts";
import { roomPower, roomPowerSensors } from "../heatmap.ts";
import { energyCost, loadRoomEnergy, type RoomEnergy } from "../live/room-energy.ts";
@@ -473,7 +474,7 @@ export class NfRoomPanel extends LitElement {
<header class="nf-rp-head">
<div>
<h2>${room.name}</h2>
${facts.length ? html`<p class="nf-rp-facts">${facts.join(" · ")}</p>` : nothing} ${this.renderEnergy()} ${this.renderSunYear()} ${this.renderShade()}
${facts.length ? html`<p class="nf-rp-facts">${facts.map((fact, i) => html`${i ? " · " : nothing}${fact}`)}</p>` : nothing} ${this.renderEnergy()} ${this.renderSunYear()} ${this.renderShade()}
${this.renderOpenWhileHeating(climates)} ${this.renderEmptyLights(room, lightsOn)}
${this.renderCurve()}
</div>
@@ -561,11 +562,11 @@ export class NfRoomPanel extends LitElement {
if (!this.floor) return nothing;
const groups = [...this.floor.placements.filter((p) => !p.outside && pointInPolygon([p.x, p.z], room.points)).map((p) => ({ name: p.name || entityName(this.hass, p.entity_id), rows: deviceValueReadouts(this.hass, p.values) })),
...this.floor.furniture.filter((f) => pointInPolygon([f.x, f.z], room.points)).map((f) => ({ name: f.name || (f.entity && f.entity !== "none" ? entityName(this.hass, f.entity) : this.t("device")), rows: deviceValueReadouts(this.hass, f.values) }))].filter((g) => g.rows.length);
return groups.length ? this.section("device_values", groups.map((g) => html`<div class="nf-extra-values"><b>${g.name}</b>${g.rows.map((v) => html`<div class="nf-rp-row"><span class="nf-rp-icon">${v.icon}</span><span class="nf-rp-name">${v.label}</span><b class="nf-rp-state">${v.text}</b></div>`)}</div>`)) : nothing;
return groups.length ? this.section("device_values", groups.map((g) => html`<div class="nf-extra-values"><b>${g.name}</b>${g.rows.map((v) => html`<div class="nf-rp-row"><span class="nf-rp-icon">${v.icon}</span><span class="nf-rp-name">${v.label}</span><b class="nf-rp-state">${v.text}${trendButton(this.hass, [v.entity], v.label)}</b></div>`)}</div>`)) : nothing;
}
private facts(climates: HassEntity[]): string[] {
const out: string[] = [];
private facts(climates: HassEntity[]): (string | TemplateResult)[] {
const out: (string | TemplateResult)[] = [];
const room = this.room;
// Outside has no climate of its own
if (!room) return out;
@@ -579,16 +580,16 @@ export class NfRoomPanel extends LitElement {
};
const climateTemp = climates.find((c) => typeof c.attributes.current_temperature === "number");
const temp = value("temperature", "°C");
if (temp) out.push(temp);
else if (climateTemp && room.climate?.temperature !== "none") out.push(`${formatNumber(this.hass, climateTemp.attributes.current_temperature as number, 1)} ${tempUnit(this.hass)}`);
if (temp) out.push(html`${temp}${trendButton(this.hass, roomClimateSensors(this.hass, this.floor, room, "temperature"), "Temperatur")}`);
else if (climateTemp && room.climate?.temperature !== "none") out.push(html`${formatNumber(this.hass, climateTemp.attributes.current_temperature as number, 1)} ${tempUnit(this.hass)}${trendButton(this.hass, [climateTemp.entity_id], "Temperatur")}`);
const hum = value("humidity", "%");
if (hum) out.push(hum);
if (hum) out.push(html`${hum}${trendButton(this.hass, roomClimateSensors(this.hass, this.floor, room, "humidity"), "Luftfeuchte")}`);
const lux = roomClimateValue(this.hass, this.floor ?? null, room, "illuminance");
if (lux !== null) out.push(`☀ ${formatNumber(this.hass, lux, 0)} lx`);
if (lux !== null) out.push(html`☀ ${formatNumber(this.hass, lux, 0)} lx${trendButton(this.hass, roomClimateSensors(this.hass, this.floor, room, "illuminance"), "Helligkeit")}`);
// what the room's devices draw now
const meter = roomUtilityReadings(this.hass, room, this.building?.floors.flatMap((f) => f.rooms)).find((r) => r.kind === "electricity" && r.metric === "power" && r.unit === "W");
const power = !meter && this.floor && this.building ? roomPower(this.hass, this.building, this.floor, room) : null;
if (meter) out.push(`⚡ ${utilityText(this.hass, meter)}`);
if (meter) out.push(html`⚡ ${utilityText(this.hass, meter)}${trendButton(this.hass, meter.sources, "Leistung")}`);
else if (power !== null) out.push(`⚡ ${powerText(this.hass, power)}`);
// how long its windows and doors stand open (the one open longest)
const openSince = this.floor
@@ -633,7 +634,7 @@ export class NfRoomPanel extends LitElement {
// how comfortable it is (0 … 100)
const comfort = comfortScore(t, h, roomClimateValue(this.hass, this.floor, room, "co2"), isSummer(new Date(), this.hass.config?.latitude));
const status = room.hvac?.status;
if (status && status !== "none") out.push(nativeText(this.hass.states[status]));
if (status && status !== "none") out.push(html`${nativeText(this.hass.states[status])}${trendButton(this.hass, [status], "Raumstatus")}`);
else if (comfort !== null && (t !== null || h !== null) && !off.includes("comfort")) out.push(`😊 ${this.t("comfort_n", { n: comfort })}`);
return out;
}
@@ -700,7 +701,7 @@ export class NfRoomPanel extends LitElement {
return html`<div class="nf-rp-row">
<span class="nf-rp-icon ${on ? "nf-rp-on" : ""}">${icon("light")}</span>
${this.nameButton(id)}
<span class="nf-rp-state">${this.stateOf(st)}</span>
<span class="nf-rp-state">${this.stateOf(st)}${trendButton(this.hass, [st.entity_id])}</span>
${this.toggle(st, on, () => this.call("light", "toggle", { entity_id: id }))}
${dimmable && !simple
? html`<label class="nf-rp-slider"
@@ -751,7 +752,7 @@ export class NfRoomPanel extends LitElement {
return html`<div class="nf-rp-row">
<span class="nf-rp-icon">${icon("cover")}</span>
${this.nameButton(id)}
<span class="nf-rp-state">${this.stateOf(st)}</span>
<span class="nf-rp-state">${this.stateOf(st)}${trendButton(this.hass, [st.entity_id])}</span>
<div class="nf-rp-buttons">
<button class="nf-btn nf-rp-small" ?disabled=${na} @click=${() => this.askFor(id) && this.call("cover", "open_cover", { entity_id: id })}>${this.t("cover_open")}</button>
${features & COVER_STOP
@@ -803,7 +804,7 @@ export class NfRoomPanel extends LitElement {
return html`<div class="nf-rp-row">
<span class="nf-rp-icon ${a.hvac_action === "heating" ? "nf-rp-on" : ""}">${icon("climate")}</span>
${this.nameButton(id)}
<span class="nf-rp-state">${this.stateOf(st)}</span>
<span class="nf-rp-state">${this.stateOf(st)}${trendButton(this.hass, [st.entity_id])}</span>
${target !== null
? html`<div class="nf-rp-stepper nf-rp-wide">
<button class="nf-btn" aria-label=${this.t("temp_down")} @click=${() => set(target - step)}>−</button>
@@ -852,7 +853,7 @@ export class NfRoomPanel extends LitElement {
return html`<div class="nf-rp-row">
<span class="nf-rp-icon ${st.state === "playing" ? "nf-rp-on" : ""}">${icon("media")}</span>
${this.nameButton(id)}
<span class="nf-rp-state">${this.stateOf(st, this.stateLabel(st.state))}</span>
<span class="nf-rp-state">${this.stateOf(st, this.stateLabel(st.state))}${trendButton(this.hass, [st.entity_id])}</span>
${title ? html`<p class="nf-rp-media nf-rp-wide">${title}</p>` : nothing}
<div class="nf-rp-buttons nf-rp-wide">
<button class="nf-btn nf-rp-small" aria-label=${this.t("previous")} ?disabled=${na} @click=${() => this.call("media_player", "media_previous_track", { entity_id: id })}>
@@ -888,7 +889,7 @@ export class NfRoomPanel extends LitElement {
return html`<div class="nf-rp-row">
<span class="nf-rp-icon ${on ? "nf-rp-on" : ""}">${icon(kind)}</span>
${this.nameButton(id)}
<span class="nf-rp-state">${this.stateOf(st)}</span>
<span class="nf-rp-state">${this.stateOf(st)}${trendButton(this.hass, [st.entity_id])}</span>
${this.toggle(st, on, act)}
</div>`;
}
@@ -899,7 +900,7 @@ export class NfRoomPanel extends LitElement {
return html`<div class="nf-rp-row">
<span class="nf-rp-icon ${warn ? "nf-rp-on" : ""}">${icon(kind)}</span>
${this.nameButton(st.entity_id)}
<span class="nf-rp-state">${this.stateOf(st)}</span>
<span class="nf-rp-state">${this.stateOf(st)}${trendButton(this.hass, [st.entity_id])}</span>
</div>`;
}