import { home, getLinkageDeviceList, device } from '@ray-js/ray';
import { SmartAlarmAbility, useDevice } from '@ray-js/panel-sdk';
const devInfo = useDevice(device => device.devInfo);
const { getDeviceInfo } = device;
const res = (await home.getCurrentHomeInfo()) as any;
// 得到家庭组下的设备
const linkageDevices = (await getLinkageDeviceList({
gid: res?.homeId,
sourceType: 'wirelessSwitch',
})) as any;
// 筛选品类是温控器或者温控阀
const arr1 = linkageDevices.filter(item => item.category === 'wk' || item.category === 'wkf');
// 自定义告警列表
const Alarm = new SmartAlarmAbility();
// 得到家庭组下品类是温控器或者温控阀的第一个设备 并找到code为temp_set的dpId
const info = (await getDeviceInfo({
deviceId: arr1[0].devId,
})) as any;
let dpId = null;
const obj = info.schema.find(item => item?.code === 'temp_set') as any;
if (obj) {
dpId = obj.id;
}
// 新增自定义场景 如果当前设备dp1<=180 那么设置 品类是温控器或者温控阀的第一个设备的temp_set的dp为240
const result = await Alarm.addCustomAlarm({
devId: devInfo.devId,
name: 'temp_low',
condition: [[1, '<=', 18 * 10]],
actions: [
{
entityId: arr1[0].devId,
actionExecutor: 'dpIssue',
executorProperty: {
[dpId]: 24 * 10,
},
extraProperty: {},
},
],
});
// 列表
const customAlarmList = await Alarm.getCustomAlarmList({ devId: devInfo.devId });
// 测试删除接口
if (customAlarmList[0]) {
await Alarm.deleteCustomAlarm({ bindId: customAlarmList[0].bindId });
}
// 测试状态接口
if (customAlarmList[0]) {
const result = await Alarm.setCustomAlarmStatus({
bindId: customAlarmList[0].bindId,
enable: true,
});
}