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(),
];