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

@@ -1,9 +1,9 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { box, floorWith, opening } from "../../../entities/fixtures.ts";
import { box, floorWith, opening, hassOf } from "../../../entities/fixtures.ts";
import type { Placement } from "../../../model.ts";
import { setWallSlope } from "./edges.ts";
import { insertCorner, areaChoice, copyOfRoom, cornerMoved, evenCeilingLights, newRoom, rectangleAfter, removeCorner, removeRoom } from "./rooms.ts";
import { insertCorner, areaChoice, areaLeafName, copyOfRoom, cornerMoved, evenCeilingLights, newRoom, rectangleAfter, removeCorner, removeRoom } from "./rooms.ts";
const lamp = (id: string, x: number, z: number, extra: Partial<Placement> = {}): Placement => ({ entity_id: id, x, z, y: null, ...extra });
@@ -73,6 +73,14 @@ test("choosing an area names a room that only had a placeholder name", () => {
assert.deepEqual(areaChoice({ ...box("r", 0, 0, 1, 1), name: "Lounge" }, "", areas), { area_id: null });
});
test("Symcon area selection preserves the name and explicit adoption uses the real leaf category", () => {
const h = hassOf([], {}, { areas: { "symcon-category-10": { area_id: "symcon-category-10", name: "Haus / OG / Büro" } }, symconObjects: [{ object_id: 10, parent_id: 2, name: "Büro / Nord", path: "Haus / OG / Büro / Nord", object_type: 0, position: 0, hidden: true, icon: "" }] });
assert.deepEqual(areaChoice({ ...box("r", 0, 0, 1, 1), name: "Room 3" }, "symcon-category-10", h.areas!, false), { area_id: "symcon-category-10" });
assert.equal(areaLeafName(h, "symcon-category-10"), "Büro / Nord");
assert.equal(areaLeafName({ ...h, symconObjects: [] }, "symcon-category-10"), "Büro");
assert.equal(areaLeafName(h, "missing"), "");
});
test("ceiling lights spread over the room in a grid, a short last row over the full width", () => {
const room = box("r", 0, 0, 6, 4);
const lights = [lamp("light.a", 1, 1), lamp("light.b", 1.1, 1), lamp("light.c", 1.2, 1), lamp("light.d", 1.3, 1), lamp("light.e", 1.4, 1)];
+10 -2
View File
@@ -3,6 +3,7 @@
import { bounds, pointInPolygon, uid, type Floor, type Opening, type Placement, type Room, type Vec2 } from "../../../model.ts";
import { arcPoints, pieceAt, polylineLength } from "../../../geometry/arcs.ts";
import { kindOf } from "../../../devices.ts";
import type { HomeAssistant } from "../../../types.ts";
const thousandths = (v: number) => Math.round(v * 1000) / 1000;
const rounded = (points: readonly Vec2[]): Vec2[] => points.map(([x, z]) => [thousandths(x), thousandths(z)]);
@@ -73,10 +74,17 @@ const GENERIC_NAME = /^(Raum|Room) \d+$/;
* What choosing a Home Assistant area does to a room: it gets the area, and a name that was only a placeholder ("Room 3", or the
* name of some area) takes the area's name.
*/
export function areaChoice(room: Room, areaId: string, areas: Readonly<Record<string, { name: string }>>): Partial<Room> {
export function areaChoice(room: Room, areaId: string, areas: Readonly<Record<string, { name: string }>>, takeName = true): Partial<Room> {
const area = areaId ? areas[areaId] : undefined;
const placeholder = !room.name || GENERIC_NAME.test(room.name) || Object.values(areas).some((a) => a.name === room.name);
return { area_id: areaId || null, ...(area && placeholder ? { name: area.name } : {}) };
return { area_id: areaId || null, ...(takeName && area && placeholder ? { name: area.name } : {}) };
}
/** Use the actual leaf category, even when its native name contains a slash. */
export function areaLeafName(hass: HomeAssistant | undefined, areaId: string): string {
const id = /^symcon-category-(\d+)$/.exec(areaId)?.[1];
return (id ? hass?.symconObjects?.find((n) => n.object_id === Number(id))?.name : undefined)
?? hass?.areas?.[areaId]?.name.split(" / ").at(-1)?.trim() ?? "";
}
/**