forked from HomeAssistant/xiaoshi-pad-card
Update xiaoshi-device-consumables-card.js
This commit is contained in:
@@ -502,7 +502,6 @@ class XiaoshiConsumablesCardEditor extends LitElement {
|
||||
} else {
|
||||
newEntities = [...currentEntities, {
|
||||
entity_id: entityId,
|
||||
attribute: null,
|
||||
overrides: undefined
|
||||
}];
|
||||
}
|
||||
@@ -544,11 +543,19 @@ class XiaoshiConsumablesCardEditor extends LitElement {
|
||||
const newEntities = [...currentEntities];
|
||||
|
||||
if (newEntities[index]) {
|
||||
const trimmedValue = attributeValue.trim();
|
||||
if (trimmedValue === '') {
|
||||
// 如果属性为空,则从配置中移除 attribute 字段
|
||||
const { attribute, ...entityWithoutAttribute } = newEntities[index];
|
||||
newEntities[index] = entityWithoutAttribute;
|
||||
} else {
|
||||
// 如果属性不为空,则设置属性值
|
||||
newEntities[index] = {
|
||||
...newEntities[index],
|
||||
attribute: attributeValue.trim() || null
|
||||
attribute: trimmedValue
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
this.config = {
|
||||
...this.config,
|
||||
|
||||
Reference in New Issue
Block a user