Control 알림과 notice 설정 세분화
This commit is contained in:
+33
-7
@@ -147,6 +147,7 @@ function setting_definitions(): array
|
||||
'security.login_window_seconds' => ['group' => 'security', 'label' => '로그인 실패 집계 시간', 'type' => 'number', 'default' => 600, 'min' => 60, 'max' => 86400, 'step' => 60, 'unit' => '초'],
|
||||
'security.login_lock_seconds' => ['group' => 'security', 'label' => '로그인 잠금 시간', 'type' => 'number', 'default' => 300, 'min' => 10, 'max' => 86400, 'step' => 10, 'unit' => '초'],
|
||||
'security.reboot_phrase' => ['group' => 'security', 'label' => '재부팅 확인 문구', 'type' => 'text', 'default' => '재부팅', 'min_length' => 2, 'max_length' => 32],
|
||||
'security.allow_reboot' => ['group' => 'security', 'label' => '재부팅 실행 허용', 'type' => 'boolean', 'default' => 1],
|
||||
'security.reboot_timeout_seconds' => ['group' => 'security', 'label' => '재부팅 명령 timeout', 'type' => 'number', 'default' => 5, 'min' => 2, 'max' => 30, 'step' => 1, 'unit' => '초'],
|
||||
'security.wifi_command_timeout_seconds' => ['group' => 'security', 'label' => 'WiFi 명령 timeout', 'type' => 'number', 'default' => 25, 'min' => 5, 'max' => 90, 'step' => 1, 'unit' => '초'],
|
||||
'security.shell_default_timeout_seconds' => ['group' => 'security', 'label' => '기본 명령 timeout', 'type' => 'number', 'default' => 8, 'min' => 2, 'max' => 60, 'step' => 1, 'unit' => '초'],
|
||||
@@ -167,6 +168,17 @@ function setting_definitions(): array
|
||||
'notice.temp_delta_threshold' => ['group' => 'notice', 'label' => '온도 이상 감지 차이', 'type' => 'number', 'default' => 3.0, 'min' => 0.5, 'max' => 15, 'step' => 0.1, 'unit' => 'C'],
|
||||
'notice.recover_rpm_delta' => ['group' => 'notice', 'label' => '팬 RPM 복구 차이', 'type' => 'number', 'default' => 500, 'min' => 50, 'max' => 3000, 'step' => 50, 'unit' => 'RPM'],
|
||||
'notice.recover_temp_delta' => ['group' => 'notice', 'label' => '온도 복구 차이', 'type' => 'number', 'default' => 1.5, 'min' => 0.2, 'max' => 10, 'step' => 0.1, 'unit' => 'C'],
|
||||
'notice.rpm_expected_pwm' => ['group' => 'notice', 'label' => 'RPM 감시 시작 PWM', 'type' => 'number', 'default' => 20, 'min' => 0, 'max' => 255, 'step' => 1, 'unit' => 'PWM'],
|
||||
'notice.log_during_alert' => ['group' => 'notice', 'label' => 'Alert 유지 중 반복 기록', 'type' => 'boolean', 'default' => 0],
|
||||
'notice.log_interval_seconds' => ['group' => 'notice', 'label' => 'Alert 반복 기록 간격', 'type' => 'number', 'default' => 300, 'min' => 30, 'max' => 3600, 'step' => 30, 'unit' => '초'],
|
||||
'notice.downward_only_process_hide' => ['group' => 'notice', 'label' => '하강 변화 원인 후보 숨김', 'type' => 'boolean', 'default' => 1],
|
||||
'notify.battery_emergency_percent' => ['group' => 'notify', 'label' => '배터리 긴급 기준', 'type' => 'number', 'default' => 5, 'min' => 1, 'max' => 30, 'step' => 0.5, 'unit' => '%'],
|
||||
'notify.battery_critical_percent' => ['group' => 'notify', 'label' => '배터리 위험 기준', 'type' => 'number', 'default' => 10, 'min' => 1, 'max' => 40, 'step' => 0.5, 'unit' => '%'],
|
||||
'notify.battery_warning_percent' => ['group' => 'notify', 'label' => '배터리 경고 기준', 'type' => 'number', 'default' => 15, 'min' => 1, 'max' => 50, 'step' => 0.5, 'unit' => '%'],
|
||||
'notify.battery_clear_percent' => ['group' => 'notify', 'label' => '배터리 복구 기준', 'type' => 'number', 'default' => 20, 'min' => 2, 'max' => 80, 'step' => 0.5, 'unit' => '%'],
|
||||
'notify.battery_low_cooldown_seconds' => ['group' => 'notify', 'label' => '배터리 낮음 알림 쿨다운', 'type' => 'number', 'default' => HA_NOTIFY_BATTERY_LOW_COOLDOWN, 'min' => 1, 'max' => 86400, 'step' => 1, 'unit' => '초'],
|
||||
'notify.battery_clear_cooldown_seconds' => ['group' => 'notify', 'label' => '배터리 복구 알림 쿨다운', 'type' => 'number', 'default' => HA_NOTIFY_BATTERY_CLEAR_COOLDOWN, 'min' => 1, 'max' => 86400, 'step' => 1, 'unit' => '초'],
|
||||
'notify.system_notice_cooldown_seconds' => ['group' => 'notify', 'label' => '시스템 유의사항 알림 쿨다운', 'type' => 'number', 'default' => HA_NOTIFY_SYSTEM_NOTICE_COOLDOWN, 'min' => 10, 'max' => 86400, 'step' => 10, 'unit' => '초'],
|
||||
'battery.trend_hours' => ['group' => 'battery', 'label' => '단기 배터리 학습 범위', 'type' => 'number', 'default' => 24, 'min' => 1, 'max' => 48, 'step' => 1, 'unit' => '시간'],
|
||||
'battery.profile_days' => ['group' => 'battery', 'label' => '장기 배터리 학습 범위', 'type' => 'number', 'default' => 45, 'min' => 3, 'max' => 90, 'step' => 1, 'unit' => '일'],
|
||||
'battery.load_adjust_recent' => ['group' => 'battery', 'label' => '최근 추세 부하 보정 강도', 'type' => 'number', 'default' => 0.45, 'min' => 0, 'max' => 1, 'step' => 0.01, 'unit' => 'x'],
|
||||
@@ -178,6 +190,8 @@ function setting_definitions(): array
|
||||
'battery.candidate_min_ratio' => ['group' => 'battery', 'label' => '후보 최소 속도 비율', 'type' => 'number', 'default' => 0.38, 'min' => 0.05, 'max' => 1, 'step' => 0.01, 'unit' => 'x'],
|
||||
'battery.candidate_max_ratio' => ['group' => 'battery', 'label' => '후보 최대 속도 비율', 'type' => 'number', 'default' => 2.65, 'min' => 1, 'max' => 8, 'step' => 0.05, 'unit' => 'x'],
|
||||
'battery.capacity_model_weight' => ['group' => 'battery', 'label' => '용량 모델 가중치', 'type' => 'number', 'default' => 0.18, 'min' => 0, 'max' => 1, 'step' => 0.01, 'unit' => 'x'],
|
||||
'battery.history_chart_limit' => ['group' => 'battery', 'label' => '상태 차트 표본 수', 'type' => 'number', 'default' => 240, 'min' => 60, 'max' => 1500, 'step' => 10, 'unit' => '개'],
|
||||
'battery.history_sync_limit' => ['group' => 'battery', 'label' => '잔여시간 차트 표본 수', 'type' => 'number', 'default' => 240, 'min' => 60, 'max' => 1500, 'step' => 10, 'unit' => '개'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -246,6 +260,7 @@ function settings_payload(): array
|
||||
$values = setting_rows();
|
||||
$groups = [
|
||||
'security' => '보안 정책',
|
||||
'notify' => '알림 정책',
|
||||
'fan' => '팬 자동 제어',
|
||||
'battery' => '배터리 예측',
|
||||
'event' => '저전압/스로틀링',
|
||||
@@ -501,7 +516,7 @@ function bootstrap_db(): void
|
||||
$pdo->exec("
|
||||
CREATE TABLE IF NOT EXISTS remember_tokens (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
selector CHAR(24) NOT NULL,
|
||||
selector VARCHAR(64) NOT NULL,
|
||||
validator_hash CHAR(64) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
expires_at DATETIME NOT NULL,
|
||||
@@ -583,6 +598,7 @@ function bootstrap_db(): void
|
||||
"ALTER TABLE sensor_logs DROP COLUMN created_ip",
|
||||
"ALTER TABLE fan_spike_logs ADD COLUMN spike_key VARCHAR(32) NULL AFTER created_at",
|
||||
"ALTER TABLE fan_spike_logs ADD UNIQUE KEY uniq_spike_key (spike_key)",
|
||||
"ALTER TABLE remember_tokens MODIFY selector VARCHAR(64) NOT NULL",
|
||||
"ALTER TABLE system_notice_state ADD COLUMN active_temp_delta DECIMAL(8,2) NULL AFTER active_reason",
|
||||
"ALTER TABLE system_notice_state ADD COLUMN active_rpm_delta DECIMAL(12,2) NULL AFTER active_temp_delta",
|
||||
"ALTER TABLE system_notice_state ADD COLUMN process_signature VARCHAR(255) NULL AFTER active_rpm_delta",
|
||||
@@ -949,7 +965,11 @@ function clear_ha_notification(string $tag, string $title = 'Control 알림 해
|
||||
|
||||
function battery_low_notify_profile(float $percent): array
|
||||
{
|
||||
if ($percent <= 5.0) {
|
||||
$emergency = (float)setting_value('notify.battery_emergency_percent');
|
||||
$critical = max($emergency, (float)setting_value('notify.battery_critical_percent'));
|
||||
$warning = max($critical, (float)setting_value('notify.battery_warning_percent'));
|
||||
|
||||
if ($percent <= $emergency) {
|
||||
return [
|
||||
'label' => '긴급',
|
||||
'level' => 'critical',
|
||||
@@ -964,7 +984,7 @@ function battery_low_notify_profile(float $percent): array
|
||||
];
|
||||
}
|
||||
|
||||
if ($percent <= 10.0) {
|
||||
if ($percent <= $critical) {
|
||||
return [
|
||||
'label' => '위험',
|
||||
'level' => 'critical',
|
||||
@@ -979,7 +999,7 @@ function battery_low_notify_profile(float $percent): array
|
||||
];
|
||||
}
|
||||
|
||||
if ($percent <= 15.0) {
|
||||
if ($percent <= $warning) {
|
||||
return [
|
||||
'label' => '경고',
|
||||
'level' => 'warning',
|
||||
@@ -1025,13 +1045,19 @@ function send_battery_low_notify_if_needed(array $battery): array
|
||||
: null;
|
||||
|
||||
$tag = 'control-battery-low';
|
||||
if ($percent > 20.0) {
|
||||
$warning = max(
|
||||
(float)setting_value('notify.battery_emergency_percent'),
|
||||
(float)setting_value('notify.battery_critical_percent'),
|
||||
(float)setting_value('notify.battery_warning_percent')
|
||||
);
|
||||
$clearPercent = max($warning + 0.5, (float)setting_value('notify.battery_clear_percent'));
|
||||
if ($percent > $clearPercent) {
|
||||
$latestLow = latest_ha_notify_epoch_by_tag($tag);
|
||||
$latestClear = latest_ha_notify_epoch_by_tag($tag . '-clear');
|
||||
if (
|
||||
$latestLow > 0
|
||||
&& $latestLow > $latestClear
|
||||
&& ha_notify_due($tag . '-clear', HA_NOTIFY_BATTERY_CLEAR_COOLDOWN)
|
||||
&& ha_notify_due($tag . '-clear', (int)setting_value('notify.battery_clear_cooldown_seconds'))
|
||||
) {
|
||||
return clear_ha_notification($tag, '배터리 SOC 복구');
|
||||
}
|
||||
@@ -1043,7 +1069,7 @@ function send_battery_low_notify_if_needed(array $battery): array
|
||||
];
|
||||
}
|
||||
|
||||
if (!ha_notify_due($tag, HA_NOTIFY_BATTERY_LOW_COOLDOWN)) {
|
||||
if (!ha_notify_due($tag, (int)setting_value('notify.battery_low_cooldown_seconds'))) {
|
||||
return [
|
||||
'sent' => 0,
|
||||
'failed' => 0,
|
||||
|
||||
Reference in New Issue
Block a user