Fix empty plan render snapshot

Issue: #111
User-Visible: yes
This commit is contained in:
Sergey Matyunin
2026-08-13 11:41:23 +03:00
committed by Matysh
parent 495a99872b
commit 30f71af200
8 changed files with 76 additions and 9 deletions
+7 -2
View File
@@ -164,7 +164,8 @@ import {
valueBadgeSourceKey, valueBadgeTitle, valueBadgeWriteFields, type ValueBadgeCandidate,
} from './device-value-badge';
import {
createRenderDeviceSnapshot, presentationSnapshotKey, type RenderDeviceSnapshot,
createRenderDeviceSnapshot, presentationSnapshotKey, renderDeviceSnapshotPositions,
type RenderDeviceSnapshot,
} from './render-device-snapshot';
import { deviceFaceStyle, renderDeviceFace } from './device-face';
import {
@@ -3428,7 +3429,11 @@ class HouseplanCard extends LitElement {
const snapshot = createRenderDeviceSnapshot({
sourceSequence: this._hassSequence, hass: planHass,
devices: this._devices, presentations,
positions: new Map(this._devices.map((device) => [device.id, this._livePos(device)])),
positions: renderDeviceSnapshotPositions(
this._model.length > 0,
this._devices,
(device) => this._livePos(device),
),
facts,
entityIds,
deviceIds,
+17
View File
@@ -22,6 +22,23 @@ export interface RenderDeviceSnapshot {
readonly facts: ReadonlyMap<string, unknown>;
}
/**
* Resolve device positions only when a plan model exists to own them.
*
* A snapshot without a renderable plan still carries its immutable HA facts,
* but there is no geometry against which a position can be resolved. Keeping
* the map empty also preserves the stricter contract of the geometry helpers:
* they continue to require a real SpaceModel.
*/
export function renderDeviceSnapshotPositions(
hasRenderablePlan: boolean,
devices: readonly DevItem[],
resolve: (device: DevItem) => { x: number; y: number },
): ReadonlyMap<string, { x: number; y: number }> {
if (!hasRenderablePlan) return new Map();
return new Map(devices.map((device) => [device.id, resolve(device)]));
}
function cloneFact<T>(value: T, stack = new WeakMap<object, unknown>()): T {
if (value === null || typeof value !== 'object') return value;
const object = value as unknown as object;