import { DpValue } from '../../../types/devInfo'; type DpId = number; type Operator = '==' | '<' | '>' | '<=' | '>='; export type AddCustomAlarmOptions = { /** * 设备 ID,默认从默认设备环境中取 */ devId?: string; /** * 告警的名称或备注 */ name?: string; /** * 告警触发的前置条件 */ preCondition?: { /** * 告警可触发的开始时间,默认全天,即 00:00 */ startTime: string; /** * 告警可触发的结束时间,默认全天,即 23:59 */ endTime: string; /** * 告警可触发的日期,默认全周,即 '1111111' */ loops: string; }; /** * 告警触发的功能点条件,[DpId, Operator, DpValue][] * * @example 多条件 * ```ts * [ * ["temp_current", "<=", 30], * ["temp_current", ">", 85] * ] * ``` * @example 单条件 * ```ts * [ * ["power", "==", true] * ] * ``` */ condition: [DpId, Operator, DpValue][]; /** * 告警触发的功能点条件持续多久才会触发执行 action 动作,单位为秒 * @default 0 */ duration?: number; /** * @internal * 前置条件集合,暂不开放,预留字段 */ preConditions?: any; /** * @internal * 条件集合,暂不开放,预留字段 */ conditions?: any; /** * @internal * 动作集合,暂不开放,预留字段 */ actions?: any; /** * @internal * 关联实体值,用于区分告警类型 */ entityValue?: string; }; export type AlarmLocaleText = { /** * 英文文案 */ en: string; /** * 中文文案 */ zh: string; }; export type BuiltInAlarmI18nData = { /** * 名称多语言 */ name: AlarmLocaleText; /** * 内容多语言 */ content: AlarmLocaleText; }; export type BuiltInAlarmRule = { /** * 审核状态 */ auditStatus: number; /** * 是否被场景面板绑定 */ boundForPanel: boolean; /** * 是否被 WiFi 场景面板绑定 */ boundForWiFiPanel: boolean; /** * 是否启用 */ enabled: boolean; /** * 多语言数据体 */ i18nData: BuiltInAlarmI18nData; /** * 规则 ID */ id: string; /** * 是否为本地联动 */ localLinkage: boolean; /** * 规则名称 */ name: string; /** * 是否为 App 管控本地联动 */ newLocalScene: boolean; /** * 场景是否显示在首页 */ stickyOnTop: boolean; }; export type BuiltInAlarmList = BuiltInAlarmRule[]; export type SetBuiltInAlarmStatusParams = { /** * 设备 ID,不传则使用当前设备 */ devId?: string; /** * true 为禁用,false 为启用 */ disabled: boolean; /** * 要操作的告警规则 ID,多个用逗号分隔 */ ruleIds: string; }; export type SetBuiltInAlarmStatusResult = [boolean, BuiltInAlarmList]; export type GetCustomAlarmListParams = { /** * 要创建告警规则的功能点 ID,不填则拉取所有 */ dpId?: string; /** * 设备 ID,不填则默认自动读取当前环境下的设备 ID */ devId?: string; }; export type CustomAlarmPreConditionExpr = { /** * 时区 id,如 Asia/Shanghai */ timeZoneId: string; /** * 开始时间,格式为 HH:mm,如 00:00 */ start: string; /** * 时间间隔,固定为 'custom' */ timeInterval: string; /** * 循环日期,'1111111' 说明为一周七天均开启,其中起始时间为周日 */ loops: string; /** * 结束时间,格式为 HH:mm,如 23:59 */ end: string; [key: string]: unknown; }; export type AlarmPreCondition = { /** * 条件表达式 */ expr: CustomAlarmPreConditionExpr; /** * 条件类型,告警 SDK 固定为 timeCheck */ condType: 'timeCheck'; /** * 条件 ID */ id: string; [key: string]: unknown; }; export type CustomAlarmCondition = { /** * 条件 ID */ id: string; /** * 规则 ID */ ruleId: string; /** * 数据 ID */ entityId: string; /** * 抽象子数据 ID */ entitySubIds: string; /** * 条件的表达式 */ expr: string; [key: string]: unknown; }; export type CustomAlarmSceneAction = { /** * 条件 id */ id: string; /** * 场景 id */ ruleId: string; /** * 动作类型,在告警 SDK 下固定为 appPushTrigger */ actionExecutor: string; [key: string]: unknown; }; export type AlarmTriggerRuleVO = { /** * 家庭 id */ ownerId: string; /** * 告警规则是否启用 */ enabled: boolean; /** * 执行规则 id */ id: string; /** * 告警名称或备注 */ name: string; /** * 执行动作的前置条件,详见 AlarmPreCondition 定义 */ preConditions: AlarmPreCondition[] | unknown[]; /** * 执行动作的条件,详见 CustomAlarmCondition 定义 */ conditions: CustomAlarmCondition[] | unknown[]; /** * 执行的动作,详见 CustomAlarmSceneAction 定义 */ actions: CustomAlarmSceneAction[] | unknown[]; }; export type CustomAlarmRule = { /** * 告警执行的规则 id */ triggerRuleId: string; /** * 触发告警规则的详细信息,详见 AlarmTriggerRuleVO 定义 */ triggerRuleVO: AlarmTriggerRuleVO; /** * 业务域标识,在告警 SDK 下固定为 miniAppPanelSDKAlarm */ bizDomain: string; /** * 当 associativeEntityId 不足以区分情况下使用,比如使用的是同一个功能点时又要区分告警类型的情况下,可以使用 DpValue,一般情况下用不到 */ associativeEntityValue: string; /** * 和当前告警相关联的设备 ID */ sourceEntityId: string; /** * 名称或备注 */ name: string; /** * 图标 */ icon: string; /** * 绑定 ID */ bindId: number; /** * 和当前告警相关联的功能点 DP ID */ associativeEntityId: string; /** * 是否启用 */ enable: boolean; }; export type CustomAlarmList = CustomAlarmRule[]; export type AddCustomAlarmBindResult = { /** * 关联实体值,用于区分告警类型 */ associativeEntityValue: string; /** * 关联实体 ID,通常为功能点 ID */ associativeEntityId: string; /** * 绑定 ID */ bindId: number; /** * 业务域,告警固定为 miniAppPanelSDKAlarm */ bizDomain: string; /** * 是否启用 */ enable: boolean; /** * 设备 ID */ sourceEntityId: string; }; export type AddCustomAlarmResult = [AddCustomAlarmBindResult, CustomAlarmList]; export type SetCustomAlarmStatusParams = { /** * 要操作的告警规则绑定 ID */ bindId: number; /** * true 为启用,false 为禁用 */ enable: boolean; }; export type SetCustomAlarmStatusResult = [boolean, CustomAlarmList]; export type DeleteCustomAlarmParams = { /** * 要删除的告警规则绑定 ID */ bindId: number; }; export type DeleteCustomAlarmResult = [boolean, CustomAlarmList]; export {};