mirror of
https://github.com/xiaoshi930/xiaoshi-pad-card.git
synced 2025-11-28 16:49:42 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f36835adb | ||
|
|
05d083c259 | ||
|
|
3738b0b092 | ||
|
|
87e9e68b79 | ||
|
|
7ddd378b9a | ||
|
|
23b6e5b8a3 | ||
|
|
4067518d0d | ||
|
|
53e06aacf7 | ||
|
|
9a59c2bb90 | ||
|
|
0ae5851361 | ||
|
|
a17033c0f0 | ||
|
|
44a1d81265 | ||
|
|
2de0668d37 |
19
README.md
19
README.md
@@ -28,7 +28,7 @@ mode: 湿度 # 【温度】或者【湿度】
|
||||
**引用示例**
|
||||
~~~
|
||||
type: custom:xiaoshi-update-card
|
||||
width: 100p%
|
||||
width: 100%
|
||||
theme: on
|
||||
~~~
|
||||
|
||||
@@ -36,7 +36,8 @@ theme: on
|
||||
**引用示例**
|
||||
~~~
|
||||
type: custom:xiaoshi-offline-card
|
||||
width: 320px
|
||||
width: 100%
|
||||
theme: on
|
||||
exclude_devices:
|
||||
- *设备*
|
||||
exclude_entities:
|
||||
@@ -48,7 +49,8 @@ exclude_entities:
|
||||
~~~
|
||||
type: custom:xiaoshi-balance-card
|
||||
name: 电话余额信息
|
||||
width: 350px
|
||||
width: 100%
|
||||
theme: on
|
||||
entities:
|
||||
- entity_id: sensor.999
|
||||
attribute: null
|
||||
@@ -65,3 +67,14 @@ entities:
|
||||
unit_of_measurement: ""
|
||||
warning: "99"
|
||||
~~~
|
||||
|
||||
## 功能5:待办事项卡(手机平板端通用)
|
||||
**引用示例**
|
||||
~~~
|
||||
type: custom:xiaoshi-todo-card
|
||||
width: 100%
|
||||
theme: on
|
||||
entities:
|
||||
- todo.kuai_di
|
||||
- todo.ji_shi_ben
|
||||
~~~
|
||||
|
||||
@@ -236,7 +236,20 @@ class XiaoshiBalanceCardEditor extends LitElement {
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label>全局预警条件:当任一实体满足此条件时触发预警</label>
|
||||
<input
|
||||
type="text"
|
||||
@change=${this._entityChanged}
|
||||
.value=${this.config.global_warning || ''}
|
||||
name="global_warning"
|
||||
placeholder="如: >10, <=5, ==on, ==off, =='hello world'"
|
||||
/>
|
||||
<div class="help-text">
|
||||
全局预警条件:当任一实体满足此条件时,该实体显示为红色预警状态<br>
|
||||
优先级:明细预警 > 全局预警 > 无预警
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>主题</label>
|
||||
@@ -308,24 +321,6 @@ class XiaoshiBalanceCardEditor extends LitElement {
|
||||
class="attribute-input"
|
||||
/>
|
||||
|
||||
<div class="override-config">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="override-checkbox"
|
||||
@change=${(e) => this._updateEntityOverride(index, 'name', e.target.checked)}
|
||||
.checked=${entityConfig.overrides?.name !== undefined}
|
||||
/>
|
||||
<span class="override-label">名称:</span>
|
||||
<input
|
||||
type="text"
|
||||
class="override-input"
|
||||
@change=${(e) => this._updateEntityOverrideValue(index, 'name', e.target.value)}
|
||||
.value=${entityConfig.overrides?.name || ''}
|
||||
placeholder="自定义名称"
|
||||
?disabled=${entityConfig.overrides?.name === undefined}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="override-config">
|
||||
<input
|
||||
type="checkbox"
|
||||
@@ -343,7 +338,25 @@ class XiaoshiBalanceCardEditor extends LitElement {
|
||||
?disabled=${entityConfig.overrides?.icon === undefined}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="override-config">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="override-checkbox"
|
||||
@change=${(e) => this._updateEntityOverride(index, 'name', e.target.checked)}
|
||||
.checked=${entityConfig.overrides?.name !== undefined}
|
||||
/>
|
||||
<span class="override-label">名称:</span>
|
||||
<input
|
||||
type="text"
|
||||
class="override-input"
|
||||
@change=${(e) => this._updateEntityOverrideValue(index, 'name', e.target.value)}
|
||||
.value=${entityConfig.overrides?.name || ''}
|
||||
placeholder="自定义名称"
|
||||
?disabled=${entityConfig.overrides?.name === undefined}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="override-config">
|
||||
<input
|
||||
type="checkbox"
|
||||
@@ -371,13 +384,11 @@ class XiaoshiBalanceCardEditor extends LitElement {
|
||||
/>
|
||||
<span class="override-label">预警:</span>
|
||||
<input
|
||||
type="number"
|
||||
type="text"
|
||||
class="override-input"
|
||||
@change=${(e) => this._updateEntityOverrideValue(index, 'warning', e.target.value)}
|
||||
.value=${entityConfig.overrides?.warning || ''}
|
||||
placeholder="预警值"
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder="如: >10, <=5, ==on, ==off, =='hello world'"
|
||||
?disabled=${entityConfig.overrides?.warning === undefined}
|
||||
/>
|
||||
</div>
|
||||
@@ -393,7 +404,7 @@ class XiaoshiBalanceCardEditor extends LitElement {
|
||||
• 名称重定义:勾选后可自定义显示名称<br>
|
||||
• 图标重定义:勾选后可自定义图标(如 mdi:phone)<br>
|
||||
• 单位重定义:勾选后可自定义单位(如 元、$、kWh 等)<br>
|
||||
• 预警值:勾选后设置预警值,低于此值显示红色<br>
|
||||
• 预警条件:勾选后设置预警条件,支持 >10, >=10, <10, <=10, ==10, ==on, ==off, =="hello world" 等<br>
|
||||
• 未勾选重定义时,将使用实体的原始属性值
|
||||
</div>
|
||||
</div>
|
||||
@@ -783,7 +794,7 @@ class XiaoshiBalanceCard extends LitElement {
|
||||
}
|
||||
|
||||
.device-icon {
|
||||
margin-left: 12px;
|
||||
margin-right: 12px;
|
||||
color: var(--fg-color, #000);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
@@ -910,6 +921,9 @@ class XiaoshiBalanceCard extends LitElement {
|
||||
// 尝试从属性中获取单位
|
||||
if (attributes.unit_of_measurement) {
|
||||
unit = attributes.unit_of_measurement;
|
||||
} else {
|
||||
// 如果实体没有单位,则不显示单位
|
||||
unit = '';
|
||||
}
|
||||
|
||||
// 应用属性重定义
|
||||
@@ -929,7 +943,7 @@ class XiaoshiBalanceCard extends LitElement {
|
||||
unit = entityConfig.overrides.unit_of_measurement;
|
||||
}
|
||||
if (entityConfig.overrides.warning !== undefined && entityConfig.overrides.warning !== '') {
|
||||
warningThreshold = parseFloat(entityConfig.overrides.warning);
|
||||
warningThreshold = entityConfig.overrides.warning; // 保持原始字符串
|
||||
}
|
||||
}
|
||||
|
||||
@@ -967,6 +981,54 @@ class XiaoshiBalanceCard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
_evaluateWarningCondition(value, condition) {
|
||||
if (!condition) return false;
|
||||
|
||||
// 解析条件字符串,支持操作符后可能有空格
|
||||
const match = condition.match(/^(>=|<=|>|<|==|!=)\s*(.+)$/);
|
||||
if (!match) return false;
|
||||
|
||||
const operator = match[1];
|
||||
let compareValue = match[2].trim();
|
||||
|
||||
// 移除比较值两端的引号(如果有的话)
|
||||
if ((compareValue.startsWith('"') && compareValue.endsWith('"')) ||
|
||||
(compareValue.startsWith("'") && compareValue.endsWith("'"))) {
|
||||
compareValue = compareValue.slice(1, -1);
|
||||
}
|
||||
|
||||
// 尝试将值转换为数字
|
||||
const numericValue = parseFloat(value);
|
||||
const numericCompare = parseFloat(compareValue);
|
||||
|
||||
// 如果两个值都是数字,进行数值比较
|
||||
if (!isNaN(numericValue) && !isNaN(numericCompare)) {
|
||||
switch (operator) {
|
||||
case '>': return numericValue > numericCompare;
|
||||
case '>=': return numericValue >= numericCompare;
|
||||
case '<': return numericValue < numericCompare;
|
||||
case '<=': return numericValue <= numericCompare;
|
||||
case '==': return numericValue === numericCompare;
|
||||
case '!=': return numericValue !== numericCompare;
|
||||
}
|
||||
}
|
||||
|
||||
// 字符串比较(用于 ==on, ==off, ==66 66 等)
|
||||
const stringValue = String(value);
|
||||
const stringCompare = compareValue;
|
||||
|
||||
switch (operator) {
|
||||
case '==': return stringValue === stringCompare;
|
||||
case '!=': return stringValue !== stringCompare;
|
||||
case '>': return stringValue > stringCompare;
|
||||
case '>=': return stringValue >= stringCompare;
|
||||
case '<': return stringValue < stringCompare;
|
||||
case '<=': return stringValue <= stringCompare;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
if (!this.hass) {
|
||||
@@ -994,16 +1056,26 @@ class XiaoshiBalanceCard extends LitElement {
|
||||
html`<div class="no-devices">请配置余额实体</div>` :
|
||||
html`
|
||||
${this._oilPriceData.map(balanceData => {
|
||||
const numericValue = parseFloat(balanceData.value);
|
||||
const isWarning = balanceData.warning_threshold !== undefined &&
|
||||
!isNaN(numericValue) &&
|
||||
numericValue < balanceData.warning_threshold;
|
||||
// 明细预警优先级最高
|
||||
let isWarning = false;
|
||||
|
||||
// 首先检查明细预警,如果存在且满足条件,直接设为预警状态
|
||||
if (balanceData.warning_threshold && balanceData.warning_threshold.trim() !== '') {
|
||||
isWarning = this._evaluateWarningCondition(balanceData.value, balanceData.warning_threshold);
|
||||
console.log(`明细预警 - 实体: ${balanceData.friendly_name}, 值: "${balanceData.value}", 条件: "${balanceData.warning_threshold}", 预警: ${isWarning}`);
|
||||
} else {
|
||||
// 只有在没有明细预警时才检查全局预警
|
||||
if (this.config.global_warning && this.config.global_warning.trim() !== '') {
|
||||
isWarning = this._evaluateWarningCondition(balanceData.value, this.config.global_warning);
|
||||
console.log(`全局预警 - 实体: ${balanceData.friendly_name}, 值: "${balanceData.value}", 条件: "${this.config.global_warning}", 预警: ${isWarning}`);
|
||||
}
|
||||
}
|
||||
|
||||
return html`
|
||||
<div class="device-item" @click=${() => this._handleEntityClick(balanceData)}>
|
||||
<div class="device-left">
|
||||
<div class="device-name">${balanceData.friendly_name}</div>
|
||||
<ha-icon class="device-icon" icon="${balanceData.icon}"></ha-icon>
|
||||
<div class="device-name">${balanceData.friendly_name}</div>
|
||||
</div>
|
||||
<div class="device-value ${isWarning ? 'warning' : ''}">
|
||||
${balanceData.value}
|
||||
|
||||
1204
xiaoshi-device-consumables-card.js
Normal file
1204
xiaoshi-device-consumables-card.js
Normal file
File diff suppressed because it is too large
Load Diff
1286
xiaoshi-device-todo-card.js
Normal file
1286
xiaoshi-device-todo-card.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,12 @@
|
||||
console.info("%c 消逝卡-平板端 \n%c v 0.0.6 ", "color: red; font-weight: bold; background: black", "color: white; font-weight: bold; background: black");
|
||||
console.info("%c 消逝卡-平板端 \n%c v 0.0.9 ", "color: red; font-weight: bold; background: black", "color: white; font-weight: bold; background: black");
|
||||
|
||||
const loadCards = async () => {
|
||||
await import('./xiaoshi-pad-grid-card.js');
|
||||
await import('./xiaoshi-device-update-card.js');
|
||||
await import('./xiaoshi-device-offline-card.js');
|
||||
await import('./xiaoshi-device-balance-card.js');
|
||||
await import('./xiaoshi-device-todo-card.js');
|
||||
await import('./xiaoshi-device-consumables-card.js');
|
||||
|
||||
window.customCards = window.customCards || [];
|
||||
window.customCards.push(...cardConfigs);
|
||||
@@ -33,6 +35,18 @@ const cardConfigs = [
|
||||
name: '消逝电话余额卡',
|
||||
description: '消逝电话余额卡',
|
||||
preview: true
|
||||
},
|
||||
{
|
||||
type: 'xiaoshi-todo-card',
|
||||
name: '消逝待办事项',
|
||||
description: '消逝待办事项',
|
||||
preview: true
|
||||
},
|
||||
{
|
||||
type: 'xiaoshi-consumables-card',
|
||||
name: '消逝耗材统计',
|
||||
description: '消逝耗材统计',
|
||||
preview: true
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user