feat: improve Symcon controls, device readings and designer help
This commit is contained in:
1 parent
ff54f4461a
commit
00fca890de
50 files changed
+2447
-1840
No files matched your search
@@ -316,12 +316,11 @@ function heatPumpCard(hass: HomeAssistant | undefined, c: HeatPumpCard, i: numbe
|
||||
|
||||
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}
|
||||
return html`<div class="live-card live-card-roomclimate" data-i=${i} data-room=${c.roomId} role="group" aria-label=${`${c.name || translate(hass, "room")} · ${translate(hass, "climate")}`}>
|
||||
${c.showTemperature ? html`<div class="live-row live-climate-temperature"><span title=${translate(hass, "climate_temperature")} aria-label=${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>` : nothing}
|
||||
${c.showHumidity ? html`<div class="live-row live-climate-humidity"><span title=${translate(hass, "climate_humidity")} aria-label=${translate(hass, "climate_humidity")}>💧</span><b>${value(c.humidity, 0, "%")}</b></div>` : nothing}
|
||||
${c.showCo2 ? html`<div class="live-row live-climate-co2"><span title=${translate(hass, "climate_co2")} aria-label=${translate(hass, "climate_co2")}>☁</span><b>${value(c.co2, 0, "ppm")}</b></div>` : nothing}
|
||||
${c.showIlluminance ? html`<div class="live-row live-climate-illuminance"><span title=${translate(hass, "climate_illuminance")} aria-label=${translate(hass, "climate_illuminance")}>☀</span><b>${value(c.illuminance, 0, "lx")}</b></div>` : nothing}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
@@ -434,18 +433,17 @@ export const liveCardStyles = css`
|
||||
.live-card-roomclimate {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
min-width: 190px;
|
||||
min-width: 96px;
|
||||
max-width: calc(100vw - 24px);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.live-card-roomclimate .live-title {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 220px;
|
||||
.live-card-roomclimate .live-row {
|
||||
gap: 12px;
|
||||
}
|
||||
.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-climate-illuminance b { color: color-mix(in srgb, #fde68a 80%, var(--nf-text)); }
|
||||
.live-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
@@ -6,16 +6,18 @@ import { roomClimateCards } from "./room-climate-card.ts";
|
||||
|
||||
test("enabled room cards use explicit numeric sensors, averages and temperature conversion", () => {
|
||||
const b = emptyBuilding();
|
||||
const room = { ...box("living", 0, 0, 4, 4), name: "Wohnzimmer", climate_card: true, climate: { temperature: ["sensor.c", "sensor.f"], humidity: "cover.knx", co2: "sensor.co2" } };
|
||||
const room = { ...box("living", 0, 0, 4, 4), name: "Wohnzimmer", climate_card: true, climate: { temperature: ["sensor.c", "sensor.f"], humidity: "cover.knx", co2: "sensor.co2", illuminance: "sensor.lux" } };
|
||||
b.floors = [floorWith([room, box("disabled", 5, 0, 8, 4)])];
|
||||
const h = hassOf([
|
||||
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("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);
|
||||
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");
|
||||
assert.equal(cards[0].illuminance, 320);
|
||||
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");
|
||||
@@ -23,8 +25,8 @@ test("enabled room cards use explicit numeric sensors, averages and temperature
|
||||
|
||||
test("floor/room navigation filters cards and concave rooms keep their anchor inside", () => {
|
||||
const b = emptyBuilding();
|
||||
const room = { ...box("u", 0, 0, 6, 6), climate_card: true, points: [[0, 0], [6, 0], [6, 6], [4, 6], [4, 2], [2, 2], [2, 6], [0, 6]] as [number, number][] };
|
||||
const upper = { ...floorWith([{ ...box("upper", 0, 0, 4, 4), climate_card: true }]), id: "upper" };
|
||||
const room = { ...box("u", 0, 0, 6, 6), climate_card: true, climate: { temperature: "sensor.pending" }, points: [[0, 0], [6, 0], [6, 6], [4, 6], [4, 2], [2, 2], [2, 6], [0, 6]] as [number, number][] };
|
||||
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);
|
||||
@@ -40,4 +42,13 @@ test("missing, unavailable and disabled readings stay missing rather than becomi
|
||||
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);
|
||||
assert.deepEqual([card.temperature, card.humidity, card.co2], [null, null, null]);
|
||||
assert.deepEqual([card.showTemperature, card.showHumidity, card.showCo2], [true, true, false]);
|
||||
});
|
||||
|
||||
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);
|
||||
assert.equal(rest.length, 0);
|
||||
assert.deepEqual([card.showTemperature, card.showHumidity, card.showCo2], [true, false, false]);
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { roomClimateValue } from "../devices.ts";
|
||||
import { roomClimateSensors, roomClimateValue, type ClimateKey } from "../devices.ts";
|
||||
import { centroid, pointInPolygon, spotGrid, type Building } from "../model.ts";
|
||||
import type { HomeAssistant } from "../types.ts";
|
||||
import type { PlanPoint } from "../viewer/live-energy.ts";
|
||||
@@ -12,6 +12,11 @@ export interface RoomClimateCard {
|
||||
temperature: number | null;
|
||||
humidity: number | null;
|
||||
co2: number | null;
|
||||
showTemperature: boolean;
|
||||
showHumidity: boolean;
|
||||
showCo2: boolean;
|
||||
illuminance: number | null;
|
||||
showIlluminance: boolean;
|
||||
}
|
||||
|
||||
/** One opt-in card per room, using the exact same sensor assignments and averaging as the room panel. */
|
||||
@@ -21,13 +26,23 @@ export function roomClimateCards(hass: HomeAssistant, building: Building, floorI
|
||||
if (floorId && floor.id !== floorId) continue;
|
||||
for (const room of floor.rooms) {
|
||||
if (!room.climate_card || room.points.length < 3 || (roomId && room.id !== roomId)) continue;
|
||||
const temperature = roomClimateValue(hass, floor, room, "temperature");
|
||||
const humidity = roomClimateValue(hass, floor, room, "humidity");
|
||||
const co2 = roomClimateValue(hass, floor, room, "co2");
|
||||
const illuminance = roomClimateValue(hass, floor, room, "illuminance");
|
||||
const linked = (key: ClimateKey, value: number | null) => {
|
||||
const chosen = room.climate?.[key];
|
||||
if (chosen === "none") return false;
|
||||
return (chosen ? [chosen].flat().some((id) => !!id && id !== "none") : false) || roomClimateSensors(hass, floor, room, key).length > 0 || value !== null;
|
||||
};
|
||||
const showTemperature = linked("temperature", temperature), showHumidity = linked("humidity", humidity), showCo2 = linked("co2", co2);
|
||||
const showIlluminance = linked("illuminance", illuminance);
|
||||
if (!showTemperature && !showHumidity && !showCo2 && !showIlluminance) continue;
|
||||
const middle = centroid(room.points);
|
||||
const [x, z] = pointInPolygon(middle, room.points) ? middle : spotGrid(room, 9, 9).sort((a, b) => Math.hypot(a[0] - middle[0], a[1] - middle[1]) - Math.hypot(b[0] - middle[0], b[1] - middle[1]))[0] ?? room.points[0];
|
||||
cards.push({ kind: "roomclimate", roomId: room.id, name: room.name,
|
||||
at: { floorId: floor.id, x, z, y: (room.ceiling ?? floor.height) + 0.4 },
|
||||
temperature: roomClimateValue(hass, floor, room, "temperature"),
|
||||
humidity: roomClimateValue(hass, floor, room, "humidity"),
|
||||
co2: roomClimateValue(hass, floor, room, "co2"),
|
||||
temperature, humidity, co2, illuminance, showTemperature, showHumidity, showCo2, showIlluminance,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user