fix: hide room climate cards in all-floors overview
This commit is contained in:
1 parent
3f6cca056c
commit
8845efdc23
8 files changed
+41
-14
No files matched your search
@@ -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]);
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user