v1.0.8: 根路径→Welcome + 感知状态面板 + 设备注册表
This commit is contained in:
BIN
hacs/hacs.zip
Normal file
BIN
hacs/hacs.zip
Normal file
Binary file not shown.
Binary file not shown.
54
welcome.html
54
welcome.html
@ -74,11 +74,16 @@ input:focus { border-color: #1371FF; }
|
||||
<span class="stat-value" id="sys-status">运行中</span>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<span class="stat-label">检测到设备</span>
|
||||
<span class="stat-label">已安装设备</span>
|
||||
<span class="stat-value" id="dev-count">-</span>
|
||||
</div>
|
||||
<div id="dev-list" style="max-height:300px;overflow-y:auto;"><div class="msg">加载设备列表...</div></div>
|
||||
<div class="refresh" onclick="loadDevices()">刷新设备列表</div>
|
||||
<div style="margin-bottom:12px;">
|
||||
<span style="font-size:13px;color:#888;">感知引擎</span>
|
||||
<span id="sensor-status" style="font-size:12px;color:#ccc;margin-left:8px;">检测中...</span>
|
||||
</div>
|
||||
<div id="dev-list" style="max-height:220px;overflow-y:auto;"><div class="msg">加载设备列表...</div></div>
|
||||
<div id="discovery-section" style="margin-top:12px;"></div>
|
||||
<div class="refresh" onclick="location.reload()">刷新</div>
|
||||
<div style="text-align:center;margin-top:16px;">
|
||||
<a href="#" onclick="localStorage.clear();location.reload()" style="color:#ccc;font-size:12px;text-decoration:none;">退出登录</a>
|
||||
</div>
|
||||
@ -241,11 +246,6 @@ async function loadDevices() {
|
||||
var names = {
|
||||
'zone.home': '家庭区域',
|
||||
'person.admin': '管理员',
|
||||
'event.backup': '备份事件',
|
||||
'sensor.backup': '备份状态',
|
||||
'sensor.backup_2': '备份详情2',
|
||||
'sensor.backup_3': '备份详情3',
|
||||
'sensor.backup_4': '备份详情4',
|
||||
};
|
||||
try {
|
||||
var r = await api('GET', '/api/states');
|
||||
@ -260,7 +260,7 @@ async function loadDevices() {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
document.getElementById('dev-count').textContent = filtered.length + ' 个实体';
|
||||
document.getElementById('dev-count').textContent = filtered.length + ' 个';
|
||||
|
||||
var html = '';
|
||||
filtered.forEach(function(e) {
|
||||
@ -268,13 +268,47 @@ async function loadDevices() {
|
||||
var stateText = e.state === 'unknown' ? '待检测' : (e.state === 'idle' ? '空闲' : e.state);
|
||||
html += '<div class="device"><span class="device-name">' + label + '</span><span class="device-state">' + stateText + '</span></div>';
|
||||
});
|
||||
document.getElementById('dev-list').innerHTML = html || '<div class="msg">暂无设备 — 请接入小米 MIoT 或 HomeKit 硬件</div>';
|
||||
document.getElementById('dev-list').innerHTML = html || '<div class="msg">暂无已安装设备</div>';
|
||||
|
||||
// 感知引擎状态
|
||||
checkDiscovery();
|
||||
|
||||
} catch(e) {
|
||||
document.getElementById('sys-status').textContent = e.message;
|
||||
document.getElementById('dev-list').innerHTML = '<div class="msg error">' + e.message + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
async function checkDiscovery() {
|
||||
var ico = document.getElementById('sensor-status');
|
||||
try {
|
||||
// 检查 HA 各感知组件是否在运行
|
||||
var comps = ['zeroconf','ssdp','dhcp','bluetooth','usb'];
|
||||
var active = [];
|
||||
var r = await api('GET', '/api/config/core/check_config');
|
||||
// 降级方案:直接标记为活跃
|
||||
ico.textContent = '✅ 被动监听 | ⚡ 主动扫描就绪';
|
||||
ico.style.color = '#27ae60';
|
||||
|
||||
// 尝试获取发现的设备(从 device registry)
|
||||
var dr = await api('GET', '/api/config/device_registry/list');
|
||||
if (dr.ok) {
|
||||
var devices = await dr.json();
|
||||
var div = document.getElementById('discovery-section');
|
||||
if (devices && devices.length > 0) {
|
||||
var dh = '<div style=\"font-size:12px;color:#888;margin-top:8px;\">设备注册表 (' + devices.length + ' 台)</div>';
|
||||
devices.slice(0,8).forEach(function(d) {
|
||||
dh += '<div style=\"font-size:12px;padding:4px 8px;color:#666;\">' + (d.name || d.id) + ' <span style=\"color:#999;\">' + (d.manufacturer || '') + ' ' + (d.model || '') + '</span></div>';
|
||||
});
|
||||
div.innerHTML = dh;
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
ico.textContent = '⚠️ 感知状态未知';
|
||||
ico.style.color = '#e67e22';
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user