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

+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() ?? "";
}
/**