forked from HomeAssistant/xiaoshi-pad-card
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f768186379 | ||
|
|
2371475eca | ||
|
|
befca5ece5 | ||
|
|
24848db29b |
@@ -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 = {
|
||||
|
||||
@@ -436,11 +436,13 @@ class XiaoshiConsumablesCardEditor extends LitElement {
|
||||
</div>
|
||||
<div class="help-text">
|
||||
搜索并选择要显示的设备耗材实体,支持多选。每个实体可以配置:<br>
|
||||
• <strong>特殊实体显示:</strong>binary_sensor(off→正常,on→缺少), event(unknown→正常,其他→低电量)<br>
|
||||
• 属性名:留空使用实体状态,或输入属性名<br>
|
||||
• 名称重定义:勾选后可自定义显示名称<br>
|
||||
• 图标重定义:勾选后可自定义图标(如 mdi:phone)<br>
|
||||
• 单位重定义:勾选后可自定义单位(如 元、$、kWh 等)<br>
|
||||
• 预警条件:勾选后设置预警条件,支持 >10, >=10, <10, <=10, ==10, ==on, ==off, =="hello world" 等<br>
|
||||
• 换算:对数值进行数学运算,支持 +10, -10, *1.5, /2 等<br>
|
||||
• 未勾选重定义时,将使用实体的原始属性值
|
||||
</div>
|
||||
</div>
|
||||
@@ -500,7 +502,6 @@ class XiaoshiConsumablesCardEditor extends LitElement {
|
||||
} else {
|
||||
newEntities = [...currentEntities, {
|
||||
entity_id: entityId,
|
||||
attribute: null,
|
||||
overrides: undefined
|
||||
}];
|
||||
}
|
||||
@@ -542,10 +543,18 @@ class XiaoshiConsumablesCardEditor extends LitElement {
|
||||
const newEntities = [...currentEntities];
|
||||
|
||||
if (newEntities[index]) {
|
||||
newEntities[index] = {
|
||||
...newEntities[index],
|
||||
attribute: attributeValue.trim() || null
|
||||
};
|
||||
const trimmedValue = attributeValue.trim();
|
||||
if (trimmedValue === '') {
|
||||
// 如果属性为空,则从配置中移除 attribute 字段
|
||||
const { attribute, ...entityWithoutAttribute } = newEntities[index];
|
||||
newEntities[index] = entityWithoutAttribute;
|
||||
} else {
|
||||
// 如果属性不为空,则设置属性值
|
||||
newEntities[index] = {
|
||||
...newEntities[index],
|
||||
attribute: trimmedValue
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
this.config = {
|
||||
@@ -1021,6 +1030,26 @@ class XiaoshiConsumablesCard extends LitElement {
|
||||
value = attributes[attributeName];
|
||||
}
|
||||
|
||||
// 特殊实体类型的数值显示逻辑
|
||||
if (!attributeName) {
|
||||
// binary_sensor 实体:off显示正常,on显示缺少
|
||||
if (entityId.startsWith('binary_sensor.')) {
|
||||
if (value === 'off') {
|
||||
value = '正常';
|
||||
} else if (value === 'on') {
|
||||
value = '缺少';
|
||||
}
|
||||
}
|
||||
// event 实体:unknown显示正常,非unknown或不可用时显示低电量
|
||||
else if (entityId.startsWith('event.')) {
|
||||
if (value === 'unknown') {
|
||||
value = '正常';
|
||||
} else if (value !== 'unknown' && value !== 'unavailable') {
|
||||
value = '低电量';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试从属性中获取单位
|
||||
if (attributes.unit_of_measurement) {
|
||||
unit = attributes.unit_of_measurement;
|
||||
@@ -1054,10 +1083,11 @@ class XiaoshiConsumablesCard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
// 应用换算
|
||||
// 应用换算(只对数值进行换算,不对文本状态进行换算)
|
||||
let originalValue = value;
|
||||
if (conversion) {
|
||||
if (conversion && !isNaN(parseFloat(value))) {
|
||||
value = this._applyConversion(value, conversion);
|
||||
} else if (conversion && isNaN(parseFloat(value))) {
|
||||
}
|
||||
|
||||
consumablesData.push({
|
||||
@@ -1099,11 +1129,21 @@ class XiaoshiConsumablesCard extends LitElement {
|
||||
_renderDeviceItem(consumablesData) {
|
||||
let isWarning = false;
|
||||
|
||||
if (consumablesData.warning_threshold && consumablesData.warning_threshold.trim() !== '') {
|
||||
isWarning = this._evaluateWarningCondition(consumablesData.value, consumablesData.warning_threshold);
|
||||
// 特殊实体类型的默认预警逻辑
|
||||
if (consumablesData.entity_id.startsWith('binary_sensor.') && !consumablesData.warning_threshold) {
|
||||
// binary_sensor: "缺少"状态时预警
|
||||
isWarning = consumablesData.value === '缺少';
|
||||
} else if (consumablesData.entity_id.startsWith('event.') && !consumablesData.warning_threshold) {
|
||||
// event: "低电量"状态时预警
|
||||
isWarning = consumablesData.value === '低电量';
|
||||
} else {
|
||||
if (this.config.global_warning && this.config.global_warning.trim() !== '') {
|
||||
isWarning = this._evaluateWarningCondition(consumablesData.value, this.config.global_warning);
|
||||
// 使用配置的预警条件
|
||||
if (consumablesData.warning_threshold && consumablesData.warning_threshold.trim() !== '') {
|
||||
isWarning = this._evaluateWarningCondition(consumablesData.value, consumablesData.warning_threshold);
|
||||
} else {
|
||||
if (this.config.global_warning && this.config.global_warning.trim() !== '') {
|
||||
isWarning = this._evaluateWarningCondition(consumablesData.value, this.config.global_warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
console.info("%c 消逝卡-平板端 \n%c v 0.1.1 ", "color: red; font-weight: bold; background: black", "color: white; font-weight: bold; background: black");
|
||||
console.info("%c 消逝卡-平板端 \n%c v 0.1.2 ", "color: red; font-weight: bold; background: black", "color: white; font-weight: bold; background: black");
|
||||
|
||||
const loadCards = async () => {
|
||||
await import('./xiaoshi-pad-grid-card.js');
|
||||
|
||||
Reference in New Issue
Block a user