HA 푸시 알림 경로를 정리

This commit is contained in:
seo
2026-06-29 06:02:30 +09:00
parent cd14bb2e5e
commit c5ab60a6e6
7 changed files with 12 additions and 652 deletions
-76
View File
@@ -2464,69 +2464,6 @@ function notice_downward_only(float $tempDelta, float $rpmDelta): bool
return true;
}
function send_fan_spike_notify(array $spike, array $fan, array $system, array $processes): array
{
$tempDelta = (float)($spike['temp_delta'] ?? 0);
$rpmDelta = (float)($spike['rpm_delta'] ?? 0);
$tempAvg = (float)($spike['temp_avg'] ?? 0);
$rpmAvg = (float)($spike['rpm_avg'] ?? 0);
$pwmAvg = (float)($spike['pwm_avg'] ?? 0);
$reasons = [];
if (abs($tempDelta) >= (float)setting_value('notice.temp_delta_threshold')) {
$reasons[] = '온도 평균보다 ' . ($tempDelta >= 0 ? '상승' : '하강');
}
if (abs($rpmDelta) >= (float)setting_value('notice.rpm_delta_threshold')) {
$reasons[] = '팬RPM 평균보다 ' . ($rpmDelta >= 0 ? '상승' : '하강');
}
if ($reasons === []) {
$reasons[] = '순간 변화';
}
$body = '기록된 이유: '
. implode(', ', $reasons)
. "\n평균: "
. number_format($tempAvg, 1)
. '°C / '
. number_format($rpmAvg, 0)
. ' RPM / PWM '
. number_format($pwmAvg, 0)
. "\n현재: "
. number_format((float)($system['temp_c'] ?? 0), 1)
. '°C / '
. number_format((float)($fan['rpm'] ?? 0), 0)
. ' RPM / PWM '
. number_format((float)($fan['pwm'] ?? 0), 0)
. (((bool)setting_value('notice.downward_only_process_hide') && notice_downward_only($tempDelta, $rpmDelta)) ? '' : "\n원인 후보: " . expected_process_detail_text($processes));
return send_ha_notify([
'title' => '시스템 유의사항',
'message' => $body,
'level' => 'warning',
'url' => '/',
'tag' => 'control-system-notice',
'data' => [
'channel' => 'control_system',
'notification_icon' => 'mdi:fan-alert',
'color' => '#f59e0b',
'sticky' => 'false',
'renotify' => 'true',
'summary' => $spike['summary'] ?? '',
'rpm_delta' => $spike['rpm_delta'] ?? 0,
'pwm_delta' => $spike['pwm_delta'] ?? 0,
'temp_delta' => $spike['temp_delta'] ?? 0,
'expected_process' => expected_process_text($processes),
],
]);
}
function latest_system_notice_notify_epoch(): int
{
return latest_ha_notify_epoch_by_tag('control-system-notice');
}
function fan_spike_history(int $limit = 100): array
{
$limit = max(1, min(500, $limit));
@@ -3347,21 +3284,9 @@ function collect_snapshot(bool $applyFan = true): array
$shouldLogNotice = !empty($fanSpike['alert_started'])
|| (!empty($fanSpike['active']) && (bool)setting_value('notice.log_during_alert'));
if ($shouldLogNotice) {
$latestNoticeNotify = latest_system_notice_notify_epoch();
$spikeLogId = add_fan_spike_log($fanSpike, $fan, $system, $processes);
if ($spikeLogId > 0) {
$fanSpike['log_id'] = $spikeLogId;
$noticeCooldown = (int)setting_value('notify.system_notice_cooldown_seconds');
if ($latestNoticeNotify <= 0 || time() - $latestNoticeNotify >= $noticeCooldown) {
$fanSpike['notify'] = send_fan_spike_notify($fanSpike, $fan, $system, $processes);
} else {
$fanSpike['notify'] = [
'sent' => 0,
'failed' => 0,
'skipped' => 'system_notice_cooldown',
'cooldown_seconds' => $noticeCooldown,
];
}
}
}
@@ -3380,7 +3305,6 @@ function collect_snapshot(bool $applyFan = true): array
'custom_services' => custom_systemd_services(),
'fan_spike' => $fanSpike,
'fan_spike_history' => fan_spike_history((int)setting_value('display.fan_notice_history_limit')),
'ha_notify_history' => ha_notify_log_rows((int)setting_value('display.ha_notify_history_limit')),
'settings' => settings_payload(),
];
-36
View File
@@ -35,7 +35,6 @@
statusBatteryRemaining: $('#statusBatteryRemaining'),
batteryRuntimeTooltip: $('#batteryRuntimeTooltip'),
spikeLogList: $('#spikeLogList'),
haNotifyList: $('#haNotifyList'),
customServiceList: $('#customServiceList'),
noticeBaseline: $('#noticeBaseline'),
rebootBtn: $('#rebootBtn'),
@@ -173,8 +172,6 @@
diagnostics: 'Diagnostics',
noticeHistory: 'Notice History',
noNoticeHistory: 'No system notice history.',
haNotifyHistory: 'HA Notify History',
noHaNotifyHistory: 'No HA notify history.',
customServices: 'Custom Services',
noCustomServices: 'No custom services.',
serviceLogs: 'Logs',
@@ -184,8 +181,6 @@
wifiAliasTitle: 'WiFi Hostname',
wifiAliasPrompt: 'Enter a name to keep for this MAC address.',
wifiAliasSaved: 'WiFi hostname saved.',
notifySuccess: 'success',
notifyFailed: 'failed',
show: 'Show',
hide: 'Hide',
translateButton: 'Translate',
@@ -324,8 +319,6 @@
diagnostics: '진단',
noticeHistory: '알림 이력',
noNoticeHistory: '시스템 알림 이력이 없습니다.',
haNotifyHistory: 'HA 알림 이력',
noHaNotifyHistory: 'HA 알림 이력이 없습니다.',
customServices: '사용자 서비스',
noCustomServices: '사용자 생성 서비스가 없습니다.',
serviceLogs: '로그',
@@ -335,8 +328,6 @@
wifiAliasTitle: 'WiFi 호스트명',
wifiAliasPrompt: '이 MAC 주소에 계속 표시할 이름을 입력하세요.',
wifiAliasSaved: 'WiFi 호스트명을 저장했습니다.',
notifySuccess: '성공',
notifyFailed: '실패',
show: '보기',
hide: '숨기기',
translateButton: '번역',
@@ -1624,32 +1615,6 @@
: `<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 renderCustomServices(rows = []) {
if (!els.customServiceList) return;
@@ -1696,7 +1661,6 @@
? `${baselineTemp.toFixed(1)}°C / ${Math.round(baselineRpm).toLocaleString()} RPM · ${stateText}`
: stateText;
renderSpikeHistory(data.fan_spike_history || []);
renderHaNotifyHistory(data.ha_notify_history || []);
renderCustomServices(data.custom_services || []);
setText(els.noticeBaseline, baselineText);
-7
View File
@@ -325,13 +325,6 @@ html[data-theme="light"] .details-panel{background:#edf3fa;border-color:#b8c7da}
</div>
</div>
<div class="spike-log-box">
<h3 data-i18n="haNotifyHistory">HA Notify History</h3>
<div id="haNotifyList" class="spike-log-list">
<div class="spike-log-empty" data-i18n="noHaNotifyHistory">No HA notify history.</div>
</div>
</div>
<div class="spike-log-box">
<div class="dmesg-head">
<h3>dmesg</h3>