Files
Cyrene_v2/internal/iot/safety.go
T
AskaEth f91a83ff81
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled
feat(urgency): 通用紧急度通道(Declarer/Level + 只抬不压折算)+ IoT 首个生产者 + 她自己的结论走结构化标记穿透安静时段
2026-10-05 13:11:04 +08:00

34 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package iot
// 安全规则表所用的字面量集中在此,避免规则命中里出现魔法字符串。
const (
deviceTypeLock = "lock"
actionUnlock = "unlock"
)
// safetySeverity 报告一次 (设备类型, 动作) 跃迁是否命中已登记的显式安全规则,
// 命中时返回该规则声明的严重度。
//
// 这是 IoT 侧严重度升级的**唯一**起点,规则逐条可审且保守:只有语义上明确属于
// 安全域的动作才升级,未命中的动作一律落在 SeverityRoutine——因此常规设备变化
// 不会因为本机制获得穿透安静时段的资格。
//
// 目前登记的规则(一条):
// - lock/unlock —— 门锁开启。不论开启者是谁,门锁从锁闭变为开启都是一次安全域
// 事件(入侵 / 异常开启),标 critical。
//
// 烟雾、漏水、门窗磁等安全来源的规则属**设备来源**(Provider)自身的语义,待真实
// Provider(MQTT / Home Assistant)接入时在同一张表登记;本机制不预置猜测性的
// 阈值或设备语义。
func safetySeverity(deviceType, action string) (AlertSeverity, bool) {
if deviceType != deviceTypeLock {
return SeverityRoutine, false
}
switch action {
case actionUnlock:
return SeverityCritical, true
default:
return SeverityRoutine, false
}
}