From f768186379c5bee0137791b0f1325e51accae584 Mon Sep 17 00:00:00 2001 From: xiaoshi <115949669+xiaoshi930@users.noreply.github.com> Date: Wed, 26 Nov 2025 14:21:37 +0800 Subject: [PATCH] Update xiaoshi-device-balance-card.js --- xiaoshi-device-balance-card.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/xiaoshi-device-balance-card.js b/xiaoshi-device-balance-card.js index ac5d5b9..40b4be9 100644 --- a/xiaoshi-device-balance-card.js +++ b/xiaoshi-device-balance-card.js @@ -466,11 +466,12 @@ class XiaoshiBalanceCardEditor extends LitElement { newEntities = currentEntities.filter(e => e.entity_id !== entityId); } else { // 添加实体 - newEntities = [...currentEntities, { - entity_id: entityId, - attribute: null, + const newEntity = { + entity_id: entityId, overrides: undefined - }]; + }; + // 只有在明确指定属性时才添加 attribute 字段 + newEntities = [...currentEntities, newEntity]; } this.config = { @@ -510,10 +511,17 @@ class XiaoshiBalanceCardEditor extends LitElement { const newEntities = [...currentEntities]; if (newEntities[index]) { - newEntities[index] = { - ...newEntities[index], - attribute: attributeValue.trim() || null - }; + const updatedEntity = { ...newEntities[index] }; + + if (attributeValue.trim()) { + // 只有当属性值不为空时才设置 attribute 字段 + updatedEntity.attribute = attributeValue.trim(); + } else { + // 如果属性值为空,则移除 attribute 字段 + delete updatedEntity.attribute; + } + + newEntities[index] = updatedEntity; } this.config = {