Improve Home Assistant notifications

This commit is contained in:
seo
2026-06-21 07:46:28 +09:00
parent 49394a8ee5
commit 772010562a
6 changed files with 269 additions and 55 deletions
+36
View File
@@ -33,6 +33,7 @@
statusBatterySoc: $('#statusBatterySoc'),
statusBatteryRemaining: $('#statusBatteryRemaining'),
spikeLogList: $('#spikeLogList'),
haNotifyList: $('#haNotifyList'),
noticeBaseline: $('#noticeBaseline'),
rebootBtn: $('#rebootBtn'),
translateBtn: $('#translateBtn'),
@@ -137,6 +138,10 @@
systemNotice: 'System Notice',
noticeHistory: 'Notice History',
noNoticeHistory: 'No system notice history.',
haNotifyHistory: 'HA Notify History',
noHaNotifyHistory: 'No HA notify history.',
notifySuccess: 'success',
notifyFailed: 'failed',
show: 'Show',
hide: 'Hide',
translateButton: 'Translate',
@@ -255,6 +260,10 @@
systemNotice: '시스템 알림',
noticeHistory: '알림 이력',
noNoticeHistory: '시스템 알림 이력이 없습니다.',
haNotifyHistory: 'HA 알림 이력',
noHaNotifyHistory: 'HA 알림 이력이 없습니다.',
notifySuccess: '성공',
notifyFailed: '실패',
show: '보기',
hide: '숨기기',
translateButton: '번역',
@@ -997,6 +1006,32 @@
: `<div class="spike-log-empty">${escapeHtml(t('noNoticeHistory'))}</div>`;
}
function renderHaNotifyHistory(rows = []) {
if (!els.haNotifyList) return;
els.haNotifyList.innerHTML = rows.length
? rows.map((row, index) => {
const ok = row.event === 'send_success';
const statusText = ok ? t('notifySuccess') : t('notifyFailed');
const detail = [
row.target ? `${t('hostLabel')}: ${row.target}` : '',
row.http_code ? `HTTP ${row.http_code}` : '',
row.channel || '',
row.error || '',
].filter(Boolean).join(' / ');
return `
<div class="spike-log-item ${index === 0 ? 'latest' : ''} ${ok ? '' : 'alert'}">
<strong>${escapeHtml(row.created_at || '-')} · ${escapeHtml(statusText)}</strong>
<span>${escapeHtml(row.title || '-')}</span>
<span>${escapeHtml(row.tag || '-')}</span>
${detail ? `<span>${escapeHtml(detail)}</span>` : ''}
</div>
`;
}).join('')
: `<div class="spike-log-empty">${escapeHtml(t('noHaNotifyHistory'))}</div>`;
}
function renderFanCause(data) {
const processes = data.processes || {};
const baseline = data.fan_spike || {};
@@ -1007,6 +1042,7 @@
? `${baselineTemp.toFixed(1)}°C / ${Math.round(baselineRpm).toLocaleString()} RPM · ${stateText}`
: stateText;
renderSpikeHistory(data.fan_spike_history || []);
renderHaNotifyHistory(data.ha_notify_history || []);
setText(els.noticeBaseline, baselineText);
renderProcessRows(els.processCpuTable, processes.cpu || [], 'cpu');