forked from HomeAssistant/xiaoshi-pad-card
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f768186379 | ||
|
|
2371475eca | ||
|
|
befca5ece5 | ||
|
|
24848db29b | ||
|
|
be232dc056 | ||
|
|
96fb548262 | ||
|
|
16831e5102 | ||
|
|
b05f7de548 | ||
|
|
d8d4389549 | ||
|
|
bca500c945 | ||
|
|
5f36835adb | ||
|
|
05d083c259 | ||
|
|
3738b0b092 | ||
|
|
87e9e68b79 | ||
|
|
7ddd378b9a | ||
|
|
23b6e5b8a3 | ||
|
|
4067518d0d | ||
|
|
53e06aacf7 | ||
|
|
9a59c2bb90 | ||
|
|
0ae5851361 | ||
|
|
a17033c0f0 | ||
|
|
44a1d81265 | ||
|
|
2de0668d37 | ||
|
|
a03a54663b | ||
|
|
6efa2864cc | ||
|
|
f4a37ff29c | ||
|
|
1c5717f5d5 | ||
|
|
15fcbf0250 | ||
|
|
de31cf6464 | ||
|
|
9f6a31f1df |
66
README.md
66
README.md
@@ -28,7 +28,7 @@ mode: 湿度 # 【温度】或者【湿度】
|
|||||||
**引用示例**
|
**引用示例**
|
||||||
~~~
|
~~~
|
||||||
type: custom:xiaoshi-update-card
|
type: custom:xiaoshi-update-card
|
||||||
width: 100p%
|
width: 100%
|
||||||
theme: on
|
theme: on
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
@@ -36,9 +36,71 @@ theme: on
|
|||||||
**引用示例**
|
**引用示例**
|
||||||
~~~
|
~~~
|
||||||
type: custom:xiaoshi-offline-card
|
type: custom:xiaoshi-offline-card
|
||||||
width: 320px
|
width: 100%
|
||||||
|
theme: on
|
||||||
exclude_devices:
|
exclude_devices:
|
||||||
- *设备*
|
- *设备*
|
||||||
exclude_entities:
|
exclude_entities:
|
||||||
- *shiti*
|
- *shiti*
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
|
## 功能4:电话信息余额卡(手机平板端通用)
|
||||||
|
**引用示例**
|
||||||
|
~~~
|
||||||
|
type: custom:xiaoshi-balance-card
|
||||||
|
name: 电话余额信息
|
||||||
|
width: 100%
|
||||||
|
theme: on
|
||||||
|
entities:
|
||||||
|
- entity_id: sensor.999
|
||||||
|
attribute: null
|
||||||
|
overrides:
|
||||||
|
icon: ""
|
||||||
|
name: ""
|
||||||
|
unit_of_measurement: ""
|
||||||
|
warning: ""
|
||||||
|
- entity_id: input_boolean.777
|
||||||
|
attribute: friendly_name
|
||||||
|
overrides:
|
||||||
|
name: ""
|
||||||
|
icon: ""
|
||||||
|
unit_of_measurement: ""
|
||||||
|
warning: "99"
|
||||||
|
~~~
|
||||||
|
|
||||||
|
## 功能5:待办事项卡(手机平板端通用)
|
||||||
|
**引用示例**
|
||||||
|
~~~
|
||||||
|
type: custom:xiaoshi-todo-card
|
||||||
|
width: 100%
|
||||||
|
theme: on
|
||||||
|
entities:
|
||||||
|
- todo.kuai_di
|
||||||
|
- todo.ji_shi_ben
|
||||||
|
~~~
|
||||||
|
|
||||||
|
## 功能6:耗材信息卡片(手机平板端通用)
|
||||||
|
**引用示例**
|
||||||
|
~~~
|
||||||
|
type: custom:xiaoshi-consumables-card
|
||||||
|
width: 100%
|
||||||
|
global_warning: <8
|
||||||
|
columns: "2"
|
||||||
|
entities:
|
||||||
|
- entity_id: input_text.aaa
|
||||||
|
overrides:
|
||||||
|
name: 奥斯卡德拉萨达实打实实打实
|
||||||
|
unit_of_measurement: "%"
|
||||||
|
warning: <10
|
||||||
|
conversion: "*2"
|
||||||
|
icon: ""
|
||||||
|
- entity_id: input_text.aaa1
|
||||||
|
- entity_id: input_text.aaa2
|
||||||
|
- entity_id: input_text.aaa3
|
||||||
|
- entity_id: input_text.aaa4
|
||||||
|
- entity_id: input_text.aaa5
|
||||||
|
- entity_id: input_text.aaa6
|
||||||
|
- entity_id: input_text.aaa7
|
||||||
|
~~~
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1121
xiaoshi-device-balance-card.js
Normal file
1121
xiaoshi-device-balance-card.js
Normal file
File diff suppressed because it is too large
Load Diff
1328
xiaoshi-device-consumables-card.js
Normal file
1328
xiaoshi-device-consumables-card.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -425,6 +425,12 @@ export class XiaoshiOfflineCard extends LitElement {
|
|||||||
|
|
||||||
const offlineDevices = [];
|
const offlineDevices = [];
|
||||||
|
|
||||||
|
// 获取设备排除模式
|
||||||
|
const excludeDevicePatterns = this.config.exclude_devices || [];
|
||||||
|
|
||||||
|
// 记录被排除的设备ID集合
|
||||||
|
const excludedDeviceIds = new Set();
|
||||||
|
|
||||||
// 并行检查所有设备
|
// 并行检查所有设备
|
||||||
const deviceChecks = devices.map(device => {
|
const deviceChecks = devices.map(device => {
|
||||||
const deviceEntities = entitiesByDevice[device.id] || [];
|
const deviceEntities = entitiesByDevice[device.id] || [];
|
||||||
@@ -434,12 +440,6 @@ export class XiaoshiOfflineCard extends LitElement {
|
|||||||
isOffline: this._checkDeviceAvailabilitySync(device, deviceEntities, entityMap)
|
isOffline: this._checkDeviceAvailabilitySync(device, deviceEntities, entityMap)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// 获取设备排除模式
|
|
||||||
const excludeDevicePatterns = this.config.exclude_devices || [];
|
|
||||||
|
|
||||||
// 记录被排除的设备ID集合
|
|
||||||
const excludedDeviceIds = new Set();
|
|
||||||
|
|
||||||
// 过滤离线设备并构建数据
|
// 过滤离线设备并构建数据
|
||||||
deviceChecks.forEach(({ device, deviceEntities, isOffline }) => {
|
deviceChecks.forEach(({ device, deviceEntities, isOffline }) => {
|
||||||
@@ -453,16 +453,25 @@ export class XiaoshiOfflineCard extends LitElement {
|
|||||||
return; // 跳过匹配排除模式的设备
|
return; // 跳过匹配排除模式的设备
|
||||||
}
|
}
|
||||||
|
|
||||||
offlineDevices.push({
|
// 再次确保设备有有效实体
|
||||||
device_id: device.id,
|
const validEntities = deviceEntities.filter(entityReg => {
|
||||||
name: deviceName,
|
const entity = entityMap[entityReg.entity_id];
|
||||||
model: device.model,
|
return entity && !entityReg.disabled_by;
|
||||||
manufacturer: device.manufacturer,
|
|
||||||
area_id: device.area_id,
|
|
||||||
entities: deviceEntities,
|
|
||||||
last_seen: this._getDeviceLastSeen(deviceEntities, entityMap),
|
|
||||||
icon: this._getDeviceIcon(device, deviceEntities)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 只有当设备有有效实体时才添加到离线设备列表
|
||||||
|
if (validEntities.length > 0) {
|
||||||
|
offlineDevices.push({
|
||||||
|
device_id: device.id,
|
||||||
|
name: deviceName,
|
||||||
|
model: device.model,
|
||||||
|
manufacturer: device.manufacturer,
|
||||||
|
area_id: device.area_id,
|
||||||
|
entities: validEntities, // 使用有效实体而不是所有实体
|
||||||
|
last_seen: this._getDeviceLastSeen(validEntities, entityMap),
|
||||||
|
icon: this._getDeviceIcon(device, validEntities)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -537,7 +546,7 @@ export class XiaoshiOfflineCard extends LitElement {
|
|||||||
|
|
||||||
_checkDeviceAvailabilitySync(device, deviceEntities, entityMap) {
|
_checkDeviceAvailabilitySync(device, deviceEntities, entityMap) {
|
||||||
if (!deviceEntities || deviceEntities.length === 0) {
|
if (!deviceEntities || deviceEntities.length === 0) {
|
||||||
return true; // 没有实体的设备视为离线
|
return false; // 没有实体的设备不视为离线,直接排除
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查设备的可用性状态
|
// 检查设备的可用性状态
|
||||||
@@ -545,16 +554,23 @@ export class XiaoshiOfflineCard extends LitElement {
|
|||||||
return false; // 被禁用的设备不算离线
|
return false; // 被禁用的设备不算离线
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 过滤出有效的实体(未被禁用且在entityMap中存在)
|
||||||
|
const validEntities = deviceEntities.filter(entityReg => {
|
||||||
|
const entity = entityMap[entityReg.entity_id];
|
||||||
|
return entity && !entityReg.disabled_by;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 如果没有有效实体,则不视为离线设备,直接排除
|
||||||
|
if (validEntities.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let hasAvailableEntity = false;
|
let hasAvailableEntity = false;
|
||||||
let hasUnavailableEntity = false;
|
let hasUnavailableEntity = false;
|
||||||
|
|
||||||
for (const entityReg of deviceEntities) {
|
for (const entityReg of validEntities) {
|
||||||
const entity = entityMap[entityReg.entity_id];
|
const entity = entityMap[entityReg.entity_id];
|
||||||
if (!entity) continue;
|
|
||||||
|
|
||||||
// 跳过被禁用的实体
|
|
||||||
if (entityReg.disabled_by) continue;
|
|
||||||
|
|
||||||
if (entity.state !== 'unavailable' ) {
|
if (entity.state !== 'unavailable' ) {
|
||||||
hasAvailableEntity = true;
|
hasAvailableEntity = true;
|
||||||
break; // 找到一个可用实体就可以停止检查
|
break; // 找到一个可用实体就可以停止检查
|
||||||
@@ -563,7 +579,7 @@ export class XiaoshiOfflineCard extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果设备有实体但所有实体都不可用,则设备离线
|
// 如果设备有有效实体但所有实体都不可用,则设备离线
|
||||||
return hasUnavailableEntity && !hasAvailableEntity;
|
return hasUnavailableEntity && !hasAvailableEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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
@@ -68,6 +68,19 @@ class XiaoshiUpdateCardEditor extends LitElement {
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
@change=${this._entityChanged}
|
||||||
|
.checked=${this.config.skip_updates !== false}
|
||||||
|
name="skip_updates"
|
||||||
|
/>
|
||||||
|
包含已跳过的更新
|
||||||
|
</label>
|
||||||
|
<div class="help-text">如果勾选,将包含标记为跳过的版本更新</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -75,10 +88,17 @@ class XiaoshiUpdateCardEditor extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_entityChanged(e) {
|
_entityChanged(e) {
|
||||||
const { name, value } = e.target;
|
const { name, value, type, checked } = e.target;
|
||||||
if (!value && name !== 'theme' && name !== 'width') return;
|
|
||||||
|
|
||||||
let finalValue = value;
|
let finalValue;
|
||||||
|
|
||||||
|
// 处理复选框
|
||||||
|
if (type === 'checkbox') {
|
||||||
|
finalValue = checked;
|
||||||
|
} else {
|
||||||
|
if (!value && name !== 'theme' && name !== 'width') return;
|
||||||
|
finalValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
// 处理不同字段的默认值
|
// 处理不同字段的默认值
|
||||||
if (name === 'width') {
|
if (name === 'width') {
|
||||||
@@ -459,19 +479,10 @@ export class XiaoshiUpdateCard extends LitElement {
|
|||||||
const haUpdates = [];
|
const haUpdates = [];
|
||||||
const otherUpdates = [];
|
const otherUpdates = [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 获取update.开头的实体更新信息
|
// 获取update.开头的实体更新信息
|
||||||
try {
|
try {
|
||||||
const entities = Object.values(this.hass.states);
|
const entities = Object.values(this.hass.states);
|
||||||
|
const skipUpdates = this.config.skip_updates !== false; // 默认为true
|
||||||
|
|
||||||
entities.forEach(entity => {
|
entities.forEach(entity => {
|
||||||
// 筛选以update.开头的实体
|
// 筛选以update.开头的实体
|
||||||
@@ -484,6 +495,15 @@ export class XiaoshiUpdateCard extends LitElement {
|
|||||||
attributes.installed_version &&
|
attributes.installed_version &&
|
||||||
attributes.latest_version !== attributes.installed_version) {
|
attributes.latest_version !== attributes.installed_version) {
|
||||||
|
|
||||||
|
// 如果不跳过更新,检查skipped_version属性
|
||||||
|
if (!skipUpdates) {
|
||||||
|
const skippedVersion = attributes.skipped_version;
|
||||||
|
// 如果skipped_version不为null且等于latest_version,则跳过此更新
|
||||||
|
if (skippedVersion !== null && skippedVersion === attributes.latest_version) {
|
||||||
|
return; // 跳过此更新
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const updateData = {
|
const updateData = {
|
||||||
name: attributes.friendly_name || entity.entity_id.replace('update.', ''),
|
name: attributes.friendly_name || entity.entity_id.replace('update.', ''),
|
||||||
current_version: attributes.installed_version,
|
current_version: attributes.installed_version,
|
||||||
@@ -493,7 +513,8 @@ export class XiaoshiUpdateCard extends LitElement {
|
|||||||
entity_id: entity.entity_id,
|
entity_id: entity.entity_id,
|
||||||
title: attributes.title || '',
|
title: attributes.title || '',
|
||||||
release_url: attributes.release_url || '',
|
release_url: attributes.release_url || '',
|
||||||
entity_picture: attributes.entity_picture || ''
|
entity_picture: attributes.entity_picture || '',
|
||||||
|
skipped_version: attributes.skipped_version || null
|
||||||
};
|
};
|
||||||
|
|
||||||
// 检查是否为home_assistant开头的实体
|
// 检查是否为home_assistant开头的实体
|
||||||
@@ -765,9 +786,6 @@ export class XiaoshiUpdateCard extends LitElement {
|
|||||||
return html`${backupElements}`;
|
return html`${backupElements}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
return html`<div class="loading">等待Home Assistant连接...</div>`;
|
return html`<div class="loading">等待Home Assistant连接...</div>`;
|
||||||
@@ -837,6 +855,7 @@ export class XiaoshiUpdateCard extends LitElement {
|
|||||||
<div class="device-name">${update.name}</div>
|
<div class="device-name">${update.name}</div>
|
||||||
<div class="device-details">
|
<div class="device-details">
|
||||||
当前版本: ${update.current_version} → 最新版本: ${update.latest_version}
|
当前版本: ${update.current_version} → 最新版本: ${update.latest_version}
|
||||||
|
${update.skipped_version ? html`<br><span style="color: #ff9800;">已跳过版本: ${update.skipped_version}</span>` : ''}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="device-last-seen" @click=${(e) => this._handleConfirmUpdate(update, e)}>
|
<div class="device-last-seen" @click=${(e) => this._handleConfirmUpdate(update, e)}>
|
||||||
@@ -861,6 +880,7 @@ export class XiaoshiUpdateCard extends LitElement {
|
|||||||
<div class="device-name">${update.name}</div>
|
<div class="device-name">${update.name}</div>
|
||||||
<div class="device-details">
|
<div class="device-details">
|
||||||
当前版本: ${update.current_version} → 最新版本: ${update.latest_version}
|
当前版本: ${update.current_version} → 最新版本: ${update.latest_version}
|
||||||
|
${update.skipped_version ? html`<br><span style="color: #ff9800;">已跳过版本: ${update.skipped_version}</span>` : ''}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="device-last-seen" @click=${(e) => this._handleConfirmUpdate(update, e)}>
|
<div class="device-last-seen" @click=${(e) => this._handleConfirmUpdate(update, e)}>
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
console.info("%c 消逝卡-平板端 \n%c v 0.0.3 ", "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 () => {
|
const loadCards = async () => {
|
||||||
await import('./xiaoshi-pad-grid-card.js');
|
await import('./xiaoshi-pad-grid-card.js');
|
||||||
await import('./xiaoshi-device-update-card.js');
|
await import('./xiaoshi-device-update-card.js');
|
||||||
await import('./xiaoshi-device-offline-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 = window.customCards || [];
|
||||||
window.customCards.push(...cardConfigs);
|
window.customCards.push(...cardConfigs);
|
||||||
@@ -26,6 +29,24 @@ const cardConfigs = [
|
|||||||
name: '消逝卡HA离线设备卡片',
|
name: '消逝卡HA离线设备卡片',
|
||||||
description: '显示所有离线的设备和实体',
|
description: '显示所有离线的设备和实体',
|
||||||
preview: true
|
preview: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'xiaoshi-balance-card',
|
||||||
|
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