fix: hide room climate cards in all-floors overview

This commit is contained in:
jhartworks committed 2026-11-10 12:32:59 +01:00
1 parent 3f6cca056c
commit 8845efdc23
8 files changed
+41 -14

No files matched your search

+7 -7
View File
@@ -12,7 +12,7 @@ test("enabled room cards use explicit numeric sensors, averages and temperature
entity("sensor.c", "20", { unit_of_measurement: "°C" }), entity("sensor.f", "68", { unit_of_measurement: "°F" }),
entity("cover.knx", "open", { symcon_numeric_value: 48.5 }), entity("sensor.co2", "780"), entity("sensor.lux", "320", { unit_of_measurement: "lx" }),
]);
const cards = roomClimateCards(h, normalizeBuilding(b), null, null);
const cards = roomClimateCards(h, normalizeBuilding(b), b.floors[0].id, null);
assert.equal(cards.length, 1);
assert.deepEqual([cards[0].temperature, cards[0].humidity, cards[0].co2], [20, 48.5, 780]);
assert.equal(cards[0].name, "Wohnzimmer");
@@ -20,7 +20,7 @@ test("enabled room cards use explicit numeric sensors, averages and temperature
assert.equal(cards[0].showIlluminance, true);
assert.ok(pointInPolygon([cards[0].at.x, cards[0].at.z], room.points));
h.states["cover.knx"] = entity("cover.knx", "open", { symcon_numeric_value: 55 });
assert.equal(roomClimateCards(h, b, null, null)[0].humidity, 55, "a fresh state updates the card values");
assert.equal(roomClimateCards(h, b, b.floors[0].id, null)[0].humidity, 55, "a fresh state updates the card values");
});
test("floor/room navigation filters cards and concave rooms keep their anchor inside", () => {
@@ -29,9 +29,9 @@ test("floor/room navigation filters cards and concave rooms keep their anchor in
const upper = { ...floorWith([{ ...box("upper", 0, 0, 4, 4), climate_card: true, climate: { temperature: "sensor.pending" } }]), id: "upper" };
b.floors = [floorWith([room]), upper];
const h = hassOf([]);
const all = roomClimateCards(h, b, null, null);
assert.equal(all.length, 2);
assert.ok(pointInPolygon([all[0].at.x, all[0].at.z], room.points));
assert.deepEqual(roomClimateCards(h, b, null, null), [], "all-floors view never shows room climate cards");
const [card] = roomClimateCards(h, b, b.floors[0].id, null);
assert.ok(pointInPolygon([card.at.x, card.at.z], room.points));
assert.deepEqual(roomClimateCards(h, b, "upper", null).map((c) => c.roomId), ["upper"]);
assert.deepEqual(roomClimateCards(h, b, null, "u").map((c) => c.roomId), ["u"]);
});
@@ -40,7 +40,7 @@ test("missing, unavailable and disabled readings stay missing rather than becomi
const b = emptyBuilding();
b.floors = [floorWith([{ ...box("r", 0, 0, 4, 4, "a"), climate_card: true, climate: { temperature: "sensor.offline", humidity: "sensor.empty", co2: "none" } }])];
const h = hassOf([entity("sensor.offline", "unavailable"), entity("sensor.empty", ""), entity("climate.other", "heat", { current_temperature: 30 })], { "climate.other": { area_id: "a" } });
const [card] = roomClimateCards(h, b, null, null);
const [card] = roomClimateCards(h, b, b.floors[0].id, null);
assert.deepEqual([card.temperature, card.humidity, card.co2], [null, null, null]);
assert.deepEqual([card.showTemperature, card.showHumidity, card.showCo2], [true, true, false]);
});
@@ -48,7 +48,7 @@ test("missing, unavailable and disabled readings stay missing rather than becomi
test("unlinked metrics are hidden and an entirely unlinked room has no empty card", () => {
const b = emptyBuilding();
b.floors = [floorWith([{ ...box("r", 0, 0, 4, 4), climate_card: true, climate: { temperature: "sensor.t", humidity: "none", co2: "none" } }, { ...box("empty", 5, 0, 9, 4), climate_card: true }])];
const [card, ...rest] = roomClimateCards(hassOf([entity("sensor.t", "22.7", { unit_of_measurement: "°C" })]), b, null, null);
const [card, ...rest] = roomClimateCards(hassOf([entity("sensor.t", "22.7", { unit_of_measurement: "°C" })]), b, b.floors[0].id, null);
assert.equal(rest.length, 0);
assert.deepEqual([card.showTemperature, card.showHumidity, card.showCo2], [true, false, false]);
});
+2 -1
View File
@@ -19,8 +19,9 @@ export interface RoomClimateCard {
showIlluminance: boolean;
}
/** One opt-in card per room, using the exact same sensor assignments and averaging as the room panel. */
/** Opt-in room cards for an opened floor/room; the all-floors overview stays clear. */
export function roomClimateCards(hass: HomeAssistant, building: Building, floorId: string | null, roomId: string | null): RoomClimateCard[] {
if (!floorId && !roomId) return [];
const cards: RoomClimateCard[] = [];
for (const floor of building.floors) {
if (floorId && floor.id !== floorId) continue;
+19
View File
@@ -126,6 +126,14 @@ try {
await page.waitForFunction(() => window.climateView.shadowRoot.querySelector(".nf-card-toggle"));
assert.equal(await page.evaluate(() => window.climateView.shadowRoot.querySelector(".nf-card-toggle").getAttribute("aria-pressed")), "false");
await page.evaluate(() => window.climateView.shadowRoot.querySelector(".nf-card-toggle").click());
await page.evaluate(async () => {
const p = window.nfPanel;
p.shadowRoot.querySelector("nf-view3d").syncDevices(true);
await window.climateView.updateComplete;
if (window.climateView.shadowRoot.querySelector(".live-card-roomclimate")) throw new Error("All-floors overview must not show room climate cards");
const name = p.data.building.floors.find((f) => f.id === window.climateFloorId).name;
[...p.shadowRoot.querySelectorAll(".nf-nav button")].find((b) => b.textContent.trim() === name).click();
});
await page.waitForFunction(() => window.climateView.shadowRoot.querySelectorAll(".live-card-roomclimate").length === 2);
const text = () => page.evaluate(() => window.climateView.shadowRoot.querySelector(`.live-card[data-room="${window.climateRoomId}"]`).textContent);
assert.match(await text(), /21,5\s*°C/);
@@ -137,6 +145,17 @@ try {
assert.equal(await page.evaluate(() => window.nfPanel.data.building.floors[0].rooms[0].climate.humidity), "cover.202");
assert.equal(await page.evaluate(() => window.climateView.shadowRoot.querySelector(`.live-card[data-room="${window.compactRoomId}"]`).querySelectorAll(".live-row").length), 1, "unlinked humidity and CO2 do not get rows");
assert.equal(await page.evaluate(() => [...window.climateView.shadowRoot.querySelectorAll(".live-card-roomclimate")].some((c) => /Wohnzimmer|Küche|Temperatur|Luftfeuchte/.test(c.textContent))), false, "cards show no repeated room name or metric labels");
await page.evaluate(() => {
const p = window.nfPanel;
[...p.shadowRoot.querySelectorAll(".nf-nav button")].find((b) => b.textContent.trim() === p.t("all_floors")).click();
});
await page.waitForFunction(() => window.climateView.floorId === null && !window.climateView.shadowRoot.querySelector(".live-card-roomclimate"));
await page.evaluate(() => {
const p = window.nfPanel;
const name = p.data.building.floors.find((f) => f.id === window.climateFloorId).name;
[...p.shadowRoot.querySelectorAll(".nf-nav button")].find((b) => b.textContent.trim() === name).click();
});
await page.waitForFunction(() => window.climateView.shadowRoot.querySelectorAll(".live-card-roomclimate").length === 2);
await page.evaluate(() => { window.humidityValue = 62.4; window.nfPanel.shadowRoot.querySelector(".nf-reload-variables").click(); });
await page.waitForFunction(() => window.climateView.shadowRoot.querySelector(`.live-card[data-room="${window.climateRoomId}"]`).textContent.includes("62 %"));
const out = join(root, "preview/screenshots");