mirror of
https://github.com/Matysh/houseplan-card
synced 2026-10-06 14:39:22 +00:00
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user