feat: add floating room climate cards and fix Symcon humidity selection
This commit is contained in:
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>`;
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import { gateStates } from "../entities/gates.ts";
|
||||
import { weatherEntity } from "../weather.ts";
|
||||
import { chosenEffects, readSkyWeather, withDensity } from "../live/sky-weather.ts";
|
||||
import { energyPicture, houseHub, type EnergyPicture } from "../live/energy-flow.ts";
|
||||
import { roomClimateCards } from "../live/room-climate-card.ts";
|
||||
import { loadWeek, type WeekBars } from "../live/week-bars.ts";
|
||||
import { binsDue, loadToday, sortDay, type TodayItem } from "../live/today.ts";
|
||||
import { forecastDays, loadForecast } from "../live/forecast.ts";
|
||||
@@ -690,7 +691,7 @@ export class NfView3d extends LitElement {
|
||||
if (changed.has("building") || changed.has("theme") || changed.has("floorThumbs") || changed.has("packs")) this.scheduleThumbs();
|
||||
// markers shown by kind outside the opened room change with the room
|
||||
const byRoom = this.markersOutside ? ["markersOutside", "floorId", "roomId"] : ["markersOutside"];
|
||||
const forced = this.pluginsDirty || ["building", "markerMode", "heatMode", "flows", "alerts", "dimmed", ...byRoom].some((k) => changed.has(k));
|
||||
const forced = this.pluginsDirty || ["building", "markerMode", "heatMode", "flows", "alerts", "dimmed", "holograms", "roomLabels", "floorId", "roomId", ...byRoom].some((k) => changed.has(k));
|
||||
this.pluginsDirty = false;
|
||||
if (forced || changed.has("hass")) this.syncDevices(forced);
|
||||
if (changed.has("autoOrbit")) v.setAutoOrbit(this.autoOrbit ? 0.06 : 0);
|
||||
@@ -969,7 +970,7 @@ export class NfView3d extends LitElement {
|
||||
playing.filter((m) => m.rings > 0).map((m) => ({ id: m.entity, at: m.at, color: m.color, level: m.volume ?? 0.5, size: m.rings })),
|
||||
multiroom(playing).map(([a, c]) => [a.at, c.at]),
|
||||
);
|
||||
this.syncLhCards(v, b, livePic, liveCars, playing);
|
||||
this.syncLhCards(v, b, livePic, liveCars, playing, hass);
|
||||
// TV screens: a TV or monitor linked to a media player that runs shows what runs
|
||||
v.setLiveScreens(this.dimmed ? [] : liveScreens(hass, b, this.furnitureLinks));
|
||||
v.setPictures(this.framePictures(hass, b));
|
||||
@@ -2618,7 +2619,7 @@ export class NfView3d extends LitElement {
|
||||
.catch(() => (this.dayCurves = null));
|
||||
}
|
||||
|
||||
private syncLhCards(v: NextFloorViewer, b: Building, pic: EnergyPicture, cars: ReturnType<NfView3d["liveCars"]>, media: MediaNow[]): void {
|
||||
private syncLhCards(v: NextFloorViewer, b: Building, pic: EnergyPicture, cars: ReturnType<NfView3d["liveCars"]>, media: MediaNow[], hass: HomeAssistant): void {
|
||||
const cards: LiveCard[] = [];
|
||||
const s = pic.summary;
|
||||
const hasEnergy = s.solar !== null || s.grid !== null || s.battery !== null || s.consumption !== null;
|
||||
@@ -2639,6 +2640,7 @@ export class NfView3d extends LitElement {
|
||||
for (const p of this.liveHeatPumps(b)) cards.push({ kind: "heatpump", at: p.at, name: p.name, pump: p.pump });
|
||||
for (const m of media) cards.push({ kind: "media", at: { ...m.at, y: m.at.y + 0.5 }, media: m });
|
||||
}
|
||||
if (this.liveCardsOn && !this.dimmed) cards.push(...roomClimateCards(hass, b, this.floorId, this.roomId));
|
||||
if (JSON.stringify(cards) !== JSON.stringify(this._liveCards)) this._liveCards = cards;
|
||||
v.setLiveAnchors(
|
||||
cards.map((c) => c.at),
|
||||
@@ -2689,7 +2691,9 @@ export class NfView3d extends LitElement {
|
||||
const own = this.ownSensors();
|
||||
const e = this._liveEnergy?.summary;
|
||||
const energy = !!e && !this.roomId && this.showEnergy && !!this.hass && !(e.consumption === null && e.grid === null && e.solar === null && e.battery === null);
|
||||
if (!energy) return own.length ? html`<div class="nf-energy" aria-live="off">${own}</div>` : nothing;
|
||||
const climate = this.building?.floors.some((f) => f.rooms.some((r) => r.climate_card));
|
||||
const climateToggle = climate ? this.renderCardToggle() : nothing;
|
||||
if (!energy) return own.length || climateToggle !== nothing ? html`<div class="nf-energy" aria-live="off">${own}${climateToggle}</div>` : nothing;
|
||||
const t = (k: Parameters<typeof translate>[1]) => translate(this.hass, k);
|
||||
const items: { cls: string; label: string; value: string }[] = [];
|
||||
if (e.solar !== null) items.push({ cls: "solar", label: t("energy_solar"), value: formatPower(this.hass, e.solar) });
|
||||
@@ -2712,15 +2716,17 @@ export class NfView3d extends LitElement {
|
||||
: html`<button class="nf-energy-item nf-flow-toggle" aria-pressed=${this._flows} title=${t("flows_hint")} aria-label=${t("flows")} @click=${() => this.toggleFlows()}>
|
||||
<span>${t("flows")}</span><b>⚡</b>
|
||||
</button>`}
|
||||
${this.holograms !== null
|
||||
? nothing
|
||||
: html`<button class="nf-energy-item nf-flow-toggle" aria-pressed=${this._liveCardOn} title=${t("holos_hint")} aria-label=${t("holos")} @click=${() => this.toggleLhCards()}>
|
||||
<span>${t("holos")}</span><b>◫</b>
|
||||
</button>`}
|
||||
${this.renderCardToggle()}
|
||||
${own}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
private renderCardToggle() {
|
||||
return this.holograms !== null ? nothing : html`<button class="nf-energy-item nf-flow-toggle nf-card-toggle" aria-pressed=${this._liveCardOn} title=${translate(this.hass, "holos_hint")} aria-label=${translate(this.hass, "holos")} @click=${() => this.toggleLhCards()}>
|
||||
<span>${translate(this.hass, "holos")}</span><b>◫</b>
|
||||
</button>`;
|
||||
}
|
||||
|
||||
/** The plan's own sensors at the top (outside temperature, the alarm…): their name and state; a tap opens their details. */
|
||||
private ownSensors() {
|
||||
const ids = this.sensorBar && this.hass ? (this.building?.settings.status_entities ?? []) : [];
|
||||
@@ -2795,7 +2801,7 @@ export class NfView3d extends LitElement {
|
||||
class="nf-stage ${this.roomLabels ? "" : "nf-no-room-names"} ${this._low ? "nf-low" : ""} ${this.panelOpen ? "nf-panel-open" : ""} ${this._alerts.length ? "nf-has-alerts" : ""} ${this._narrowStage ? "nf-narrow" : ""}"
|
||||
style=${style}
|
||||
>
|
||||
${this._error ? html`<p class="nf-error">${this._error}</p>` : nothing} ${this.renderTopLeft()} ${renderLhCards(this.hass, this.roomId || this.panelOpen ? [] : this._liveCards, (domain, service, entity, data) => this.hass?.callService(domain, service, { entity_id: entity, ...data }), { folded: this._houseFolded, toggle: () => this.toggleHouseFold() })} ${this.clean ? nothing : this.renderLegend()} ${this.renderMapCredit()}
|
||||
${this._error ? html`<p class="nf-error">${this._error}</p>` : nothing} ${this.renderTopLeft()} ${renderLhCards(this.hass, this._liveCards, (domain, service, entity, data) => this.hass?.callService(domain, service, { entity_id: entity, ...data }), { folded: this._houseFolded, toggle: () => this.toggleHouseFold() }, !!this.roomId || this.panelOpen)} ${this.clean ? nothing : this.renderLegend()} ${this.renderMapCredit()}
|
||||
${this.renderAlerts()} ${this.renderAnnouncement()} ${this.clean ? nothing : html`${this.renderThumbs()} ${this.renderScenes()} ${this.renderFind()} ${this.renderCentral()}`} ${this.renderSwipe()}
|
||||
${this.renderMenu()} ${this.renderPlate()} ${this.renderEye()} ${this.renderLock()} ${this.renderWalk()} ${this.renderTravel()} ${this.renderClock()} ${this.renderToday()} ${this.renderLayers()} ${this.renderPluginWindow()}
|
||||
${this.showStats && this._stats
|
||||
|
||||
@@ -47,3 +47,10 @@ test("a standalone blind's separate slat position is watched", () => {
|
||||
b.floors[0].placements.push({ entity_id: "cover.blind", cover_tilt: "cover.slats", x: 2, z: 2, y: null });
|
||||
assert.ok(watchedEntities(inputs({ building: b })).includes("cover.slats"));
|
||||
});
|
||||
|
||||
test("room cards watch explicitly chosen values outside the area, including a source that is temporarily missing", () => {
|
||||
const b = building();
|
||||
Object.assign(b.floors[0].rooms[0], { climate_card: true, climate: { humidity: "cover.knx", temperature: "sensor.missing", co2: "sensor.other_room" } });
|
||||
const ids = watchedEntities(inputs({ building: b, needsRoomSensors: false }));
|
||||
for (const id of ["cover.knx", "sensor.missing", "sensor.other_room"]) assert.ok(ids.includes(id), id);
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
// everything it shows: devices and their power sensors, openings and their contacts, energy, presence, heat, weather, and so on.
|
||||
|
||||
import { alertEntities, type AlertSources } from "../../alerts.ts";
|
||||
import { carWatched, deviceSiblings, kindOf, robotRoomSensor, type FurnitureLinks, type OpeningEntities, roomEntities } from "../../devices.ts";
|
||||
import { carWatched, deviceSiblings, kindOf, robotRoomSensor, roomClimateSensors, type FurnitureLinks, type OpeningEntities, roomEntities } from "../../devices.ts";
|
||||
import { powerSensorFor } from "../../energy.ts";
|
||||
import { placedEntities } from "../../markers.ts";
|
||||
import type { Building } from "../../model.ts";
|
||||
@@ -59,7 +59,9 @@ export function watchedEntities(inputs: WatchInputs): string[] {
|
||||
const placed = placedEntities(b);
|
||||
const energy = b.energy;
|
||||
const lightsOfRooms = roomsOf(b).flatMap((r) => roomEntities(hass, r).filter((id) => kindOf(id) === "light"));
|
||||
const sensorsOfRooms = inputs.needsRoomSensors ? roomsOf(b).flatMap((r) => roomEntities(hass, r).filter((id) => id.startsWith("sensor.") || id.startsWith("climate."))) : [];
|
||||
const sensorsOfRooms = b.floors.flatMap((f) => f.rooms.flatMap((r) => inputs.needsRoomSensors || r.climate_card
|
||||
? [...roomEntities(hass, r).filter((id) => id.startsWith("sensor.") || id.startsWith("climate.")), ...Object.values(r.climate ?? {}).flat(), ...(["temperature", "humidity", "co2"] as const).flatMap((key) => roomClimateSensors(hass, f, r, key))]
|
||||
: []));
|
||||
const ids: MaybeId[] = [
|
||||
...placed,
|
||||
...b.floors.flatMap((f) => f.placements.map((p) => p.cover_tilt)),
|
||||
|
||||
Reference in new issue
Block a user