Update xiaoshi-device-balance-card.js

This commit is contained in:
xiaoshi
2025-11-26 14:21:37 +08:00
committed by GitHub
parent 2371475eca
commit f768186379

View File

@@ -466,11 +466,12 @@ class XiaoshiBalanceCardEditor extends LitElement {
newEntities = currentEntities.filter(e => e.entity_id !== entityId); newEntities = currentEntities.filter(e => e.entity_id !== entityId);
} else { } else {
// 添加实体 // 添加实体
newEntities = [...currentEntities, { const newEntity = {
entity_id: entityId, entity_id: entityId,
attribute: null,
overrides: undefined overrides: undefined
}]; };
// 只有在明确指定属性时才添加 attribute 字段
newEntities = [...currentEntities, newEntity];
} }
this.config = { this.config = {
@@ -510,10 +511,17 @@ class XiaoshiBalanceCardEditor extends LitElement {
const newEntities = [...currentEntities]; const newEntities = [...currentEntities];
if (newEntities[index]) { if (newEntities[index]) {
newEntities[index] = { const updatedEntity = { ...newEntities[index] };
...newEntities[index],
attribute: attributeValue.trim() || null if (attributeValue.trim()) {
}; // 只有当属性值不为空时才设置 attribute 字段
updatedEntity.attribute = attributeValue.trim();
} else {
// 如果属性值为空,则移除 attribute 字段
delete updatedEntity.attribute;
}
newEntities[index] = updatedEntity;
} }
this.config = { this.config = {